本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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');
}
}