本文整理汇总了PHP中app\models\User::generateAuthKey方法的典型用法代码示例。如果您正苦于以下问题:PHP User::generateAuthKey方法的具体用法?PHP User::generateAuthKey怎么用?PHP User::generateAuthKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\User
的用法示例。
在下文中一共展示了User::generateAuthKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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->generateAuthKey();
$user->avatar = 'avatar/0_{size}.png';
if ($this->action != self::ACTION_AUTH_SIGNUP) {
if (intval(Yii::$app->params['settings']['email_verify']) === 1) {
$user->status = User::STATUS_INACTIVE;
} else {
if (intval(Yii::$app->params['settings']['admin_verify']) === 1) {
$user->status = User::STATUS_ADMIN_VERIFY;
} else {
$user->status = User::STATUS_ACTIVE;
}
}
} else {
$user->status = User::STATUS_ACTIVE;
}
if ($user->save()) {
if ($this->action != self::ACTION_AUTH_SIGNUP && intval(Yii::$app->params['settings']['email_verify']) === 1) {
Token::sendActivateMail($user);
}
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->setPassword($this->password);
$user->generateAuthKey();
$user->status = 0;
if ($user->save()) {
Yii::$app->getSession()->setFlash('success', ['type' => 'success', 'duration' => 5000, 'icon' => 'fa fa-users', 'message' => 'Successfully Register', 'title' => 'Hi, ' . $user->username . ' Thanks for register..', 'positonY' => 'top', 'positonX' => 'left']);
$notification = new \sintret\gii\models\Notification();
$notification->title = 'user';
$notification->message = 'new user, username:' . $user->username;
$notification->params = \yii\helpers\Json::encode(['model' => 'User', 'id' => $user->id]);
if ($notification->save()) {
$this->sendEmail($this->email);
} else {
print_r($notification->getErrors());
exit(0);
}
return $user;
} else {
return $user->getErrors();
}
}
return null;
}
示例3: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate() && $this->checkConfirmPhone()) {
$user = new User();
$user->username = $this->phone;
$user->phone = $this->phone;
$user->firstname = $this->firstname;
$user->lastname = $this->lastname;
$user->birth_date = $this->birth_date;
$user->date_create = date('Y-m-d');
$user->city = $this->city;
$user->setPassword($this->password);
$user->generateAuthKey();
$myDate = \DateTime::createFromFormat('d.m.Y', $this->birth_date);
if ($myDate) {
$user->birth_date = $myDate->format('Y-m-d');
} else {
return null;
}
if ($user->save()) {
return Yii::$app->user->login($user, 3600 * 8);
}
}
return null;
}
示例4: save
public function save($profile, $urls)
{
$user = new User();
$user->email = $this->email;
$user->password = $this->password;
$user->setPassword($user->password);
$user->generateAuthKey();
$user->save(false);
$auth = Yii::$app->authManager;
$auth->assign($auth->getRole(User::ROLE_SHOP), $user->id);
$profile->user_id = $user->id;
$profile->host = $profile->getHost($profile->url);
$profile->status_id = 1;
$profile->save(false);
$url = new Url();
$url->user_id = $user->id;
$url->link = $profile->url;
$url->name = 'Главная страница';
$url->save(false);
if (is_array($urls)) {
foreach ($urls as $item) {
if (is_array($item)) {
$url = new Url();
$url->user_id = $user->id;
$url->link = $item['link'];
$url->name = $item['name'];
$url->save(false);
}
}
}
Yii::$app->mailer->compose('registration/shop', ['model' => $user])->setFrom(Yii::$app->params['emailFrom'])->setTo($this->email)->setSubject('Регистрация магазина')->send();
}
示例5: 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->generateAuthKey();
$user->status = 0;
if ($user->save()) {
$notification = new Notification();
$notification->title = 'user';
$notification->message = 'new user, username:' . $user->username;
$notification->params = \yii\helpers\Json::encode(['model' => 'User', 'id' => $user->id]);
if ($notification->save()) {
$this->sendEmail($this->email);
} else {
print_r($notification->getErrors());
exit(0);
}
return $user;
} else {
return $user->getErrors();
}
}
return null;
}
示例6: actionCreate
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new User();
if (Yii::$app->request->post()) {
$transaction = User::getDb()->beginTransaction();
try {
$model->scenario = User::SCENARIO_CREATE;
$model->load(Yii::$app->request->post());
$model->setPassword(Yii::$app->request->post()['User']['password']);
$model->generateAuthKey();
if ($model->save()) {
foreach (Yii::$app->request->post()['User']['empresa_id'] as $emp_id) {
$modelEmpresasUsuarios = new EmpresasUsuarios();
$modelEmpresasUsuarios->empresa_id = $emp_id;
$modelEmpresasUsuarios->usuario_id = $model->id;
if (!$modelEmpresasUsuarios->save()) {
throw new Exception('Não foi possível salvar uma das empresas!');
}
}
$auth = Yii::$app->authManager;
$auth->revokeAll($model->id);
$userRole = $auth->getRole(Yii::$app->request->post()['User']['user_role']);
$auth->assign($userRole, $model->id);
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
} catch (Exception $e) {
$transaction->rollBack();
throw new HttpException(400, '$e');
}
} else {
return $this->render('create', ['model' => $model]);
}
}
示例7: 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->generateAuthKey();
$user->mobile = $this->mobile;
$user->user_extra1 = $this->user_extra1;
//上传用户信息图片, 多文件上传, 最多2张图
$tmpStr2 = "";
$this->files = UploadedFile::getInstances($this, 'files');
foreach ($this->files as $file) {
//$user->files = UploadedFile::getInstances($user, 'files');
//foreach ($user->files as $file)
//{
$targetFileId = date("YmdHis") . '-' . uniqid();
$ext = pathinfo($file->name, PATHINFO_EXTENSION);
$targetFileName = "{$targetFileId}.{$ext}";
$targetFile = Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . SignupForm::PHOTO_PATH . DIRECTORY_SEPARATOR . $targetFileName;
$file->saveAs($targetFile);
//$tmpStr2 = $tmpStr2 . "{$targetFile};";
$tmpStr2 = $tmpStr2 . "/user/photo/{$targetFileName};";
}
$user->user_extra2 = $tmpStr2;
if ($user->save()) {
return $user;
}
}
return null;
}
示例8: actionRegister
public function actionRegister()
{
$errors = null;
$model = new UserForm();
if (Yii::$app->request->isPost) {
$model->setAttributes(Yii::$app->request->post());
if ($model->validate()) {
$user = new User();
$user->setAttributes($model->getAttributes());
$user->setPassword($model->password);
$user->generateAuthKey();
$save = $user->save();
if ($save) {
$purse = new Purse();
$purse->user_id = $user->id;
$purse->active = 1;
$purse->balance = 0;
$purse->name = "Основной";
$purse->save();
$login = Yii::$app->user->login($user, 3600 * 24 * 14);
if ($login) {
return $this->goHome();
}
}
} else {
$errors = $model->getErrors();
}
}
return $this->renderPartial('register', ['errors' => $errors, 'model' => $model]);
}
示例9: actionLogin
public function actionLogin()
{
/** @var $eauth \nodge\eauth\ServiceBase */
$eauth = Yii::$app->get('eauth')->getIdentity('steam');
$eauth->setRedirectUrl(Yii::$app->getUser()->getReturnUrl());
$eauth->setCancelUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('site/login'));
try {
if ($eauth->authenticate()) {
$identity = User::findByEAuth($eauth);
$user = User::findOne(['steamid' => $identity->steamid]);
if (!$user) {
$user = new User();
}
$user->username = $identity->username;
$user->steamid = $identity->steamid;
$user->profile_url = $identity->profile_url;
$user->avatar = $identity->avatar;
$user->avatar_md = $identity->avatar_md;
$user->avatar_lg = $identity->avatar_lg;
$user->generateAuthKey();
$user->save();
Yii::$app->getUser()->login($identity);
$eauth->redirect();
} else {
$eauth->cancel();
}
} catch (ErrorException $e) {
Yii::$app->getSession()->setFlash('error', 'EAuthException: ' . $e->getMessage());
$eauth->redirect($eauth->getCancelUrl());
}
}
示例10: actionCreate
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new User();
if ($model->load(Yii::$app->request->post())) {
$model->setPassword($model->password);
$model->username = $model->email;
if ($model->save()) {
$model->generateAuthKey();
if ($model->user_role == 'host') {
// the following three lines were added:
$auth = Yii::$app->authManager;
$hostRole = $auth->getRole('host');
$auth->assign($hostRole, $model->id);
// return $this->redirect(['hosts/index', 'id' => $model->id]);
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
return $this->render('create', ['model' => $model]);
}
} else {
return $this->render('create', ['model' => $model]);
}
}
示例11: actionInit
public function actionInit()
{
//roles
//user admin psychologist school
$auth = Yii::$app->authManager;
//$user = $auth->createRole('user');
$adminUser = new User();
$adminUser->email = 'admin@gmail.com';
$adminUser->setPassword('123456');
$adminUser->generateAuthKey();
$adminUser->save();
$admin = $auth->createRole('admin');
$auth->add($admin);
$averageUser = new User();
$averageUser->email = 'user@gmail.com';
$averageUser->setPassword('123456');
$averageUser->generateAuthKey();
$averageUser->save();
$profile = new Profile();
$model = new SignupForm();
$model->first_name = "Юзер";
$model->last_name = "Юзерович";
$model->second_name = "Юзеров";
$profile->initProfile($model, $averageUser->id);
$user = $auth->createRole('user');
$auth->add($user);
/* $accessAdmin = $auth->createPermission('accessAdmin');
$accessAdmin->description = 'Access admin';
$auth->add($accessAdmin);
$auth->addChild($admin, $accessAdmin);*/
//$psychologist = $auth->createRole('psychologist');
/*// add "createPost" permission
$createPost = $auth->createPermission('createPost');
$createPost->description = 'Create a post';
$auth->add($createPost);
// add "updatePost" permission
$updatePost = $auth->createPermission('updatePost');
$updatePost->description = 'Update post';
$auth->add($updatePost);
// add "author" role and give this role the "createPost" permission
$author = $auth->createRole('author');
$auth->add($author);
$auth->addChild($author, $createPost);
// add "admin" role and give this role the "updatePost" permission
// as well as the permissions of the "author" role
$admin = $auth->createRole('admin');
$auth->add($admin);
$auth->addChild($admin, $updatePost);
$auth->addChild($admin, $author);
// Assign roles to users. 1 and 2 are IDs returned by IdentityInterface::getId()
// usually implemented in your User model.
$auth->assign($author, 2);*/
$auth->assign($admin, 1);
$auth->assign($user, 2);
}
示例12: createUser
protected function createUser($username, $typeRole)
{
$user = new User(['username' => $username, 'status' => User::STATUS_ACTIVE, 'email' => $username . '@' . Yii::$app->params['domain']]);
$user->setPassword('123456');
$user->generateAuthKey();
$user->save(false);
$this->assign($user, $typeRole);
}
示例13: reg
public function reg()
{
$user = new User();
$user->name = $this->name;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
return $user->save(false) && empty($this->getErrors()) ? $user : null;
}
示例14: reg
public function reg()
{
$user = new User();
$user->login = $this->login;
$user->setPassword($this->pass);
$user->email = $this->email;
$user->generateAuthKey();
return $user->save() ? $user : null;
}
示例15: reg
public function reg()
{
$user = new User();
$user->username = $this->username;
$user->name = $this->name;
$user->setPassword($this->password);
$user->generateAuthKey();
return $user->save() ? $user : null;
}