119 lines
3.0 KiB
PHP
119 lines
3.0 KiB
PHP
<?php
|
||
namespace Users\Operation;
|
||
|
||
use \Helpers\dbh as dbh;
|
||
use \Users\Gravatar;
|
||
|
||
class LoginOperate implements \Users\Event\LoginEvent
|
||
{
|
||
private $db; //传入PDO对象
|
||
public $tbl_member = "users";
|
||
public $FieldUsername = "username";
|
||
public $FieldPasword = "password";
|
||
public $FieldLastlogin = "ts_last_login";
|
||
public $FieldEmail = "email";
|
||
public $FieldLastloginIp = "last_login_ip";
|
||
public $FieldGravatarEmail = "gravatar_email";
|
||
private $DefaultFetchMode = \PDO::FETCH_BOTH; //默认检索模式,防止出现sdtClass错误
|
||
private $config; //全局配置
|
||
|
||
function __construct($db = NULL)
|
||
{
|
||
if(empty($db))
|
||
{
|
||
$this->db = \Zend_Registry::get('db');
|
||
}else{
|
||
$this->db = $db;
|
||
}
|
||
|
||
$this->config = \Zend_Registry::get('config');
|
||
}
|
||
|
||
public function checkParam(\Zend_EventManager_Event $e){
|
||
|
||
$data = $e->getParam('data');
|
||
|
||
if(!is_array($data))
|
||
{
|
||
return "参数错误";
|
||
}
|
||
|
||
if(empty($data['username']))
|
||
{
|
||
return array('error'=>"请输入用户名",'place'=>'username');
|
||
}
|
||
|
||
if(!empty($data['username']))
|
||
{
|
||
if(mb_strlen($data['username'])<2)
|
||
{
|
||
return array('error'=>"用户名长度应该大于两个字符",'place'=>'username');
|
||
}
|
||
}
|
||
|
||
if(empty($data['password']))
|
||
{
|
||
return array('error'=>"请输入密码",'place'=>'password');
|
||
}
|
||
|
||
$sql = "SELECT id,{$this->FieldPasword},status FROM {$this->tbl_member} WHERE {$this->FieldUsername}=?";
|
||
$sth = $this->db->prepare($sql);
|
||
$rs = $sth->execute(array($data[$this->FieldUsername]));
|
||
$row = $sth->fetch();
|
||
|
||
if(isset($row['id']) && !empty($row['id']))
|
||
{
|
||
if(strlen($row[$this->FieldPasword]) !== 32)
|
||
{
|
||
return array('error'=>"您的密码或因安全原因或其他问题已经被重置,请先<a href='/account/forgotpassword'>重置密码</a>再登陆",'place'=>'password');
|
||
}
|
||
if($row[$this->FieldPasword] !== md5($data['password']))
|
||
{
|
||
return array('error'=>"密码错误",'place'=>'password');
|
||
}
|
||
if($row['status'] == -1)
|
||
{
|
||
return array('error'=>'您的帐号已被禁止登录','place'=>'password');
|
||
}
|
||
return true;
|
||
}else{
|
||
return array('error'=>"用户不存在",'place'=>'username');
|
||
}
|
||
|
||
}//checkParam
|
||
|
||
public function updateStatus(\Zend_EventManager_Event $e){
|
||
|
||
$id = (int)$e->getParam('id');
|
||
|
||
if(!is_numeric($id))
|
||
{
|
||
return false;
|
||
}
|
||
|
||
$update = array(
|
||
$this->FieldLastlogin => date("Y-m-d H:i:s"),
|
||
//$this->FieldLastloginIp => $_SERVER["REMOTE_ADDR"]
|
||
);
|
||
|
||
$dbh = new dbh();
|
||
@$statusUpdate = $dbh->update($this->tbl_member,$update," id=$id ");
|
||
|
||
return true;
|
||
}//loginSuccess
|
||
|
||
public function createAvatar(\Zend_EventManager_Event $e){
|
||
|
||
$email = $e->getParam('email');
|
||
$avatar = new Gravatar();
|
||
return $avatar->Get($email);
|
||
|
||
}//loginSuccess
|
||
|
||
//检查token表记录
|
||
public function checkOAuthToken()
|
||
{
|
||
|
||
}
|
||
|
||
} |