当前位置: 首页>>代码示例>>PHP>>正文


PHP User::getByEmail方法代码示例

本文整理汇总了PHP中backend\models\User::getByEmail方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getByEmail方法的具体用法?PHP User::getByEmail怎么用?PHP User::getByEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在backend\models\User的用法示例。


在下文中一共展示了User::getByEmail方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionCreate

 /**
  * 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" : "sarazhang@augmentum.com.cn",
  *     "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:"sarazhang@augmentum.com.cn", 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");
 }
开发者ID:timelessmemory,项目名称:uhkklp,代码行数:69,代码来源:UserController.php

示例2: actionGenerateByEmail

 /**
  * create a user by email(generate-by-email)
  */
 public function actionGenerateByEmail($email)
 {
     $email = mb_strtolower($email);
     $user = User::getByEmail($email);
     if (!empty($user)) {
         echo 'email is used' . PHP_EOL;
         return;
     }
     $name = Yii::$app->params['defaultName'];
     $accountId = Account::create('', '', $name);
     $attributes = ['status' => Account::STATUS_ACTIVATED, 'availableExtMods' => Yii::$app->params['extMods'], 'serviceStartAt' => new \MongoDate()];
     Account::updateAll($attributes, ['_id' => $accountId]);
     $salt = StringUtil::rndString(6);
     $password = User::encryptPassword(md5(Yii::$app->params['defaultPwd']), $salt);
     $user = new User();
     $user->email = $email;
     $user->accountId = $accountId;
     $user->name = $name;
     $user->role = User::ROLE_ADMIN;
     $user->isActivated = User::ACTIVATED;
     $user->avatar = Yii::$app->params['defaultAvatar'];
     $user->language = Yii::$app->params['defaultLanguage'];
     $user->salt = $salt;
     $user->password = $password;
     if (!$user->save()) {
         Account::deleteAll(['_id' => $accountId]);
         SensitiveOperation::deleteAll(['accountId' => $accountId]);
         MessageTemplate::deleteAll(['accountId' => $accountId]);
         echo 'create account fail' . PHP_EOL;
     } else {
         echo 'create account successfully' . PHP_EOL;
     }
 }
开发者ID:timelessmemory,项目名称:uhkklp,代码行数:36,代码来源:AccountController.php

示例3: actionSendResetPasswordEmail

 /**
  * 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'];
 }
开发者ID:timelessmemory,项目名称:uhkklp,代码行数:36,代码来源:SiteController.php


注:本文中的backend\models\User::getByEmail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。