public function getAdminUser()
 {
     if ($this->_admin_user === null) {
         $this->_admin_user = AdminUser::findByUsername($this->username);
     }
     return $this->_admin_user;
 }
 public function validateOldPassword($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $username = $this->getAdminUser()->username;
         $AdminUser = AdminUser::findByUsername($username);
         if ($AdminUser->validatePassword($this->old_password)) {
         } else {
             $this->addError($attribute, 'old password is not right!');
         }
     }
 }
 public function save($runValidation = true, $attributeNames = NULL)
 {
     if ($this->id) {
         $this->updated_at_datetime = date("Y-m-d H:i:s");
     } else {
         $this->created_at_datetime = date("Y-m-d H:i:s");
         $this->updated_at_datetime = date("Y-m-d H:i:s");
     }
     # 如果auth_key为空,则重置
     if (!$this->auth_key) {
         $this->generateAuthKey();
     }
     # 如果access_token为空,则重置
     if (!$this->access_token) {
         $this->generateAccessToken();
     }
     # 设置password
     $this->setPassword($this->password);
     parent::save($runValidation, $attributeNames);
 }
 public function actionLoginbyaccesstoken()
 {
     $access_token = CRequest::param("access_token");
     $username = CRequest::param("username");
     if ($access_token) {
         if ($username) {
             $one = AdminUser::findOne(['username' => $username, 'access_token' => $access_token]);
             if ($one->username) {
                 $one->generateAccessToken();
                 $one->save();
                 \Yii::$app->user->login($one, 3600 * 24);
                 header('Location: ' . CUrl::getHomeUrl());
             } else {
                 echo "User Access Token Is TimeOut";
             }
         } else {
             echo "UserName Can Not Empty";
         }
     } else {
         echo "Access Token Can Not Empty";
     }
 }