コード例 #1
0
 /**
  * Create a new user
  *
  * <b>Request Type</b>: POST<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/management/user<br/><br/>
  * <b>Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for billing account to create a new user
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *     email: string, the user email, required<br/>
  *     role: string, the user role, required<br/>
  *     <br/><br/>
  *
  * <b>Response Params:</b><br/>
  *     ack: integer, mark the create result, 0 means create successfully, 1 means create fail<br/>
  *     data: array, json array to describe the user created<br/>
  *     <br/><br/>
  *
  * <b>Request Example:</b><br/>
  * <pre>
  * {
  *     "email" : "*****@*****.**",
  *     "role" : "admin"
  * }
  * </pre>
  * <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  * {
  *    'ack' : 1,
  *    'data': {"msg": "您当前已成功发送验证邮件到sarazhang@augmentum.com.cn邮箱中", "user": {name:"Devin Jin", avatar:"path/to/avatar", email:"*****@*****.**", isActivated:false}}
  * }
  * </pre>
  */
 public function actionCreate()
 {
     $params = $this->getParams();
     if (empty($params['email'])) {
         throw new InvalidParameterException(['email' => Yii::t('common', 'email_is_required')]);
     }
     $params['email'] = mb_strtolower($params['email']);
     if (!StringUtil::isEmail($params['email'])) {
         throw new InvalidParameterException(['email' => Yii::t('helpDesk', 'email_format_wrong')]);
     }
     $user = User::getByEmail($params['email']);
     if (!empty($user)) {
         throw new InvalidParameterException(['email' => Yii::t('helpDesk', 'email_has_used')]);
     }
     $user = new User();
     $user->email = $params['email'];
     $user->role = $params['role'];
     $user->avatar = Yii::$app->params['defaultAvatar'];
     $user->isActivated = User::NOT_ACTIVATED;
     $user->accountId = $this->getAccountId();
     if ($user->save()) {
         $currentUser = $this->getUser();
         $link = Yii::$app->request->hostInfo . '/site/invite/code?type=2';
         //type=2 means invite user account
         $result = EmailUtil::sendInviteEmail($user, $currentUser->name, $link, self::SUBJECT);
         if ($result) {
             return ['user' => $user];
         } else {
             throw new ServerErrorHttpException("validation save fail");
         }
     }
     throw new ServerErrorHttpException("create user fail");
 }
コード例 #2
0
 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;
 }
コード例 #3
0
 private function _validateProperty($member)
 {
     $idValueMap = $member->getPropertyMap();
     //get all property
     $memberProperties = MemberProperty::getByAccount($member->accountId);
     foreach ($memberProperties as $memberProperty) {
         $id = $memberProperty->_id . '';
         //validate require
         if ($memberProperty->isRequired && !isset($idValueMap[$id])) {
             throw new InvalidParameterException([$id => \Yii::t('member', 'require_filed')]);
         }
         //validate unique
         if ($memberProperty->isUnique && isset($idValueMap[$id]) && $idValueMap[$id] != "") {
             $uniqueMember = Member::getByProperty($memberProperty->_id, $idValueMap[$id]);
             if (!empty($uniqueMember) && (empty($member->_id) || !empty($member->_id) && $uniqueMember->_id != $member->_id)) {
                 if ($memberProperty->name == 'tel') {
                     throw new InvalidParameterException([$id => \Yii::t('member', 'unique_tel_filed')]);
                 } else {
                     throw new InvalidParameterException([$id => \Yii::t('member', 'unique_filed')]);
                 }
             }
         }
         //validate email
         if ($memberProperty->name === Member::DEFAULT_PROPERTIES_EMAIL && !empty($idValueMap[$id]) && !StringUtil::isEmail($idValueMap[$id])) {
             throw new InvalidParameterException([$id => \Yii::t('member', 'email_format_error')]);
         }
     }
 }
コード例 #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'];
 }
コード例 #5
0
 public function validateEmail($Emailarray, $EmailParams, $properties, $result, $realTitles, $titles)
 {
     extract($Emailarray);
     extract($EmailParams);
     if (!empty($value) && StringUtil::isEmail($value) == false) {
         $this->storeError($redis, $Emailarray, $args);
         return false;
     }
     return ['id' => $properties[$titleIndex]['_id'], 'name' => $properties[$titleIndex]['isDefault'] == true ? $titles[$titleIndex] : $result[$realTitles[$titleIndex]], 'value' => $value];
 }