예제 #1
0
 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;
     }
 }
 public function process()
 {
     if ($this->validate()) {
         $this->_user->passhash = User::hashPassword($this->password);
         return $this->_user->save();
     }
     return false;
 }