null], [['status'], 'default', 'value' => 10], [['username', 'auth_key', 'password_hash', 'email', 'created_at', 'updated_at'], 'required'], [['status', 'created_at', 'updated_at'], 'integer'], [['username', 'password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255], [['auth_key', 'role'], 'string', 'max' => 32], [['username'], 'unique'], [['email'], 'unique'], [['password_reset_token'], 'unique'], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'username' => 'Username', 'auth_key' => 'Auth Key', 'password_hash' => 'Password Hash', 'password_reset_token' => 'Password Reset Token', 'email' => 'Email', 'status' => 'Status', 'created_at' => 'Created At', 'updated_at' => 'Updated At', 'role' => 'Role', ]; } /** * {@inheritdoc} */ public static function findIdentity($id) { return static::find() ->where(['id' => $id]) ->andWhere(['status' => self::STATUS_ACTIVE]) ->one(); } /** * {@inheritdoc} */ public static function findIdentityByAccessToken($token, $type = null) { die(__FILE__); foreach (self::$users as $user) { if ($user['accessToken'] === $token) { return new static($user); } } return null; } /** * Finds user by username * * @param string $username * @return static|null */ public static function findByUsername($username) { return static::find() ->where(['username' => $username]) ->andWhere(['status' => self::STATUS_ACTIVE]) ->one(); } /** * {@inheritdoc} */ public function getId() { return $this->id; } /** * {@inheritdoc} */ public function getAuthKey() { return $this->auth_key; } /** * {@inheritdoc} */ public function validateAuthKey($authKey) { return $this->auth_key === $authKey; } /** * Validates password * * @param string $password password to validate * @return bool if password provided is valid for current user */ public function validatePassword($password) { return Yii::$app->security->validatePassword( $password, $this->password_hash ); } public function getRole() { return $this->role; } }