public function actionUpdate($login)
 {
     /** @var User $user */
     $user = User::findOne(['login' => $login]);
     if ($user === null) {
         throw new Exception('User with this login not found');
     }
     $assignParam = function ($from, $to = null, $isBool = false) use($user) {
         $to = $to === null ? $from : $to;
         if ($this->{$from} !== null) {
             $user->{$to} = $isBool ? in_array($this->{$from}, ['yes', 'y', '1']) ? 1 : 0 : $this->{$from};
         }
     };
     $assignParam('login');
     $assignParam('name');
     $assignParam('email');
     $assignParam('active', 'is_active', true);
     $assignParam('superadmin', 'is_super_admin', true);
     if ($this->password !== null) {
         $user->passhash = User::hashPassword($this->password);
     }
     if ($user->save()) {
         return self::EXIT_CODE_NORMAL;
     } else {
         $this->stderr("Errors: " . Json::encode($user->getErrors()));
         return self::EXIT_CODE_ERROR;
     }
 }
Beispiel #2
0
 /**
  * @inheritdoc
  */
 public function checkAccess($userId, $permissionName, $params = [])
 {
     if (!isset($this->_users[$userId])) {
         $this->_users[$userId] = User::findOne($userId);
     }
     $user = $this->_users[$userId];
     if ($user instanceof User && $user->is_super_admin) {
         return true;
     } else {
         return parent::checkAccess($userId, $permissionName, $params);
     }
 }
Beispiel #3
0
 public function actionLoginByToken($id, $token)
 {
     if (self::getAdminModule()->allowLoginViaToken == false) {
         throw new NotFoundHttpException();
     }
     /** @var User $user */
     $user = User::findOne($id);
     if ($user === null) {
         throw new NotFoundHttpException();
     }
     $token = AdminLoginToken::compareToken($user->id, $token);
     if ($token === null) {
         throw new ForbiddenHttpException();
     }
     $token->delete();
     \Yii::$app->user->login($user);
     return $this->goHome();
 }
 /**
  * Finds the User model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return User the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = User::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }