当前位置: 首页>>代码示例>>PHP>>正文


PHP Users::findIdentity方法代码示例

本文整理汇总了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);
 }
开发者ID:yurii-github,项目名称:yii2-mylib,代码行数:32,代码来源:SiteController.php

示例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);
 }
开发者ID:yurii-github,项目名称:yii2-mylib,代码行数:17,代码来源:UsersTest.php


注:本文中的app\models\Users::findIdentity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。