Exemplo n.º 1
0
 public function register()
 {
     if (!$this->validate()) {
     }
     $users = new Users();
     $users->username = $this->username;
     $users->email = $this->email;
     $users->pass = $users->getPasswordHash($this->pass);
     $users->first_name = $this->first_name;
     $users->last_name = $this->last_name;
     $users->date_expires = time() - 60 * 60 * 24;
     $users->auth_key = Yii::$app->security->generateRandomString();
     if (!$users->save()) {
         return false;
     }
     $auth = Yii::$app->authManager;
     $authorRole = $auth->getRole('member');
     $auth->assign($authorRole, $users->getId());
     return true;
 }
Exemplo n.º 2
0
 public function actionRegister()
 {
     $users = new RegisterForm();
     if (Yii::$app->request->isAjax && Yii::$app->request->isPost) {
         if ($users->load(\Yii::$app->request->post())) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($users);
         }
     }
     if ($users->load(Yii::$app->request->post()) && $users->register()) {
         Yii::$app->email->sendMail('Registration Confirmation', "Thank you for registering at <whatever site>. Blah. Blah. Blah.\n\n", $users->email);
         Yii::$app->user->login(Users::findEmailIdentity($users->email));
         return $this->render('register-successfully', ['e' => $users->email]);
     }
     return $this->render('register', compact('users'));
 }
Exemplo n.º 3
0
 public function changePassword()
 {
     if (!$this->validate()) {
         return false;
     }
     $user = Users::findEmailIdentity($this->email);
     if (is_null($user)) {
         $this->addError('email', 'The submitted email address does not match those on file!');
         return false;
     }
     $password = substr(md5(uniqid(rand(), true)), 10, 15);
     $user->pass = $user->getPasswordHash($password);
     $user->save();
     $body = "Your password to log into <whatever site> has been temporarily changed to '{$password}'. Please log in using that password and this email address. Then you may change your password to something more familiar.";
     Yii::$app->email->sendMail('Your temporary password.', $body, $user->email);
     return true;
 }
Exemplo n.º 4
0
 public function login()
 {
     if (!$this->validate()) {
         return false;
     }
     $users = Users::findEmailIdentity($this->email);
     if (!$users) {
         $this->addError('email');
         $this->addError('password');
         return false;
     }
     if (!$users->validatePasswordHash($this->password)) {
         $this->addError('email');
         $this->addError('password');
         return false;
     }
     return Yii::$app->user->login($users, $this->rememberMe ? 3600 * 24 * 30 : 0);
 }