public function actionCheckUnique()
 {
     $query = $this->getQuery();
     $accountId = $this->getAccountId();
     if (!empty($query['email'])) {
         $email = $query['email'];
         if (!StringUtil::isEmail($email)) {
             throw new InvalidParameterException(['email' => Yii::t('helpDesk', 'email_format_wrong')]);
         }
         $helpDesk = HelpDesk::getByEmail($email);
         if (!empty($helpDesk)) {
             throw new InvalidParameterException(['email' => Yii::t('helpDesk', 'email_has_used')]);
         }
     }
     if (!empty($query['badge'])) {
         $helpDesk = HelpDesk::getByBadge($query['badge'], $accountId);
         if (!empty($helpDesk)) {
             throw new InvalidParameterException(['number' => Yii::t('helpDesk', 'badge_has_used')]);
         }
     }
     return true;
 }
 /**
  * Send Reset password email
  */
 public function actionSendResetPasswordEmail()
 {
     $email = $this->getParams('email');
     $email = mb_strtolower($email);
     if (empty($email)) {
         throw new BadRequestHttpException(Yii::t('chat', 'email_empty'));
     }
     //validate the email
     $user = HelpDesk::getByEmail($email);
     if (empty($user)) {
         throw new BadRequestHttpException(Yii::t('common', 'incorrect_userid'));
     }
     //generate the validation
     $validation = new Validation();
     $validation->userId = $user->_id;
     $validation->expire = new \MongoDate(strtotime('+7 day'));
     if (!$validation->save()) {
         throw new ServerErrorHttpException(Yii::t('chat', 'save_validation_fail'));
     }
     $host = Yii::$app->request->hostInfo;
     $link = $host . '/chat/resetpassword?code=' . $validation->code;
     $mail = Yii::$app->mail;
     $vars = ['name' => $user->name, 'link' => $link, 'host' => $host];
     $mail->setView('//mail/resetPassword', $vars, '//layouts/email');
     $mail->sendMail($user->email, '群脉重置密码');
     return ['status' => 'ok'];
 }