Users::updateUser PHP Method

updateUser() public method

modify user's information
public updateUser ( $token, $alias = null, $password = null, $avatar = null )
    public function updateUser($token, $alias = null, $password = null, $avatar = null)
    {
        $token = $this->factory->create('Tokens')->getToken($token);
        Verify::isTrue(isset($token['uid']) && $token['uid'] != 0, new Forbidden("invalid uid {$token['uid']}"));
        if ($avatar) {
            $avatar = $this->uploadAvatar($avatar);
        }
        $uid = $token['uid'];
        $pdo = $this->db;
        $pdo->beginTransaction();
        try {
            if ($alias || $avatar) {
                $sets = array();
                $params = array();
                if ($alias) {
                    $res = Sql::select('uid')->from('pre_common_member_profile')->where('realname = ? AND uid <> ?', $alias, $uid)->forUpdate()->get($pdo);
                    Verify::isTrue(count($res) == 0, new AliasConflict("alias {$alias} conflict"));
                    $params['realname'] = $alias;
                }
                if ($avatar) {
                    $params['avatar'] = $avatar;
                }
                Sql::update('pre_common_member_profile')->setArgs($params)->where('uid = ?', $uid)->exec($pdo);
            }
            if ($password !== null) {
                Sql::update('uc_members')->setArgs(['password' => $password, 'salt' => ''])->where('uid=?', $uid)->exec($pdo);
            }
            $pdo->commit();
        } catch (Exception $e) {
            Logger::warning("updateUser({$uid}) failed with " . $e->getMessage());
            $pdo->rollBack();
            throw $e;
        }
    }

Usage Example

 /**
  * Carries out the specified action
  */
 function perform()
 {
     // update the user information
     $this->_userInfo->setEmail(Textfilter::filterAllHTML($this->_request->getValue("userEmail")));
     if ($this->_userPassword != "") {
         $this->_userInfo->setPassword($this->_userPassword);
     }
     $this->_userInfo->setAboutMyself(Textfilter::filterAllHTML($this->_request->getValue("userAbout")));
     $this->_userInfo->setFullName(Textfilter::filterAllHTML($this->_request->getValue("userFullName")));
     $this->_userInfo->setPictureId($this->_request->getValue("userPictureId"));
     $this->_userInfo->setProperties($this->_request->getValue("properties"));
     $this->notifyEvent(EVENT_PRE_USER_UPDATE, array("user" => &$this->_userInfo));
     $this->_session->setValue("userInfo", $this->_userInfo);
     $this->saveSession();
     // update the user information
     $this->_view = new AdminUserProfileView($this->_blogInfo, $this->_userInfo);
     $users = new Users();
     if (!$users->updateUser($this->_userInfo)) {
         $this->_view->setErrorMessage($this->_locale->tr("error_updating_user_settings"));
     } else {
         $this->_view->setSuccessMessage($this->_locale->pr("user_settings_updated_ok", $this->_userInfo->getUsername()));
         // if everything fine, also say so...
         $this->notifyEvent(EVENT_POST_USER_UPDATE, array("user" => &$this->_userInfo));
     }
     $this->setCommonData();
     return true;
 }
All Usage Examples Of Users::updateUser