/**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $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();
         $user->save();
         //添加权限
         $permissionList = $_POST['SignupForm']['permissions'];
         foreach ($permissionList as $value) {
             $newPermission = new AuthAssignment();
             $newPermission->user_id = $user->id;
             $newPermission->item_name = $value;
             $newPermission->save();
             print_r($newPermission->getErrors());
         }
         //die;
         if ($user->save()) {
             return $user;
         }
     }
     return null;
 }
Пример #2
0
 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();
 }
Пример #3
0
 /**
  * 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();
 }
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             $str = 'abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' . date('yyydmmdhis');
             $potong = str_shuffle($str);
             $random = substr($potong, 3, 12);
             $model->setPassword($random);
             $model->username = $_POST['User']['username'];
             $model->role = $_POST['User']['role'];
             $model->generateAuthKey();
             $content = '
                 <center><img src="http://i.imgur.com/p5lHZXS.png"/></center><br/>
                 <h4 align="center">Badan Pengawas Tenaga Nuklir  ' . date('Y') . '</h4>
                 <hr/>
                 <p>Yth ' . $model->username . ',<br/>  
                 Dengan ini kami sampaikan akun telah terdaftar untuk masuk ke Sistem Aplikasi Perjalanan Dinas – BAPETEN, sebagai berikut:<br/> 
                 Username : '******' <br/>
                 Password :<b>' . $random . '</b><br/>
                 Mohon lakukan penggantian password Anda setelah melakukan login.\\n
                 Terima Kasih. <hr/>
                 <h5 align="center">Subbag Perjalanan Dinas Biro Umum BAPETEN  ' . date('Y') . '</h5><br/>';
             Yii::$app->mailer->compose("@common/mail/layouts/html", ["content" => $content])->setTo($_POST['User']['email'])->setFrom([$_POST['User']['email'] => $model->username])->setSubject('Ubah Kata Sandi')->setTextBody($random)->send();
             $model->save();
             return $this->redirect(['index']);
         } else {
             var_dump($model->errors);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #5
0
 /**
  * Creates a new User model.
  * For ajax request will return json object
  * and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $request = Yii::$app->request;
     $model = new User();
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($request->isGet) {
             return ['code' => '200', 'message' => 'OK', 'data' => $this->renderPartial('create', ['model' => $model])];
         } else {
             if ($model->load($request->post()) && $model->save()) {
                 return ['code' => '200', 'message' => 'Create User success'];
             } else {
                 return ['code' => '400', 'message' => 'Validate error', 'data' => $this->renderPartial('create', ['model' => $model])];
             }
         }
     } else {
         /*
          *   Process for non-ajax request
          */
         if ($model->load($request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }
 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);
 }
Пример #7
0
 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);
 }
Пример #8
0
 /**
  * Resets password.
  *
  * @return boolean if password was reset.
  */
 public function resetPassword()
 {
     $this->_user->setPassword($this->password);
     $this->_user->removePasswordResetToken();
     if ($this->_user->save()) {
         $this->_user->sendPasswordChangedEmail();
         return true;
     }
     return false;
 }
Пример #9
0
 /**
  * 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->setScenario('create_user');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $model->generatePasswordResetToken();
         $model->save(false);
         return $this->redirect(['view', 'id' => $model->id]);
     }
     $model->status = User::STATUS_ACTIVE;
     $model->group = User::GROUP_READER;
     return $this->render('create', ['model' => $model]);
 }
Пример #10
0
 /**
  * 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
 }
Пример #11
0
 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;
 }
Пример #12
0
 /**
  * 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();
         if ($user->validate()) {
             $broker = new Broker();
             $broker->user_id = 1;
             $broker->type_id = $this->type_id;
             $broker->name = $this->name;
             $broker->company = $this->company;
             $broker->phone = $this->phone;
             $broker->email = $this->email;
             $broker->address = $this->address;
             $broker->contact = $this->contact;
             $broker->recommend = $this->recommend;
             $broker->note_user = $this->note_user;
             $broker->sale_add = $this->sale_add;
             if ($broker->validate()) {
                 $user->save();
                 $broker->user_id = $user->id;
                 $broker->save();
                 return $user;
             }
         }
     }
     return null;
 }
Пример #13
0
 /**
  * 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;
 }
Пример #14
0
 /**
  * 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;
 }
Пример #15
0
 /**
  * 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->username = $_POST['User']['username'];
         $model->email = $_POST['User']['email'];
         $model->password = $_POST['User']['password'];
         $model->setPassword($_POST['User']['password']);
         $model->generateAuthKey();
         $model->fname = $_POST['User']['fname'];
         $model->lname = $_POST['User']['lname'];
         $model->groupid = $_POST['User']['groupid'];
         $model->departmentid = $_POST['User']['departmentid'];
         //  $model->roleid = $_POST['User']['roleid'];
         $model->roleid = 2;
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             print_r($model->getErrors());
         }
         //            if ($id = $model->signup() ) {
         //                return $this->redirect(['view', 'id' => $id->id]);
         //            }
         //            if(is_null($model->signup())){
         //              //  echo "Value is null";
         //                print_r($model->getErrors());
         //            }
     }
     return $this->render('create', ['model' => $model]);
 }
Пример #16
0
 public function actionCreate()
 {
     $model = new User();
     $model->scenario = 'create';
     $users['User'] = Yii::$app->request->post();
     if (Yii::$app->request->isPost && $model->load($users)) {
         $model->password_hash = Yii::$app->request->post('password');
         if (!empty($_FILES)) {
             $upload = new UploadedFile();
             $upload->name = $_FILES['image']['name'];
             $upload->type = $_FILES['image']['type'];
             $upload->tempName = $_FILES['image']['tmp_name'];
             $upload->error = $_FILES['image']['error'];
             $upload->size = $_FILES['image']['size'];
             $model->image = $upload;
             $filepath = Yii::getAlias('@uploadpath');
             $model->image->saveAs($filepath . '/' . $model->image->baseName . '.' . $model->image->extension);
             $model->setImage($model->image->name, FALSE);
         }
         if ($model->save()) {
             return $model;
         } else {
             return $model->getErrors();
         }
     } else {
         throw new ForbiddenHttpException('User is not saved successfully. Please try again with proper details.');
     }
 }
Пример #17
0
 /**
  * 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 user up.
  *
  * @return User|false the saved model or false if saving fails
  */
 public function signup($runValidation = true)
 {
     if ($runValidation && !$this->validate()) {
         return false;
     }
     $user = new User();
     $user->mobile = $this->_session['mobileSignup'];
     $user->setPassword($this->_session['mobileSignupPassword']);
     $user->generateAuthKey();
     $user->generateAccessToken();
     $transaction = Yii::$app->db->beginTransaction();
     try {
         if (!$user->save(false)) {
             throw new \Exception();
         }
         $userAccount = new UserAccount();
         $userAccount->id = $user->id;
         $userAccount->password_hash = null;
         if (!$userAccount->save(false)) {
             throw new \Exception();
         }
         $transaction->commit();
         return $user;
     } catch (\Exception $e) {
         $transaction->rollBack();
         return false;
     }
 }
 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;
 }
 /**
  * Регистрация нового пользователя
  *
  * @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;
 }
Пример #21
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $model = new SignupForm();
         $user->firstname = $this->firstname;
         $user->lastname = $this->lastname;
         $user->clubname = $this->clubname;
         $user->phonenumber = $this->phonenumber;
         $user->mobilenumber = $this->mobilenumber;
         $user->dateofbirth = $this->dateofbirth;
         $user->address = $this->address;
         $user->description = $this->description;
         $model->file = UploadedFile::getInstance($model, 'file');
         if ($model->file) {
             $model->file->saveAs('uploads/' . $model->file->name);
             $user->image = $model->file->name;
         }
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             return $user;
         }
     }
     return null;
 }
Пример #22
0
 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;
 }
Пример #23
0
 /**
  * @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);
 }
Пример #24
0
 /**
  * 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;
 }
Пример #25
0
 /**
  * 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 = User::SCENARIO_CREATE;
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if (!($role = User::getAuthItem($model->role))) {
             $model->addError('role', 'Role does not exist');
         } else {
             $transaction = $model->getDb()->beginTransaction();
             try {
                 if ($model->save(false)) {
                     if (!$model->assignRole()) {
                         throw new Exception();
                     }
                     if (!Yii::$app->user->can(User::PERMISSION_CAN_CUD, $model)) {
                         throw new Exception();
                     }
                     $transaction->commit();
                     return $this->redirect('index');
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Пример #26
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  * @param $isAdmin true|false
  * can create Simple Manager or Admin
  */
 public function signup($isAdmin = false)
 {
     if ($this->validate()) {
         $user = new User();
         $user->firmname = $this->firmname;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             if ($isAdmin) {
                 $ssid = $user->id;
                 $user->ssid = $ssid;
                 $user->update();
                 // set's up Defaults for Admin
                 NewUserSetup::AdminSetUp($ssid);
             } else {
                 $user->ssid = helper::getSsid();
                 $user->update();
             }
             return $user;
         }
     } else {
         return null;
     }
 }
Пример #27
0
 /**
  * Signs user up.
  * @return User|null the saved model or null if saving fails
  * @internal param string $avatar
  */
 public function register()
 {
     if ($this->validate()) {
         $user = new User(['scenario' => 'register']);
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setHashPassword($this->password);
         $user->generateAuthKey();
         $user->generateAccessToken();
         $user->password = md5($this->password);
         if ($this->saveAvatar(UploadedFile::getInstance($this, 'avatar'))) {
             $user->avatar = $this->avatar;
         } else {
             Yii::$app->session->setFlash('alert', '注册失败');
             Yii::$app->session->setFlash('alert-type', 'alert-danger');
             return false;
         }
         if ($user->save()) {
             return $user;
         } else {
             Yii::$app->session->setFlash('alert', '注册失败');
             Yii::$app->session->setFlash('alert-type', 'alert-danger');
             return false;
         }
     }
     return null;
 }
Пример #28
0
 /**
  * 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';
 }
Пример #29
0
 /**
  * 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;
 }
Пример #30
0
 /**
  * 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());
     }
 }