/** * Регистрация нового пользователя * * @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; $randLength = mt_rand(6, 9); $this->password = Yii::$app->security->generateRandomString($randLength); $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { //$profile = new Profile(); //$profile->user_id = $user->id; //$profile->name = $this->name; ////если в куках есть id аффилиата, сохраняем его //$affiliateId = (int) Yii::$app->request->cookies['affiliate']; //if ($affiliateId > 0 && User::findIdentity($affiliateId)) { //$profile->user_affiliate_id = $affiliateId; //} //$profile->save(); // Присвоить роль пользователю можно при создании нового пользователя. // присвоить Роль "user" новому пользователю // `auth_assignment` $userRole = Yii::$app->authManager->getRole('user'); Yii::$app->authManager->assign($userRole, $user->getId()); return $this->sendRegistrationEmail(); } } 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->nama = $this->nama; $user->email = $this->email; $user->setPassword($this->password); $user->tanggal_lahir = $this->tanggal_lahir; $user->fakultas = $this->fakultas; $user->jurusan = $this->jurusan; $user->angkatan = $this->angkatan; $user->pekerjaan = $this->pekerjaan; $user->alamat_rumah = $this->alamat_rumah; $user->alamat_domilisi = $this->alamat_domilisi; $user->no_hp = $this->no_hp; $user->id_line = $this->id_line; $user->foto = 'uploads/' . $this->foto; $user->generateAuthKey(); 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(); // Add field for project lifeguard 9/2015 $user->code = $this->code; $user->referrer = $this->referrer; $user->first_name = $this->first_name; $user->last_name = $this->last_name; $user->sex = $this->sex; $user->graduate_high_school = $this->graduate_high_school; $user->city = $this->city; $user->state = $this->state; $user->zip = $this->zip; $user->mobile = $this->mobile; $user->status = $this->status; if (!$user->save()) { throw new ErrorException("Error save information user"); } 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->status = User::STATUS_NOTACTIVATED; $b = $user->save(); $activationToken = new UserTokens(); $activationToken->user_id = $user->id; $activationToken->token_type = ETokenType::ACCOUNT_ACTIVATION; $activationToken->token = sha1(mt_rand(10000, 99999) . time() . $user->email); $activationToken->save(); $auth = Yii::$app->authManager; $userRole = $auth->getRole('user'); $auth->assign($userRole, $user->id); if ($b) { $x = new UserInfo(); $x->user_id = $user->id; $x->save(); EventService::createEvent(EEvent::ACCOUNT_CREATE(), new UserId($user->id)); $this->sendActivationMail($user, $activationToken->token); return $user; } } return null; }
/** * Signs user up. * * @return true|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->phone = $this->phone; $user->email = $this->email; $randLength = mt_rand(6, 9); $this->password = Yii::$app->security->generateRandomString($randLength); $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { $profile = new Profile(); $profile->user_id = $user->id; $profile->name = $this->name; //если в куках есть id аффилиата, сохраняем его $affiliateId = (int) Yii::$app->request->cookies['affiliate']; if ($affiliateId > 0 && User::findIdentity($affiliateId)) { $profile->user_affiliate_id = $affiliateId; } $profile->save(); return $this->sendRegistrationEmail(); } } return null; }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new Admin(); $user->fname = $this->fname; $user->lname = $this->lname; $user->contact_no = $this->contact_no; $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->company_name = $this->company_name; $user->company_description = $this->company_description; $user->shipping_address = $this->shipping_address; $user->generateAuthKey(); $user1 = new User(); $user1->fname = $this->fname; $user1->lname = $this->lname; $user1->contact_no = $this->contact_no; $user1->username = $this->username; $user1->email = $this->email; $user1->setPassword($this->password); $user1->company_name = $this->company_name; $user1->company_description = $this->company_description; $user1->shipping_address = $this->shipping_address; $user1->generateAuthKey(); if ($user->save() && $user1->save()) { return $user; return $user1; } } return null; }
/** * Resets password. * * @return boolean if password was reset. */ public function resetPassword() { if (!empty($this->password)) { $this->_user->password_hash = Yii::$app->security->generatePasswordHash($this->password); } return $this->_user->save(); }
/** * Logs in a user. * * @return mixed */ 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()); } }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->company_id = $this->company_id; $user->first_name = $this->first_name; $user->last_name = $this->last_name; $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { $permissionList = $_POST['SignupForm']['permissions']; foreach ($permissionList as $value) { $newPermissions = new AuthAssignment(); $newPermissions->user_id = $user->id; $newPermissions->item_name = $value; $newPermissions->save(); $newPermissions->getErrors(); } 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->type = $this->type; $user->first_name = $this->first_name; $user->last_name = $this->last_name; $user->full_name = $this->first_name . " " . $this->last_name; $user->age = $this->age; $user->gender = $this->gender; $user->birthdate = $this->birthdate; $user->address = $this->address; if ($this->type == 'Student') { $user->section_id = $this->section_id; $user->level_id = $this->level_id; } else { $user->section_id = ''; $user->level_id = ''; } $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { Yii::$app->session->setFlash('success'); } else { Yii::$app->session->setFlash('failed'); } } return null; }
/** * Signs company up. * * @return User|null the saved model or null if saving fails */ public function signupCompany() { if ($this->validate()) { $user = new User(); $user->username = $this->name; $user->email = $this->email; $user->phone = $this->phone; $user->setPassword($this->password); $user->generateAuthKey(); $check_user = $user->save(); $service = new Service(); $service->category_id = $this->category_id; $service->owner = $user->id; $service->name = $this->name; $service->phone = $this->phone; $service->description = $this->description; $check_service = $service->save(); if ($check_user && $check_service) { return $user; } VarDumper::dump($service->getErrors(), 6, 1); die; } 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->gender = $this->gender; $user->firstname = $this->firstname; $user->lastname = $this->lastname; $user->username = $this->email; $user->email = $this->email; $user->birthday = $this->birthday; $user->user_role = $this->user_role; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { if ($user->user_role == 'host') { $auth = Yii::$app->authManager; $hostRole = $auth->getRole('host'); $auth->assign($hostRole, $user->id); } elseif ($user->user_role == 'traveller') { $auth = Yii::$app->authManager; $hostRole = $auth->getRole('traveller'); $auth->assign($hostRole, $user->id); } return $user; } } 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(); $model->scenario = 'create'; $userData = new UserData(); //$hotelMapping = new UserHotelMapping(); if ($model->load(Yii::$app->request->post()) && $userData->load(Yii::$app->request->post())) { $validUser = $model->validate(); $validUserData = $userData->validate(); //$validHotelMapping = $hotelMapping->validate(); if ($validUser && $validUserData) { // && $validHotelMapping $model->setPassword($model->password); $model->generateAuthKey(); if ($model->save()) { $userData->user_id = $model->id; //$hotelMapping->user_id = $model->id; $userData->save(false); //$hotelMapping->save(false); return $this->redirect(['view', 'id' => $model->id]); } } } return $this->render('create', ['model' => $model, 'userData' => $userData]); }
private function saveProject($model, $customer) { if (empty($model->customer_id)) { if (!empty($customer->name)) { // Save the project $user = new User(); $user->username = $customer->email_address; $user->email = $user->username; $user->status = User::STATUS_AWAITING_REQUEST; $user->save(false); $customer->user_id = $user->id; if ($customer->save(false)) { // We can save the contact $model->customer_id = $customer->customer_id; $model->creator_id = Yii::$app->user->id; return $model->save(false); } else { return false; } } } else { return $model->save(false); } return false; }
public function signup() { if ($this->validate()) { $user = new User(); $user->last_name = $this->last_name; $user->first_name = $this->first_name; $user->middle_name = $this->middle_name; $user->city_address = $this->city_address; $user->telephone_no = $this->telephone_no; $user->email = $this->email; $user->cellphone_no = $this->cellphone_no; $user->birth_month = $this->birth_month; $user->birth_date = $this->birth_date; $user->birth_year = $this->birth_year; $user->status = $this->status; $user->sex = $this->sex; $user->birth_place = $this->birth_place; $user->nationality = $this->nationality; $user->height = $this->height; $user->weight = $this->weight; $user->religion = $this->religion; if ($user->save()) { return $user; } } return null; }
/** * @param \nodge\eauth\ServiceBase $service * @return User * @throws ErrorException */ public static function findByEAuth($service) { if (!$service->getIsAuthenticated()) { throw new ErrorException('EAuth user should be authenticated before creating identity.'); } $service_id = $service->getServiceName() . '-' . $service->getId(); // find user auth $user_auth = AuthRecords::find()->where(["id" => $service_id])->one(); if (!isset($user_auth->user_id)) { $attributes = $service->getAttributes(); $nameFromService = isset($attributes['name']) ? $attributes['name'] : null; // add user $model = new User(); $model->username = $nameFromService ? $nameFromService : $service_id; $model->auth_key = md5($service_id); $model->password_hash = "asd" . rand(0, 1045693); // $model->email = ""; $model->save(); $user_id = $model->id; // add auth $new_auth = new AuthRecords(); $new_auth->id = $service_id; $new_auth->user_id = $user_id; $new_auth->attributes = serialize($service->getAttributes()); $new_auth->save(); } else { $user_id = $user_auth->user_id; } return user::findIdentity($user_id); }
/** * Create init user */ public function actionUser() { echo "Create init user ...\n"; // 提示当前操作 $username = $this->prompt('User Name:'); // 接收用户名 $email = $this->prompt('Email:'); // 接收Email $password = $this->prompt('Password:'); // 接收密码 $model = new User(); // 创建一个新用户 $model->username = $username; // 完成赋值 $model->email = $email; $model->password = $password; if (!$model->save()) { foreach ($model->getErrors() as $error) { foreach ($error as $e) { echo "{$e}\n"; } } return 1; // 命令行返回1表示有异常 } return 0; // 返回0表示一切OK }
public static function avatar(User $user, $size = 60, $options = []) { $size = (int) $size; unset($options['height'], $options['width']); static::addCssClass($options, 'ava'); if ($src = $user->getAvatar($size)) { return static::img($src, $options); } else { $cssStyleName = ''; foreach (User::$sizesAvatar as $sizeK => $cssStyleName) { if ($sizeK >= $size) { break; } } mb_internal_encoding("UTF-8"); $char1 = mb_substr($user->username, 0, 1); $char2 = mb_substr($user->username, 1, 1); $charList = array_merge(String::$charsEng, String::$charsRus); $posCount = count($charList); $pos = array_search(mb_strtolower($char1), $charList) ?: 0; $pos2 = array_search(mb_strtolower($char2), $charList) ?: 0; $count = count(static::$colorsAvatar); $colorKey = (int) floor(($pos + $pos2) / ($posCount * 2) * $count); list($backgroundCol, $textCol) = isset(static::$colorsAvatar[$colorKey]) ? static::$colorsAvatar[$colorKey] : current(self::$colorsAvatar); static::addCssClass($options, 'fake-avatar'); static::addCssClass($options, 'fake-avatar-' . $cssStyleName); static::addCssStyle($options, "color:#{$textCol};background:#{$backgroundCol}"); return static::tag('div', $char1 . $char2, $options); } }
/** * @return bool */ public function signup() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->setPassword($this->password); $user->email = $this->email; $user->generateAuthKey(); $user->generateActivateToken(); $user->status = User::STATUS_NO_ACTIVATE; $user->lastName = $this->lastName; $user->firstName = $this->firstName; $user->middleName = $this->middleName; $user->division = $this->division; $user->post = $this->post; $user->phone = $this->phone; $user->mobile = $this->mobile; if ($this->sendEmail($user) && $user->save()) { $authManager = \Yii::$app->authManager; $employeeRole = $authManager->getRole(SystemRole::EMPLOYEE); $authManager->assign($employeeRole, $user->primaryKey); return true; } } return false; }
public function actionCreateuser() { $userModel = User::findOne(['user_name' => yii::$app->request->post('user_name')]); if ($userModel === null) { $userModel = new User(); $userModel->load(yii::$app->request->post()); if ($userModel->save()) { yii::$app->AjaxResponse->error = false; yii::$app->AjaxResponse->message = ['User has been created']; yii::$app->UserComponent->sendWelcomeEmail($userModel->first_name, $userModel->email); } else { yii::$app->AjaxResponse->message = array_values($userModel->getErrors()); } } else { // user exits but is not active if ($userModel->status_id != Types::$status['active']['id']) { $userModel->status_id = Types::$status['active']['id']; $userModel->save(); yii::$app->AjaxResponse->error = false; yii::$app->AjaxResponse->message = ['User reactivated']; } else { yii::$app->AjaxResponse->message = ['User already exists']; } } yii::$app->AjaxResponse->sendContent(); }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if (!$this->validate()) { return false; } $transaction = Yii::$app->db->beginTransaction(); try { $key = User::generateDynamicKey(); $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); $user->setDynamicKey($key, User::DYNAMIC_KEY_ACTIVATE_LIFE); $user->save(); $title = 'Activate Account on find.forfreedomandlove.com'; $content = "<br><br>" . 'Click the following link to activate the account you have registered on find.forfreedomandlove.com'; $content .= "<br><a href=\"https://find.forfreedomandlove.com/user/index/activate/{$user->id}/{$key}\" target=\"_blank\">"; $content .= "https://find.forfreedomandlove.com/user/index/activate/{$user->id}/{$key}</a>"; $content .= "<br>" . 'You can also copy the link and open it in the Address Field' . "<br><br><br>"; $mail = Yii::$app->mailer->compose()->setTo($this->email)->setSubject($title)->setHtmlBody($content)->send(); if ($mail) { $transaction->commit(); return true; } } catch (Exception $e) { $transaction->rollBack(); $this->addError('user', 'fail to create account'); } return false; }
/** * Lists all Opduser models. * @return mixed */ public function actionAdduser() { //$request = Yii::$app->request; //if ($request->isAjax) { /* ตรวจสอบว่าเป็น ajax */ } //if ($request->isGet) { echo "Is Get"; } //if ($request->isPost) { echo "Is Post"; } //if ($request->isPut) { /* ตรวจสอบว่าเป็น PUT */ } $username = Yii::$app->request->get('username'); $email = Yii::$app->request->get('email'); $password = Yii::$app->request->get('passweb'); //return $username; if (!User::findByUsername($username)) { $user = new User(); $user->username = $username; $user->email = $email; $user->setPassword($password); $user->generateAuthKey(); $user->status = User::STATUS_ACTIVE; if ($user->save()) { Yii::$app->session->setFlash('success', 'Successes'); $this->redirect(\Yii::$app->urlManager->createUrl("opduser/index")); //return 'successes'; } else { Yii::$app->session->setFlash('error', 'failed'); $this->redirect(\Yii::$app->urlManager->createUrl("opduser/index")); //return 'failed'; } } return 'aleadyexists'; }
public function signup() { if ($this->validate()) { $user = new User(); $user->phone = $this->phone; $user->setPassword($this->password); if (empty($this->username)) { $user->username = $this->phone; } else { $user->username = $this->username; } if (!empty($this->email)) { $user->email = $this->email; } #$user->generateAuthKey(); $ret = $user->save(); if (!$ret) { Yii::$app->getSession()->setFlash('error', '系统错误,注册失败。'); return false; } return $user; } $error = array_pop($this->getErrors()); Yii::$app->getSession()->setFlash('error', $error[0]); return false; }
/** * 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->email; $user->email = $this->email; $user->status = User::STATUS_AWAITING_REQUEST; if ($user->save(false)) { $customer = new Customer(); $customer->name = $this->company_name; $customer->location = $this->location; $customer->address = $this->address; $customer->zip_code = $this->zip_code; $customer->phone_number = $this->phone_number; $customer->website = $this->website; $customer->kvk = $this->kvk; $customer->btw = $this->btw; $customer->email_address = $this->email; $customer->description = $this->description; $customer->contact_type = $this->contact_type; $customer->contact = $this->contact; $customer->user_id = $user->id; if ($customer->save(false)) { return $user; } else { $user->delete(); } } } 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->nombre = $this->nombre; $user->apellido = $this->apellido; $user->username = $this->username; $user->email = $this->email; $user->cedula = $this->cedula; $user->supervisor = $this->supervisor; $user->id_division = $this->id_division; $user->id_organizacion = $this->id_organizacion; $user->id_empresa = $this->id_empresa; $user->departamento = $this->departamento; $user->id_aplicacion = $this->id_aplicacion; $user->id_distrito = $this->id_distrito; $user->telefono = $this->telefono; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { return $user; } } return null; }
public function generateToken() { $mobile = $this->_session['passwordResetMobile']; $this->_user = User::findByMobile($mobile); if (!User::isPasswordResetTokenValid($this->_user->password_reset_token)) { $this->_user->generatePasswordResetToken(); } return $this->_user->save(false); }
/** * @param User $model * @return User */ public function setModel($model) { $this->username = $model->username; $this->email = $model->email; $this->status = $model->status; $this->model = $model; $this->roles = ArrayHelper::getColumn(\Yii::$app->authManager->getRolesByUser($model->getId()), 'name'); return $this->model; }
public function actionSignup() { $user = new User(); $user->username = '******'; $user->email = 'admin'; $user->setPassword('admin'); $user->generateAuthKey(); $user->save(); }
public function resetPassword() { $this->_user = User::findIdentity(Yii::$app->user->id); if (!Yii::$app->getSecurity()->validatePassword($this->password, $this->_user->password_hash)) { throw new InvalidParamException(Yii::t('User', 'source_password_error')); } $this->_user->setPassword($this->new_password); return $this->_user->save(false); }
public function actionIndex() { $model = new User(); $dataProvider = new ActiveDataProvider(['query' => $model->find(), 'pagination' => ['pageSize' => 3]]); echo \Yii::$app->request->userIP . "<br>"; //echo \Yii::$app->request->userHost."<br>"; //echo \Yii::$app->request->userAgent."<br>"; return $this->render('index', ['dataProvider' => $dataProvider, 'model' => $model]); }