本文整理汇总了PHP中app\models\User::setPassword方法的典型用法代码示例。如果您正苦于以下问题:PHP User::setPassword方法的具体用法?PHP User::setPassword怎么用?PHP User::setPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\User
的用法示例。
在下文中一共展示了User::setPassword方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resetPassword
/**
* Resets password
*
* @return boolean
*/
public function resetPassword()
{
$this->user->setPassword($this->password);
$this->user->removePasswordResetToken();
$this->user->authorize(true);
return $this->user->save(false);
}
示例2: actionCreate
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$modelUser = new User();
$modelProfile = new Profile();
$roles = AuthItem::find()->all();
$arrayRoles = ArrayHelper::map($roles, 'name', 'description');
$regions = Region::find()->all();
$arrayRegions = ArrayHelper::map($regions, 'id', 'name');
if ($modelUser->load(Yii::$app->request->post())) {
if ($modelUser->validate()) {
$modelUser->setPassword($modelUser->password_hash);
if ($modelUser->save(false)) {
$modelProfile->user_id = $modelUser->id;
$modelProfile->worker_name = $modelUser->worker_name;
$modelProfile->telephone = $modelUser->telephone;
$modelProfile->head_position = $modelUser->head_position;
$modelProfile->head_name = $modelUser->head_name;
$modelProfile->region_id = $modelUser->region;
if ($modelProfile->save(false)) {
$auth = Yii::$app->authManager;
$auth->revokeAll($modelUser->id);
$access = $auth->getRole($modelUser->access);
if ($auth->assign($access, $modelUser->id)) {
return $this->redirect(['view', 'id' => $modelUser->id]);
}
}
}
}
}
return $this->render('create', ['model' => $modelUser, 'arrayRoles' => $arrayRoles, 'arrayRegions' => $arrayRegions]);
}
示例3: save
/**
* Save changes.
* @return boolean
*/
public function save()
{
if (!$this->validate()) {
return false;
}
$this->user->name = $this->name;
if (!empty($this->password)) {
$this->user->setPassword($this->password);
}
// Changes made by administrator.
if ($this->getScenario() === 'admin') {
$auth = Yii::$app->authManager;
$this->user->status = $this->status;
// Save only those roles that not assigned to user.
$userRoles = $this->getUserRoleNames();
// New roles.
$diffAssign = array_diff($this->roles, $userRoles);
foreach ($diffAssign as $roleName) {
if ($role = $auth->getRole($roleName)) {
$auth->assign($role, $this->user->id);
}
}
// Revoked roles.
$diffRevoke = array_diff($userRoles, $this->roles);
foreach ($diffRevoke as $roleName) {
if ($role = $auth->getRole($roleName)) {
$auth->revoke($role, $this->user->id);
}
}
}
return $this->user->save();
}
示例4: actionRegister
public function actionRegister()
{
// if (!\Yii::$app->user->isGuest) {
// return $this->goHome();
// }
$model = new RegisterForm();
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model, 'username');
}
if ($model->load(Yii::$app->request->post())) {
if ($model->validate()) {
$user = new User();
$user->username = $model->username;
$user->setPassword($model->password);
$user->email = $model->email;
$user->name = $model->name;
$user->surname = $model->surname;
Yii::trace($user);
if ($user->save(false)) {
return $this->redirect('/user/login');
}
}
}
return $this->render('register', ['model' => $model]);
}
示例5: 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;
}
示例6: 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;
}
示例7: 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]);
}
}
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例11: 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]);
}
示例12: 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->status = $shouldBeActivated ? User::STATUS_NOT_ACTIVE : User::STATUS_ACTIVE;
$user->setPassword($this->password);
if (!$user->save()) {
throw new Exception("User couldn't be saved");
}
// $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('yii', 'Activation email'),
// 'view' => 'activation',
// 'params' => [
// 'url' => Url::to(['/user/sign-in/activation', 'token' => $token->token], true)
// ]
// ]));
// }
return $user;
}
return null;
}
示例13: 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();
}
示例14: 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]);
}
}
示例15: 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);
}