2013-11-22 04:20:00 +00:00
|
|
|
|
<?php
|
|
|
|
|
namespace Users;
|
|
|
|
|
|
|
|
|
|
use \Helpers\View as view;
|
|
|
|
|
use \Helpers\dbh as dbh;
|
|
|
|
|
use \Users\Account;
|
|
|
|
|
use \Helpers\Table;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
对 \Users\Account 再次进行抽象,满足后台调用的需求,屏蔽一些错误等等
|
|
|
|
|
!!!!important!!!!大部分操作直接来自 \User\Account,慎重修改
|
|
|
|
|
*/
|
2014-09-13 02:18:32 +00:00
|
|
|
|
class Users
|
2013-11-22 04:20:00 +00:00
|
|
|
|
{
|
|
|
|
|
private $db;
|
|
|
|
|
protected $events = NULL; //事件
|
|
|
|
|
public $table;
|
|
|
|
|
|
|
|
|
|
public $account;
|
|
|
|
|
|
|
|
|
|
function __construct($accountClass = FALSE,$db = NULL)
|
|
|
|
|
{
|
|
|
|
|
if(empty($db))
|
|
|
|
|
{
|
|
|
|
|
$this->db = \Zend_Registry::get('db');
|
|
|
|
|
}else{
|
|
|
|
|
$this->db = $db;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->table = new Table();
|
|
|
|
|
|
|
|
|
|
$this->config = \Zend_Registry::get('config');
|
|
|
|
|
|
|
|
|
|
if($accountClass === TRUE)
|
|
|
|
|
{
|
|
|
|
|
$this->account = new Account();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//通过email地址返回用户信息是否存在
|
|
|
|
|
public function userExists($email = NULL)
|
|
|
|
|
{
|
|
|
|
|
if(empty($email))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(empty($this->account))
|
|
|
|
|
{
|
|
|
|
|
$account = new Account(FALSE);
|
|
|
|
|
}else{
|
|
|
|
|
$account = $this->account;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM {$account->memberTable} WHERE {$account->FieldEmail}=? LIMIT 1";
|
|
|
|
|
$sth = $this->db->prepare($sql);
|
|
|
|
|
$sth->execute(array($email));
|
|
|
|
|
$row = $sth->fetch();
|
|
|
|
|
|
|
|
|
|
unset($account);
|
|
|
|
|
|
|
|
|
|
if(isset($row['id']) && !empty($row['id']))
|
|
|
|
|
{
|
|
|
|
|
return $row;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-09-13 02:18:32 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 封禁用户
|
|
|
|
|
* @param $userid
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function ban($userid)
|
|
|
|
|
{
|
|
|
|
|
if(!is_numeric($userid) || $userid < 1)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sql = "UPDATE users SET status=-1 WHERE id=$userid";
|
|
|
|
|
$rs = $this->db->exec($sql);
|
|
|
|
|
|
|
|
|
|
if($rs > 0)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}//ban
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 解禁用户
|
|
|
|
|
* @param $userid
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function unban($userid)
|
|
|
|
|
{
|
|
|
|
|
if(!is_numeric($userid) || $userid < 1)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sql = "UPDATE users SET status=1 WHERE id=$userid";
|
|
|
|
|
$rs = $this->db->exec($sql);
|
|
|
|
|
|
|
|
|
|
if($rs > 0)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-22 04:20:00 +00:00
|
|
|
|
}
|