generateAuthKey() публичный Метод

Generates "remember me" authentication key
public generateAuthKey ( )
Пример #1
0
 public function reg()
 {
     $user = new User();
     $user->phone = $this->phone;
     $user->email = $this->email;
     $user->status = $this->status;
     $user->setPassword($this->password);
     $user->generateAuthKey();
     if ($this->scenario === 'emailActivation') {
         $user->generateSecretKey();
     }
     $transaction = Yii::$app->db->beginTransaction();
     try {
         if ($user->save()) {
             $modelProfile = new Profile();
             $modelProfile->user_id = $user->id;
             if ($modelProfile->save()) {
                 $transaction->commit();
                 return RbacHelper::assignRole($user->getId()) ? $user : null;
             }
         } else {
             return false;
         }
     } catch (Exception $e) {
         $transaction->rollBack();
     }
 }
 /**
  * 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;
 }
Пример #3
0
 public function actionAddData()
 {
     $model = new UserBackend();
     $auth = new AuthAssignment();
     if ($model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         $user = new User();
         $user->username = $_POST['UserBackend']['username'];
         $user->email = $_POST['UserBackend']['email'];
         $user->setPassword('123456');
         $user->generateAuthKey();
         $user->status = 10;
         if ($user) {
             $auth = new AuthAssignment();
             $auth->item_name = $_POST['AuthAssignment']['item_name'];
             $auth->user_id = 17;
             $auth->created_at = 1428931496;
             if ($auth->save()) {
                 $res = array('message' => 'Data Berhasil Di Simpan.', 'alert' => 'success', 'proses' => 'save', 'success' => true);
             } else {
                 $res = array('message' => 'Data Gagal Di Simpan.', 'alert' => 'error', 'proses' => 'save', 'success' => false);
             }
         } else {
             $res = array('message' => 'Data Gagal Di Simpan.', 'alert' => 'error', 'proses' => 'save', 'success' => false);
         }
         return $res;
         \Yii::$app->end();
     } else {
         return $this->renderAjax('create', ['model' => $model, 'auth' => $auth]);
     }
 }
Пример #4
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;
 }
Пример #5
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;
 }
Пример #6
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->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;
 }
 /**
  * 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());
     }
 }
Пример #8
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;
 }
Пример #9
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;
 }
Пример #10
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();
         $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;
 }
Пример #11
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();
         $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;
 }
Пример #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();
         //            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;
 }
Пример #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();
         $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;
 }
 /**
  * Регистрация нового пользователя
  *
  * @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;
 }
Пример #15
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->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;
 }
Пример #16
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;
 }
Пример #17
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]);
 }
Пример #18
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;
 }
Пример #19
0
 /**
  * @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;
 }
Пример #20
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;
 }
Пример #21
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;
     }
 }
Пример #22
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';
 }
 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]);
     }
 }
 /**
  * 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;
     }
 }
 /**
  * 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;
 }
Пример #26
0
 public function actionSignup()
 {
     $user = new User();
     $user->username = '******';
     $user->email = 'admin';
     $user->setPassword('admin');
     $user->generateAuthKey();
     $user->save();
 }
 public function up()
 {
     $user = new User();
     $user->username = '******';
     $user->email = Yii::$app->params['adminEmail'];
     $user->setPassword('admin');
     $user->generateAuthKey();
     $user->save();
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     $this->createTable('categories', ['id' => $this->primaryKey(), 'name' => $this->string(255), 'comment' => $this->string(255), 'seq' => $this->integer(), 'visible' => $this->boolean()], $tableOptions);
     $this->insert('categories', ['name' => 'main', 'comment' => 'Main menu', 'seq' => 1, 'visible' => 1]);
     $this->createTable('layouts', ['id' => $this->primaryKey(), 'name' => $this->string(255)->unique(), 'comment' => $this->string(255)->unique(), 'seq' => $this->integer()], $tableOptions);
     $this->insert('layouts', ['name' => 'main', 'comment' => 'Main layouts', 'seq' => 1]);
     $this->createTable('views', ['id' => $this->primaryKey(), 'name' => $this->string(255)->unique(), 'comment' => $this->string(255), 'seq' => $this->integer()], $tableOptions);
     $this->insert('views', ['name' => '/site/index', 'comment' => 'Main site view', 'seq' => 1]);
     $this->createTable('sessions', ['id' => $this->primaryKey(), 'name' => $this->string(255)], $tableOptions);
     $this->createTable('links', ['id' => $this->primaryKey(), 'categories_id' => $this->integer()->defaultValue(1), 'layouts_id' => $this->integer()->defaultValue(1), 'views_id' => $this->integer()->defaultValue(1), 'parent' => $this->integer(), 'url' => $this->string(255)->unique(), 'name' => $this->string(255), 'anchor' => $this->string(255), 'child_exist' => $this->boolean(), 'level' => $this->integer(), 'seq' => $this->integer(), 'title' => $this->string(1024), 'keywords' => $this->string(1024), 'description' => $this->string(1024), 'start' => $this->boolean()->defaultValue(0), 'priority' => $this->decimal(2, 1)->defaultValue(0.5), 'created_at' => $this->integer(), 'updated_at' => $this->integer(), 'state' => $this->boolean(), 'content_nums' => $this->integer()->defaultValue(1), 'css_class' => $this->string(255), 'icon' => $this->string(255)], $tableOptions);
     $this->addForeignKey('fk-links-categories_id', 'links', 'categories_id', 'categories', 'id', 'CASCADE', 'CASCADE');
     $this->addForeignKey('fk-links-layouts_id', 'links', 'layouts_id', 'layouts', 'id', 'CASCADE', 'CASCADE');
     $this->addForeignKey('fk-links-views_id', 'links', 'views_id', 'views', 'id', 'CASCADE', 'CASCADE');
     $this->addForeignKey('fk-links-parent', 'links', 'parent', 'links', 'id', 'CASCADE', 'CASCADE');
     $this->createTable('contents', ['id' => $this->primaryKey(), 'links_id' => $this->integer(), 'parent' => $this->integer(), 'css_class' => $this->string(255), 'text' => $this->text(), 'seq' => $this->integer()], $tableOptions);
     $this->addForeignKey('fk-contents-links_id', 'contents', 'links_id', 'links', 'id', 'CASCADE', 'CASCADE');
     $this->addForeignKey('fk-contents-parent', 'contents', 'parent', 'contents', 'id', 'CASCADE', 'CASCADE');
     $this->createTable('redirects', ['id' => $this->primaryKey(), 'links_id' => $this->integer(), 'url' => $this->integer(), 'code' => $this->integer()], $tableOptions);
     $this->addForeignKey('fk-redirects-links_id', 'redirects', 'links_id', 'links', 'id', 'CASCADE', 'CASCADE');
     $this->createTable('search', ['id' => $this->primaryKey(), 'name' => $this->string(255)], $tableOptions);
     $this->createTable('gallery_types', ['id' => $this->primaryKey(), 'name' => $this->string(255)->unique(), 'comment' => $this->string(255), 'destination' => $this->string(255), 'small_width' => $this->integer()->defaultValue(0), 'small_height' => $this->integer()->defaultValue(0), 'large_width' => $this->integer()->defaultValue(0), 'large_height' => $this->integer()->defaultValue(0), 'quality' => $this->integer()->defaultValue(80), 'visible' => $this->boolean()->defaultValue(1)], $tableOptions);
     $this->createTable('gallery_groups', ['id' => $this->primaryKey(), 'gallery_types_id' => $this->integer(), 'gallery_images_id' => $this->integer(), 'name' => $this->string(255)], $tableOptions);
     $this->createTable('gallery_images', ['id' => $this->primaryKey(), 'gallery_groups_id' => $this->integer(), 'small' => $this->string(255), 'large' => $this->string(255), 'name' => $this->string(255), 'alt' => $this->string(255), 'url' => $this->string(255), 'seq' => $this->integer()], $tableOptions);
     $this->addForeignKey('fk-gallery_images-gallery_groups_id', 'gallery_images', 'gallery_groups_id', 'gallery_groups', 'id', 'CASCADE', 'CASCADE');
     $this->addForeignKey('fk-gallery_groups-gallery_types_id', 'gallery_groups', 'gallery_types_id', 'gallery_types', 'id', 'CASCADE', 'CASCADE');
     $this->addForeignKey('fk-gallery_groups-gallery_images_id', 'gallery_groups', 'gallery_images_id', 'gallery_images', 'id', 'CASCADE', 'CASCADE');
     $this->insert('gallery_types', ['name' => 'links', 'comment' => 'Link images', 'destination' => '/img/links', 'visible' => 0]);
     $this->insert('gallery_types', ['name' => 'news', 'comment' => 'News', 'destination' => '/img/news', 'small_width' => 350, 'small_height' => 300, 'visible' => 0]);
     $this->insert('gallery_types', ['name' => 'gallery', 'comment' => 'Photo gallery', 'destination' => '/img/gallery', 'small_width' => 280, 'small_height' => 280, 'large_width' => 800]);
     $this->addColumn('links', 'gallery_images_id', $this->integer());
     $this->addForeignKey('fk-links-gallery_images_id', 'links', 'gallery_images_id', 'gallery_images', 'id', 'SET NULL', 'CASCADE');
     $this->createTable('news_types', ['id' => $this->primaryKey(), 'categories_id' => $this->integer(), 'links_id' => $this->integer(), 'name' => $this->string(255), 'gallery_types_id' => $this->integer(), 'gallery_groups_id' => $this->integer()], $tableOptions);
     $this->createTable('news', ['id' => $this->primaryKey(), 'news_types_id' => $this->integer(), 'links_id' => $this->integer(), 'url' => $this->string(255), 'date' => $this->date(), 'date_from' => $this->date(), 'date_to' => $this->date()], $tableOptions);
     $this->addForeignKey('fk-news_types-categories_id', 'news_types', 'categories_id', 'categories', 'id', 'CASCADE', 'CASCADE');
     $this->addForeignKey('fk-news_types-links_id', 'news_types', 'links_id', 'links', 'id', 'CASCADE', 'CASCADE');
     $this->addForeignKey('fk-news-news_types_id', 'news', 'news_types_id', 'news_types', 'id', 'CASCADE', 'CASCADE');
     $this->addForeignKey('fk-news-links_id', 'news', 'links_id', 'links', 'id', 'CASCADE', 'CASCADE');
     $this->createTable('modules', ['id' => $this->primaryKey(), 'name' => $this->string(255), 'url' => $this->string(255), 'visible' => $this->boolean()->defaultValue(1), 'icon' => $this->string(255), 'seq' => $this->integer()]);
     $this->insert('modules', ['name' => 'Новости', 'url' => '/news/index', 'visible' => 1, 'icon' => 'fa fa-newspaper-o', 'seq' => 1]);
     $this->insert('modules', ['name' => 'Фотогалерея', 'url' => '/gallery/index', 'visible' => 1, 'icon' => 'fa fa-file-image-o', 'seq' => 2]);
     $this->insert('modules', ['name' => 'Интернет-магазин', 'url' => '/shop/index', 'visible' => 1, 'icon' => 'fa fa-shopping-cart', 'seq' => 3]);
     $this->insert('modules', ['name' => 'Недвижимость', 'url' => '/realty/index', 'visible' => 0, 'icon' => 'fa fa-home', 'seq' => 4]);
     $this->insert('modules', ['name' => 'Email-рассылка', 'url' => '/broadcast/index', 'visible' => 1, 'icon' => 'fa fa-envelope-o', 'seq' => 5]);
     $this->insert('modules', ['name' => 'Обмен справками РЖД', 'url' => '/certificates/index', 'visible' => 0, 'icon' => 'fa fa-archive', 'seq' => 6]);
 }
Пример #28
0
 public function actionInit()
 {
     //$auth = Yii::$app->authManager;
     $user = new User();
     $user->username = "******";
     $user->email = "*****@*****.**";
     $user->status = 10;
     $user->setPassword("abc@1234");
     $user->generatePasswordResetToken();
     $user->generateAuthKey();
     $user->save();
 }
Пример #29
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if (!$this->validate()) {
         return null;
     }
     $user = new User();
     $user->username = $this->username;
     $user->email = $this->email;
     $user->setPassword($this->password);
     $user->generateAuthKey();
     return $user->save() ? $user : null;
 }
Пример #30
0
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         $model->setPassword(Yii::$app->request->post()['User']['_password']);
         $model->generateAuthKey();
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }