/**
  * Reset password
  */
 public function actionResetPassword()
 {
     $code = $this->getParams('code');
     $newPassword = $this->getParams('password');
     $result = Validation::validateCode($code);
     if ($result == Validation::LINK_INVALID) {
         throw new BadRequestHttpException(Yii::t('common', 'link_invalid'));
     } else {
         if ($result == Validation::LINK_EXPIRED) {
             throw new BadRequestHttpException(Yii::t('common', 'link_expired'));
         }
     }
     $userId = $result;
     $user = HelpDesk::findByPk($userId);
     if (empty($user)) {
         throw new BadRequestHttpException(Yii::t('commmon', 'incorrect_userid'));
     }
     // update the user password
     $user->password = HelpDesk::encryptPassword($newPassword, $user->salt);
     if (!$user->save()) {
         throw new ServerErrorHttpException("Save user failed!");
     }
     return ['status' => 'ok'];
 }
 /**
  * Update help desk password
  *
  * <b>Request Type</b>: PUT<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/chat/help-desk<br/><br/>
  * <b>Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for help desk to update password.
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *     id: int, the user id, required<br/>
  *     currentPwd: string, the user currentPwd, required<br/>
  *     newPwd: string, the user newPwd, required<br/>
  *     newPwdC: string, the user newPwdC, required<br/>
  *     <br/><br/>
  *
  * <b>Response Params:</b><br/>
  *     ack: integer, mark the update result, 0 means update successfully, 1 means update fail<br/>
  *     data: array, json array to describe the user updated<br/>
  *     <br/><br/>
  *
  * <b>Request Example:</b><br/>
  * <pre>
  * {
  *     "id" : "547eaf82e9c2fb52478b4567,
  *     "currentPwd" : "6c302344ab2117ee4ce52b7d8952c689",
  *     "newPwd" : "6c302344ab2117ee4ce52b7d8952c689",
  *     "newPwdC" : "6c302344ab2117ee4ce52b7d8952c689"
  * }
  * </pre>
  * <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  * {
  *    "result" : "success"
  * }
  * </pre>
  */
 public function actionUpdatepassword()
 {
     $params = $this->getParams();
     if (empty($params['id']) || empty($params['currentPwd']) || empty($params['newPwd']) || empty($params['newPwdC'])) {
         throw new BadRequestHttpException("Parameters missing");
     }
     // validate if the userid is correct
     $user = HelpDesk::findOne(['_id' => new \MongoId($params['id'])]);
     if (empty($user)) {
         throw new BadRequestHttpException("Incorrect userid");
     }
     // validate if the current password is correct
     if (!$user->validatePassword($params['currentPwd'])) {
         throw new InvalidParameterException(['old-password' => Yii::t('common', 'common_user_currentpwd_error')]);
     }
     // check if the two passwords match
     if ($params['newPwd'] !== $params['newPwdC']) {
         throw new InvalidParameterException(['new-password' => Yii::t('common', 'common_user_currentpwd_error')]);
     }
     // check the new password is same as the current password
     if ($params['currentPwd'] == $params['newPwd']) {
         throw new InvalidParameterException(['new-password' => Yii::t('chat', 'password_error')]);
     }
     // update the user information
     $user->password = HelpDesk::encryptPassword($params['newPwd'], $user->salt);
     if (!$user->save()) {
         throw new ServerErrorHttpException("Save help desk failed!");
     }
     return ['result' => 'success'];
 }