本文整理汇总了PHP中app\models\Users::findIdentity方法的典型用法代码示例。如果您正苦于以下问题:PHP Users::findIdentity方法的具体用法?PHP Users::findIdentity怎么用?PHP Users::findIdentity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Users
的用法示例。
在下文中一共展示了Users::findIdentity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionLogin
public function actionLogin()
{
/* @var $user \yii\web\User */
//TODO: GET show view, POST login
//TODO: yii negotiator
//\Yii::$app->response->format = Response::FORMAT_JSON;
$resp = new \stdClass();
$resp->result = false;
try {
$username = \Yii::$app->request->post('username');
$password = \Yii::$app->request->post('password');
$remember_me = (bool) \Yii::$app->request->post('remember-me') ? 3600 * 24 * 30 : 0;
$user = \Yii::$app->user;
$identity = Users::findIdentity($username);
if (empty($identity) || !$identity instanceof \yii\web\IdentityInterface) {
throw new \yii\base\InvalidValueException('wrong login or password', 1);
}
if (!$identity->validatePassword($password)) {
//var_dump($password);
throw new \yii\base\InvalidValueException('wrong login or password', 2);
}
if (!$user->login($identity, $remember_me)) {
throw new \yii\base\InvalidValueException('server error. please try later', 3);
}
//success
$resp->result = true;
} catch (\Exception $e) {
//TODO: mitiple errors support
$resp->data = $e->getMessage();
}
return json_encode($resp);
}
示例2: test_finds
public function test_finds()
{
$user = new Users();
$user->username = 'yurii';
$user->password = 'pass';
$user->access_token = 'token';
$user->save();
$user2 = new Users();
$user2->username = 'yurii2';
$user2->password = 'pass2';
$user2->access_token = 'token2';
$user2->save();
$this->assertEquals($user->username, $user->getId());
$this->assertEquals($user->username, Users::findIdentity($user->username)->username);
$this->assertEquals($user->username, Users::getUserByUsername($user->username)->username);
$this->assertEquals($user->access_token, Users::findIdentityByAccessToken($user->access_token)->access_token);
}