leammas /yii2-megaplanauth
提供使用Megaplan Auth API进行用户认证的能力
dev-master
2015-07-09 06:43 UTC
Requires
- linslin/yii2-curl: dev-develop
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-09-28 18:16:24 UTC
README
提供使用Megaplan Auth API进行用户认证的能力。具体说明可以在此处找到。
安装
安装此扩展的首选方式是通过composer。
运行以下命令
php composer.phar require --prefer-dist leammas/yii2-megaplanauth "*"
或者
"leammas/yii2-megaplanauth": "*"
将以下内容添加到你的composer.json
文件的require部分。
要求
- Yii2
- PHP 5.4+
- 已安装Curl和php-curl
使用方法
安装扩展后,将其用作应用组件
'components' => [
...
'mpauth' => [
'class' => 'leammas\yii2\megaplanauth\Megaplanauth',
'url' => 'http://some.url',
'timeout' => 10
],
...
主要方法authenticate
接受两个参数username
和password
。你可以在表单或用户模型验证中使用它。如果成功,它将返回包含用户数据的数组,或者在出现错误时抛出包含错误信息的MPAuthException。
/** * @param $password * @return bool */ public function validatePassword($password) { try { $success = Yii::$app->mpauth->authenticate($this->username, $password); // if you don't use Megaplan user id's or employee id's, just replace it with `return true;` return $success['EmployeeId'] == $this->id; } catch(MPAuthException $e) { Yii::trace('MPAuth Fail: ' . $e->getMessage()); return false; } }