示例#1
0
 public static function sendInviteEmail($user, $accountName, $link, $subject, $template = 'invitation')
 {
     $validation = new Validation();
     $validation->userId = $user->_id;
     $validation->code = StringUtil::uuid();
     $validation->expire = new \MongoDate(strtotime('+7 day'));
     if ($validation->save()) {
         $mail = Yii::$app->mail;
         $vars = ['name' => $accountName, 'email' => $user->email, 'host' => Yii::$app->request->hostInfo, 'link' => str_replace('code', $validation->code, $link)];
         $mail->setView('//mail/' . $template, $vars, '//layouts/email');
         $mail->sendMail($user->email, $subject);
         return true;
     }
     return false;
 }
 /**
  * Register billing account
  *
  * <b>Request Type</b>: POST<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/site/register<br/><br/>
  * <b>Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for registering user.
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *     name: string, the user name<br/>
  *     email: string, the user email<br/>
  *     password: string, the user password<br/>
  *     <br/><br/>
  *
  * <b>Response Params:</b><br/>
  *     ack: integer, mark the create result, 1 means create successfully, 0 means create fail<br/>
  *     message: string, if create fail, it contains the error message<br/>
  *     data: array, json array to describe all users detail information<br/>
  *     <br/><br/>
  *
  * <b>Request Example:</b><br/>
  * <pre>
  * {
  *     "name" : "harrysun",
  *     "email" : "*****@*****.**",
  *     "password" : "abc123_"
  * }
  * </pre>
  * <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  * {
  *    'ack' : 1,
  *    'message': ''
  * }
  * </pre>
  */
 public function actionRegister()
 {
     $data = $this->getParams();
     $account = new Account();
     $account->save();
     $user = new User();
     $user->name = $data['name'];
     $user->email = $data['email'];
     $user->salt = StringUtil::rndString(6);
     $user->password = User::encryptPassword($data['password'], $user->salt);
     $user->accountId = $account->_id;
     $user->role = User::ROLE_ADMIN;
     $user->isActivated = User::NOT_ACTIVATED;
     $user->avatar = Yii::$app->params['defaultAvatar'];
     $user->language = 'zh_cn';
     if ($user->validate()) {
         // all inputs are valid
         if ($user->save()) {
             $validation = new Validation();
             $validation->userId = $user->_id;
             $validation->code = StringUtil::uuid();
             $validation->expire = new \MongoDate(strtotime('+1 day'));
             if ($validation->save()) {
                 $mail = Yii::$app->mail;
                 $host = Yii::$app->request->hostInfo;
                 $vars = ['name' => $user->name, 'link' => $host . '/api/old-site/activate?code=' . $validation->code, 'host' => $host];
                 $mail->setView('//mail/register', $vars, '//layouts/email');
                 $mail->sendMail($user->email, '欢迎注册WeMarketing');
                 return ["ack" => 1, "message" => 'Register success.'];
             } else {
                 return ["ack" => 0, "message" => 'Validation save fail.'];
             }
         } else {
             return ["ack" => 0, "message" => 'Register user fail.'];
         }
     } else {
         // validation failed: $errors is an array containing error messages
         $errors = $user->errors;
         //revert the accout data
         Account::deleteAll(['_id' => $account->_id]);
         return ["ack" => 0, "message" => $errors];
     }
 }
示例#3
0
 /**
  * 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'];
 }
示例#4
0
 /**
  * Send Reset password email
  */
 public function actionSendResetPasswordEmail()
 {
     $email = $this->getParams('email');
     $email = mb_strtolower($email);
     if (empty($email)) {
         throw new InvalidParameterException(['reset-email' => Yii::t('common', 'email_is_required')]);
     }
     if (!StringUtil::isEmail($email)) {
         throw new InvalidParameterException(['reset-email' => Yii::t('member', 'email_format_error')]);
     }
     //validate the email
     $user = User::getByEmail($email);
     if (empty($user)) {
         throw new InvalidParameterException(['reset-email' => Yii::t('common', 'incorrect_userid')]);
     }
     if (!empty($user) && !$user->isActivated) {
         throw new InvalidParameterException(['reset-email' => Yii::t('common', 'user_not_activate')]);
     }
     //generate the validation
     $validation = new Validation();
     $validation->userId = $user->_id;
     $validation->expire = new \MongoDate(strtotime('+7 day'));
     if (!$validation->save()) {
         throw new ServerErrorHttpException("Failed to save validation");
     }
     $host = Yii::$app->request->hostInfo;
     $link = $host . '/site/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'];
 }