本文整理汇总了PHP中common\models\User::generateSecretKey方法的典型用法代码示例。如果您正苦于以下问题:PHP User::generateSecretKey方法的具体用法?PHP User::generateSecretKey怎么用?PHP User::generateSecretKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\User
的用法示例。
在下文中一共展示了User::generateSecretKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reg
public function reg()
{
$user = new User();
$user->phone = $this->phone;
$user->email = $this->email;
$user->status = $this->status;
$user->setPassword($this->password);
$user->generateAuthKey();
if ($this->scenario === 'emailActivation') {
$user->generateSecretKey();
}
$transaction = Yii::$app->db->beginTransaction();
try {
if ($user->save()) {
$modelProfile = new Profile();
$modelProfile->user_id = $user->id;
if ($modelProfile->save()) {
$transaction->commit();
return RbacHelper::assignRole($user->getId()) ? $user : null;
}
} else {
return false;
}
} catch (Exception $e) {
$transaction->rollBack();
}
}
示例2: onAuthSuccess
public function onAuthSuccess($client)
{
/* @var $client \yii\authclient\OAuth2*/
/* @var $user \common\models\User */
$attributes = $client->getUserAttributes();
/* @var $auth Auth */
$auth = Auth::find()->where(['source' => $client->getId(), 'source_id' => $attributes['id']])->one();
if (Yii::$app->user->isGuest) {
if ($auth) {
// вход
$user = $auth->user;
if ($user->status == User::STATUS_NOT_ACTIVE && $user->email == '') {
Yii::$app->getSession()->setFlash('success', [Yii::t('app', "To complete registration, enter the phone number and confirm the e-mail address.")]);
return $this->redirectUser($url = Url::to(['/main/finish-reg', 'id' => $user->id]));
} elseif ($user->status == User::STATUS_NOT_ACTIVE && $user->email != '') {
Yii::$app->getSession()->setFlash('success', [Yii::t('app', "To complete registration, enter a phone number.")]);
return $this->redirectUser($url = Url::to(['/main/finish-reg', 'id' => $user->id]));
} elseif ($user->status == User::STATUS_DELETED) {
Yii::$app->getSession()->setFlash('error', [Yii::t('app', "This user is blocked.")]);
return $this->redirectUser($url = Url::to(['/ad/view/all']));
}
Yii::$app->user->login($user);
} else {
// регистрация
if (isset($attributes['email']) && ($user = User::findOne(['email' => $attributes['email']]))) {
// Если пользователь регитрировался ранее через форму регистации.
if ($user) {
if ($user->status == User::STATUS_DELETED) {
Yii::$app->getSession()->setFlash('error', Yii::t('app', "User <strong> {email} </strong> blocked.", ['email' => $user->email]));
} elseif ($user->auths->source) {
Yii::$app->getSession()->setFlash('error', [Yii::t('app', "Authorization using the email address <strong> {email} </strong> is already happening through the account <strong> {auths} </strong>.\n Log on using the account <strong> {auths} </strong> or use the link <strong> Forgot your password? </strong> for email <strong> {email} </strong> to restore the password..", ['email' => $user->email, 'auths' => $user->auths->source])]);
} else {
Yii::$app->getSession()->setFlash('error', Yii::t('app', "Authorization using the email address <strong> {email} </strong> has successfully passed through the registration form. Click on the link <strong> Forgot your password? </strong> to restore the password.", ['email' => $user->email]));
}
}
return $this->redirectUser($url = Url::to(['/main/login']));
} else {
// Полученные данные заносим в переменные
/* @var $email string */
/* @var $first_name string */
/* @var $last_name string */
if (Yii::$app->request->get('authclient') == 'google') {
$first_name = $attributes['name']['givenName'];
$last_name = $attributes['name']['familyName'];
$email = $attributes['emails'][0]['value'];
} elseif (Yii::$app->request->get('authclient') == 'yandex') {
$first_name = $attributes['first_name'];
$last_name = $attributes['last_name'];
$email = $attributes['default_email'];
} elseif (Yii::$app->request->get('authclient') == 'facebook') {
$names = explode(' ', $attributes['name']);
$first_name = $names[0];
$last_name = $names[1];
$email = $attributes['email'];
} elseif (Yii::$app->request->get('authclient') == 'vkontakte') {
$first_name = $attributes['first_name'];
$last_name = $attributes['last_name'];
$email = false;
} elseif (Yii::$app->request->get('authclient') == 'twitter') {
$names = $attributes['name'];
$names = explode(' ', $names);
$first_name = $names[0];
$last_name = $names[1];
$email = false;
} elseif (Yii::$app->request->get('authclient') == 'linkedin') {
$first_name = $attributes['first_name'];
$last_name = $attributes['last_name'];
$email = $attributes['email'];
}
$password = Yii::$app->security->generateRandomString(6);
if ($email == false) {
$email = '';
}
$user = new User(['email' => $email, 'password' => $password, 'status' => User::STATUS_NOT_ACTIVE, 'country_id' => 182]);
$user->generateAuthKey();
$user->generateSecretKey();
$transaction = $user->getDb()->beginTransaction();
if ($user->save()) {
$auth = new Auth(['user_id' => $user->id, 'source' => $client->getId(), 'source_id' => (string) $attributes['id']]);
if ($auth->save()) {
/* @var $modelProfile /common/models/UserProfile */
$modelProfile = new UserProfile();
$modelProfile->user_id = $user->id;
$modelProfile->first_name = $first_name;
$modelProfile->last_name = $last_name;
if ($modelProfile->save()) {
if (RbacHelper::assignRole($user->id)) {
$modelUserPrivilege = new UserPrivilege();
$modelUserPrivilege->link('user', $user);
$transaction->commit();
}
// если нет емайл, делаем перенаправление на main/finish-reg
if ($email == false) {
Yii::$app->getSession()->setFlash('success', [Yii::t('app', "To complete registration, enter the phone number and confirm the e-mail address.")]);
return $this->redirectUser($url = Url::to(['/main/finish-reg', 'id' => $user->id]));
}
Yii::$app->getSession()->setFlash('success', [Yii::t('app', "To complete registration, enter a phone number.")]);
return $this->redirectUser($url = Url::to(['/main/finish-reg', 'id' => $user->id]));
}
} else {
//.........这里部分代码省略.........
示例3: reg
public function reg()
{
if ($this->validate()) {
$modelUser = new User();
$modelUser->phone = $this->getPhoneNumber();
$modelUser->email = $this->email;
$modelUser->status = $this->status;
$modelUser->country_id = $this->country_id;
$modelUser->setPassword($this->password);
$modelUser->generateAuthKey();
if ($this->scenario === 'emailActivation') {
$modelUser->generateSecretKey();
}
if ($modelUser->save()) {
$modelUserProfile = new UserProfile();
$modelUserProfile->link('user', $modelUser);
$modelUserPrivilege = new UserPrivilege();
$modelUserPrivilege->link('user', $modelUser);
return RbacHelper::assignRole($modelUser->getId()) ? $modelUser : null;
}
}
return false;
}
示例4: onAuthSuccess
public function onAuthSuccess($client)
{
/* @var $client \yii\authclient\OAuth2*/
/* @var $user \common\models\User */
$attributes = $client->getUserAttributes();
/* @var $auth Auth */
$auth = Auth::find()->where(['source' => $client->getId(), 'source_id' => $attributes['id']])->one();
if (Yii::$app->user->isGuest) {
if ($auth) {
// вход
$user = $auth->user;
if ($user->status == User::STATUS_NOT_ACTIVE && $user->email == '') {
Yii::$app->getSession()->setFlash('success', [Yii::t('app', "Для завершения регистрации введите телефон и подтвердите адрес электронной почты.")]);
return $this->redirectUser($url = Url::to(['/main/finish-reg', 'id' => $user->id]));
} elseif ($user->status == User::STATUS_NOT_ACTIVE && $user->email != '') {
Yii::$app->getSession()->setFlash('success', [Yii::t('app', "Для завершения регистрации введите номер телефона.")]);
return $this->redirectUser($url = Url::to(['/main/finish-reg', 'id' => $user->id]));
} elseif ($user->status == User::STATUS_DELETED) {
Yii::$app->getSession()->setFlash('error', [Yii::t('app', "Данный пользователь заблокирован.")]);
return $this->redirectUser($url = Url::to(['/main/index']));
}
Yii::$app->user->login($user);
} else {
// регистрация
if (isset($attributes['email']) && ($user = User::findOne(['email' => $attributes['email']]))) {
// Если пользователь регитрировался ранее через форму регистации.
if ($user->status == User::STATUS_ACTIVE) {
Yii::$app->getSession()->setFlash('error', Yii::t('app', "Авторизация с использованием электронного адреса <strong>" . $user->email . "</strong> уже успешно прошла через форму регистрации.\n Воспользуйте ссылкой <strong>" . '"Забыли пароль?"' . "</strong> для востанновления пароля."));
return $this->redirectUser($url = Url::to(['/main/login']));
} else {
Yii::$app->getSession()->setFlash('error', [Yii::t('app', "Авторизация с использованием электронного адреса <strong>" . $user->email . "</strong> уже происходила через аккунт <strong>" . $user->auths->source . "</strong>.\n Выполните вход используя аккаунт <strong>" . $user->auths->source . "</strong> или воспользуйте ссылкой <strong>" . '"Забыли пароль?"' . "</strong> для востанновления пароля для\n пользователя с емайл <strong>" . $user->email . "</strong>.", ['client' => $title = $client->getTitle()])]);
return $this->redirectUser($url = Url::to(['/main/login']));
}
} else {
// Полученные данные заносим в переменные
/* @var $email string */
/* @var $first_name string */
/* @var $second_name string */
if (Yii::$app->request->get('authclient') == 'google') {
$first_name = $attributes['name']['givenName'];
$second_name = $attributes['name']['familyName'];
$email = $attributes['emails'][0]['value'];
} elseif (Yii::$app->request->get('authclient') == 'yandex') {
$first_name = $attributes['first_name'];
$second_name = $attributes['last_name'];
$email = $attributes['default_email'];
} elseif (Yii::$app->request->get('authclient') == 'facebook') {
$names = explode(' ', $attributes['name']);
$first_name = $names[0];
$second_name = $names[1];
$email = $attributes['email'];
} elseif (Yii::$app->request->get('authclient') == 'vkontakte') {
$first_name = $attributes['first_name'];
$second_name = $attributes['last_name'];
$email = false;
} elseif (Yii::$app->request->get('authclient') == 'twitter') {
$names = $attributes['name'];
$names = explode(' ', $names);
$first_name = $names[0];
$second_name = $names[1];
$email = false;
} elseif (Yii::$app->request->get('authclient') == 'linkedin') {
$first_name = $attributes['first_name'];
$second_name = $attributes['last_name'];
$email = $attributes['email'];
}
$password = Yii::$app->security->generateRandomString(6);
$user = new User(['email' => $email, 'password' => $password, 'status' => User::STATUS_NOT_ACTIVE]);
$user->generateAuthKey();
$user->generateSecretKey();
$transaction = $user->getDb()->beginTransaction();
if ($user->save()) {
$auth = new Auth(['user_id' => $user->id, 'source' => $client->getId(), 'source_id' => (string) $attributes['id']]);
if ($auth->save()) {
/* @var $modelProfile /common/models/Profile */
$modelProfile = new Profile();
$modelProfile->user_id = $user->id;
$modelProfile->first_name = $first_name;
$modelProfile->second_name = $second_name;
if ($modelProfile->save()) {
$transaction->commit();
// если нет емайл, делаем перенаправление на main/finish-reg
if ($email == false) {
Yii::$app->getSession()->setFlash('success', [Yii::t('app', "Для завершения регистрации введите телефон и подтвердите адрес электронной почты.")]);
return $this->redirectUser($url = Url::to(['/main/finish-reg', 'id' => $user->id]));
}
Yii::$app->getSession()->setFlash('success', [Yii::t('app', "Для завершения регистрации введите номер телефона.")]);
return $this->redirectUser($url = Url::to(['/main/finish-reg', 'id' => $user->id]));
//Yii::$app->user->login($user);
}
} else {
//dd($user->errors);
print_r($auth->getErrors());
}
} else {
$user = User::findOne(['email' => $user->email]);
// Если пользователь регитрировался ранее через форму регистации.
if ($user->status == User::STATUS_ACTIVE) {
Yii::$app->getSession()->setFlash('error', Yii::t('app', "Авторизация с использованием электронного адреса <strong>" . $user->email . "</strong> уже успешно прошла через форму регистрации.\n Воспользуйте ссылкой <strong>" . '"Забыли пароль?"' . "</strong> для востанновления пароля."));
return $this->redirectUser($url = Url::to(['/main/login']));
//.........这里部分代码省略.........