-
Notifications
You must be signed in to change notification settings - Fork 1
/
User.php
98 lines (84 loc) · 1.94 KB
/
User.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace tests\codeception\unit\models;
use Yii;
use yii\web\IdentityInterface;
class User extends \tests\codeception\unit\models\base\User implements IdentityInterface
{
public $authKey;
public $accessToken;
/**
* @inheritdoc
*/
public static function findIdentity($id)
{
return self::findOne($id);
}
/**
* @inheritdoc
*/
public static function findIdentityByAccessToken($token, $type = null)
{
$identity = Yii::$app->cache->get($token);
return $identity != false ? $identity : null;
}
/**
* Finds user by username
*
* @param string $username
* @return static|null
*/
public static function findByUsername($username)
{
return static::findOne(['username' => $username]);
}
/**
* @inheritdoc
*/
public function getId()
{
return $this->getPrimaryKey();
}
/**
* @inheritdoc
*/
public function getAuthKey()
{
return $this->authKey;
}
/**
* @inheritdoc
*/
public function validateAuthKey($authKey)
{
return $this->authKey === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return boolean if password provided is valid for current user
*/
public function validatePassword($password)
{
return Yii::$app->security->validatePassword($password, $this->password);
}
/**
* @inheritdoc
*/
public function getAccessToken()
{
return $this->accessToken;
}
/** @inheritdoc */
public function fields()
{
$fields = parent::fields();
// remove fields that contain sensitive information
unset($fields['password'], $fields['authKey'], $fields['accessToken']);
return $fields;
}
public function extraFields()
{
return ['profile','department'];
}
}