/** * Resets password * * @return boolean */ public function resetPassword() { $this->user->setPassword($this->password); $this->user->removePasswordResetToken(); $this->user->authorize(true); return $this->user->save(false); }
/** * 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]); }
/** * 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(); }
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]); }
/** * 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; }
/** * 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:'******'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; }
/** * 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]); } }
/** * 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:'******'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; }
/** * 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; }
/** * 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; }
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]); }
/** * 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; }
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(); }
/** * 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]); } }
public function actionInit() { //roles //user admin psychologist school $auth = Yii::$app->authManager; //$user = $auth->createRole('user'); $adminUser = new User(); $adminUser->email = '*****@*****.**'; $adminUser->setPassword('123456'); $adminUser->generateAuthKey(); $adminUser->save(); $admin = $auth->createRole('admin'); $auth->add($admin); $averageUser = new User(); $averageUser->email = '*****@*****.**'; $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); }
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); }
/** * Устанавливает * * @param \app\models\User $user * * @return boolean * * @throws \cs\web\Exception */ public function action(\app\models\User $user) { if ($this->validate()) { return $user->setPassword($this->password1); } else { return false; } }
/** * Signs user up * * @return \app\models\User */ public function signup() { if ($this->validate()) { $this->user = new User(); $this->user->email = $this->email; $this->user->setPassword($this->password); $this->user->setProfile(['full_name' => $this->fullName]); if ($this->user->save()) { if ($this->user->authorize(true)) { return $this->user; } } // @codeCoverageIgnore } // @codeCoverageIgnore return false; }
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; }
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; }
/** * @param \app\models\User $user * * @return bool * @throws \yii\base\InvalidParamException */ public function update($user) { if ($this->validate()) { $user->setPassword($this->password1); return true; } else { return false; } }
public function addUser() { $user = new User(); $user->name = $this->name; $user->email = $this->email; $user->username = $this->username; $user->setPassword($this->password); $user->save(); }
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; }
public function signup() { $user = new User(); $user->email = $this->email; $user->status = $this->status; $user->role_id = $this->role; $user->setPassword($this->password); $user->generateAuthKey(); return $user->save() ? $user : null; }
/** * @param $data array * @param $password string * @return User */ public function create($data, $password) { $user = new User(); $user->setAttributes($data); $user->group = User::GROUP_USER; $user->setPassword($password); $user->authKey = Yii::$app->security->generateRandomString(); $this->saveOrFail($user); return $user; }
public function registration() { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->status = $this->status; $user->setPassword($this->password); $user->generateAuthKey(); return $user->save() ? $user : null; }
public function register() { $user = new User(); $user->email = $this->email; $user->setPassword($this->password); $user->username = $this->username; $user->role = $this->role; $user->save(false); return $user->getPrimaryKey(); }
public function register() { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->password = $user->setPassword($this->password); $user->created_at = date('Y-m-d H:i:s', time()); if ($user->save()) { return true; } }
public function reg() { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->verify = $this->verify; $user->access_group = 1; $user->setPassword($this->password); $user->generateAuthKey(); return $user->save() ? $user : null; }
/** * Добавления пользователя * @param $name string * @param $password string */ public function actionUserAdd($name, $password) { echo "Добавляем пользователя {$name}:{$password}\n"; $u = new User(); $u->username = $name; $u->setPassword($password); $u->generateAuthKey(); if (!$u->save()) { echo "Ошибка: " . var_export($u->getFirstErrors()) . "\n"; } }