Exemplo n.º 1
0
 /**
  * Logs in the user using the given username and password in the model.
  * @return boolean whether login is successful
  */
 public function save()
 {
     $user = new Users();
     $user->setAttributes($this->attributes);
     $user->setAttribute("password", BaseTool::ENPWD($this->password));
     if ($user->validate() && $user->save()) {
         $accountarray = array('user_id' => Yii::app()->db->getLastInsertID(), 'total' => 0, 'use_money' => 0, 'no_use_money' => 0, 'newworth' => 0);
         $newAccount = new Account();
         $newAccount->setAttributes($accountarray);
         $newAccount->save();
         //发送邮件
         $activecode = BaseTool::getActiveMailCode($this->username);
         $message = MailTemplet::getActiveEmail($this->username, $activecode);
         $mail = Yii::app()->Smtpmail;
         $mail->SetFrom(Yii::app()->params['adminEmail']);
         $mail->Subject = "好帮贷测试邮件";
         $mail->MsgHTML($message);
         $mail->AddAddress($this->email);
         if ($mail->Send()) {
             $user->updateAll(array("regtaken" => $activecode, "regativetime" => time() + 60 * 60), "username=:username", array(":username" => $this->username));
         }
         Yii::import("application.models.form.LoginForm", true);
         $loginform = new LoginForm();
         $loginarray = array('rememberMe' => false, 'username' => $this->username, 'password' => $this->password);
         $loginform->setAttributes($loginarray);
         if ($loginform->validate() && $loginform->login()) {
         }
         return true;
     } else {
         $usererror = $user->errors;
         $this->addError("username", current(current($usererror)));
         return false;
     }
 }
Exemplo n.º 2
0
 /**
  * 
  * @param type $string
  * @param type $string1
  * @return boolean
  * 验证密码是否正确
  */
 public function validatePassword($string = '', $string1 = "")
 {
     if (BaseTool::ENPWD($string) === $string1) {
         return true;
     } else {
         return false;
     }
 }