當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::afterSignup方法代碼示例

本文整理匯總了PHP中common\models\User::afterSignup方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::afterSignup方法的具體用法?PHP User::afterSignup怎麽用?PHP User::afterSignup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在common\models\User的用法示例。


在下文中一共展示了User::afterSignup方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->save();
         $user->afterSignup();
         return $user;
     }
     return null;
 }
開發者ID:dellirom,項目名稱:yii2-starter-kit,代碼行數:18,代碼來源:SignupForm.php

示例2: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->status = Yii::$app->keyStorage->get('frontend.email-confirm') ? User::STATUS_INACTIVE : User::STATUS_ACTIVE;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $user->save();
         $user->afterSignup();
         return $user;
     }
     return null;
 }
開發者ID:beaten-sect0r,項目名稱:yii2-core,代碼行數:20,代碼來源:SignupForm.php

示例3: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $shouldBeActivated = $this->shouldBeActivated();
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->is_activated = !$shouldBeActivated;
         $user->setPassword($this->password);
         $user->save();
         $user->afterSignup();
         if ($shouldBeActivated) {
             $token = UserToken::create($user->id, UserToken::TYPE_ACTIVATION, Time::SECONDS_IN_A_DAY);
             Yii::$app->commandBus->handle(new SendEmailCommand(['subject' => Yii::t('frontend', 'Activation email'), 'view' => 'activation', 'params' => ['url' => Url::to(['/user/sign-in/activation', 'token' => $token->token], true)]]));
         }
         return $user;
     }
     return null;
 }
開發者ID:icron,項目名稱:yii2-starter-kit,代碼行數:24,代碼來源:SignupForm.php

示例4: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->save();
         $user->afterSignup();
         $auth = Yii::$app->authManager;
         $auth->revokeAll($user->getId());
         if ($this->roles && is_array($this->roles)) {
             foreach ($this->roles as $role) {
                 $auth->assign($auth->getRole($role), $user->getId());
             }
         }
         return $user;
     }
     return null;
 }
開發者ID:Sywooch,項目名稱:AVSProduct,代碼行數:25,代碼來源:SignupForm.php

示例5: successOAuthCallback

 /**
  * @param $client \yii\authclient\BaseClient
  * @return bool
  * @throws Exception
  */
 public function successOAuthCallback($client)
 {
     // use BaseClient::normalizeUserAttributeMap to provide consistency for user attribute`s names
     $attributes = $client->getUserAttributes();
     $user = User::find()->where(['oauth_client' => $client->getName(), 'oauth_client_user_id' => ArrayHelper::getValue($attributes, 'id')])->one();
     if (!$user) {
         $user = new User();
         $user->scenario = 'oauth_create';
         $user->username = ArrayHelper::getValue($attributes, 'login');
         $user->email = ArrayHelper::getValue($attributes, 'email');
         $user->oauth_client = $client->getName();
         $user->oauth_client_user_id = ArrayHelper::getValue($attributes, 'id');
         $password = Yii::$app->security->generateRandomString(8);
         $user->setPassword($password);
         if ($user->save()) {
             $user->afterSignup();
             $sentSuccess = Yii::$app->commandBus->handle(new SendEmailCommand(['view' => 'oauth_welcome', 'params' => ['user' => $user, 'password' => $password], 'subject' => Yii::t('frontend', '{app-name} | Your login information', ['app-name' => Yii::$app->name]), 'to' => $user->email]));
             if ($sentSuccess) {
                 Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-success'], 'body' => Yii::t('frontend', 'Welcome to {app-name}. Email with your login information was sent to your email.', ['app-name' => Yii::$app->name])]);
             }
         } else {
             // We already have a user with this email. Do what you want in such case
             if (User::find()->where(['email' => $user->email])->count()) {
                 Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-danger'], 'body' => Yii::t('frontend', 'We already have a user with email {email}', ['email' => $user->email])]);
             } else {
                 Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-danger'], 'body' => Yii::t('frontend', 'Error while oauth process.')]);
             }
         }
     }
     if (Yii::$app->user->login($user, 3600 * 24 * 30)) {
         return true;
     } else {
         throw new Exception('OAuth error');
     }
 }
開發者ID:rzrio,項目名稱:enterprise-portal,代碼行數:40,代碼來源:SignInController.php


注:本文中的common\models\User::afterSignup方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。