Пример #1
0
 /**
  * Signs user with given credentials
  * @return string|null JWT or null if user is not saved or does not have getJWT method
  */
 public function sign()
 {
     $user = new User();
     $user->username = $this->username;
     $user->email = $this->email;
     $user->setPassword($this->password);
     // This way we check whether JWT is included. And even if it's not but
     // method is present - it's developer's mistake
     if (method_exists($user, 'getJWT')) {
         if ($user->save()) {
             return $user->JWT;
         }
     }
     return null;
 }
 public function down()
 {
     $user = User::findByEmail('*****@*****.**');
     if (!empty($user)) {
         $user->delete();
     }
 }
 public function testProject_Ok()
 {
     $user = User::findByLogin('test');
     $result = Project::find('all', array('joins' => array('members'), 'select' => 'projects.identifier,members.user_id,members.role_id', 'conditions' => array('user_id = ?', $user->id)));
     $this->assertEquals(4, $result[0]->role_id);
     $this->assertEquals(3, $result[1]->role_id);
 }
Пример #4
0
 /**
  * Signs user with given credentials
  * @return string|null Either JWT either null if user is not saved
  * @throws \yii\web\ServerErrorHttpException If getJWT method is missing in
  *         									 User model
  */
 public function auth()
 {
     $user = User::findByUsername($this->username);
     if ($user && $user->validatePassword($this->password)) {
         return $user->jwt;
     }
     return null;
 }
Пример #5
0
 public function actionView($id)
 {
     $model = $this->findModel($id);
     if (!$model) {
         throw new NotFoundHttpException();
     }
     $user = \api\models\User::findOne($model->domain_id);
     $user = $user ? $user->username : '';
     return $this->render('view', ['model' => $model, 'user' => $user]);
 }
Пример #6
0
 public function testProjectsJoin_Ok()
 {
     $user = User::findByLogin('test');
     $this->assertNotNull($user);
     $projects = $user->projects;
     $c = count($projects);
     $this->assertEquals(2, $c);
     $this->assertEquals('testpal-dictionary', $projects[0]->identifier);
     $this->assertEquals('lwl2', $projects[1]->identifier);
 }
Пример #7
0
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_fk']);
 }