change register function
This commit is contained in:
parent
68f53c9d9a
commit
fbe7ef3bfe
|
@ -62,24 +62,15 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa
|
|||
return $rs->fetch();
|
||||
}
|
||||
|
||||
//注册
|
||||
/**
|
||||
* 用户注册
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function register($data)
|
||||
{
|
||||
$params = compact('data');
|
||||
$results = $this->getEventManager()->trigger('register.checkParam', $this, $params);
|
||||
$cache_data = $results->last();
|
||||
|
||||
if($cache_data !== true)
|
||||
{
|
||||
if(!is_array($cache_data))
|
||||
{
|
||||
return array('error'=>$cache_data);
|
||||
}else{
|
||||
return $cache_data;
|
||||
}
|
||||
}
|
||||
|
||||
$results = $this->getEventManager()->trigger('register.checkUser', $this, $params);
|
||||
$results = $this->getEventManager()->trigger('register.pre', $this, $params);
|
||||
$cache_data = $results->last();
|
||||
|
||||
if($cache_data !== true)
|
||||
|
@ -92,29 +83,48 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数据分为两组,一组用于做注册成功后的登陆,一组用于写入数据库
|
||||
* 写入数据库的数据需要完全重建一个新的,防止因为前端传入时有人恶意增加字段造成破坏
|
||||
*/
|
||||
$loginData = array(
|
||||
'username'=>$data['username'],
|
||||
'password'=>$data['password']
|
||||
);
|
||||
|
||||
$data['password'] = md5($data['password']);
|
||||
$data['usertype'] = "guest";
|
||||
unset($data['confirm_password']);
|
||||
$registerData = [
|
||||
'username' => $data['username'],
|
||||
'password' => md5($data['password']),
|
||||
'usertype' => 'guest',
|
||||
'email' => $data['email'],
|
||||
'realname' => $data['realname'],
|
||||
'unit' => $data['unit'],
|
||||
'address' => $data['address'],
|
||||
'project' => $data['project'],
|
||||
'phone' => $data['phone'],
|
||||
'project_id' => $data['project_id'],
|
||||
'project_type' => $data['project_type'],
|
||||
'project_title' => $data['project_title'],
|
||||
'project_leader' => $data['project_leader'],
|
||||
];
|
||||
|
||||
$dbh = new dbh();
|
||||
|
||||
$id = $dbh->insert($this->memberTable,$data,true);
|
||||
$id = $dbh->insert($this->memberTable,$registerData,true);
|
||||
|
||||
if(!empty($id) && is_numeric($id))
|
||||
{
|
||||
$this->storeLogin($loginData);
|
||||
|
||||
if(isset($state['success']))
|
||||
{
|
||||
//$mb = new Member();
|
||||
//$mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]);
|
||||
}
|
||||
|
||||
$data = $registerData;
|
||||
$params = compact('data','id');
|
||||
$results = $this->getEventManager()->trigger('register.success', $this, $params);
|
||||
$this->getEventManager()->trigger('register.success', $this, $params);
|
||||
return array("success" => 1);
|
||||
}else{
|
||||
if($id === false)
|
||||
|
@ -127,7 +137,11 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa
|
|||
|
||||
}//register
|
||||
|
||||
//登陆
|
||||
/**
|
||||
* 用户登陆
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function login($data)
|
||||
{
|
||||
$results = $this->getEventManager()->trigger('login.pre', $this, compact('data'));
|
||||
|
@ -147,6 +161,9 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa
|
|||
|
||||
if(isset($state['success']))
|
||||
{
|
||||
//$mb = new Member();
|
||||
//$mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]);
|
||||
|
||||
$user = (array)$state['user'];
|
||||
$this->getEventManager()->trigger('login.success', $this, compact('user'));
|
||||
}else{
|
||||
|
@ -156,7 +173,13 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa
|
|||
return $state;
|
||||
}//login
|
||||
|
||||
//storeLogin
|
||||
/**
|
||||
* 存储用户登陆信息
|
||||
* 为了防止login中的用户信息检查不规范,再加入一层内置的数据库权限检查,以防通过漏洞登入系统
|
||||
* @param $data
|
||||
* @param bool $md5 是否对密码进行md5加密再校验
|
||||
* @return array
|
||||
*/
|
||||
private function storeLogin($data,$md5 = true)
|
||||
{
|
||||
$auth = new AuthenticationService();
|
||||
|
@ -197,7 +220,7 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa
|
|||
'success'=>1,
|
||||
'user' => $user
|
||||
);
|
||||
}
|
||||
}//storeLogin
|
||||
|
||||
public function cookieLogin($data)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue