westdc-zf1/application/module/Users/Users.php

125 lines
2.5 KiB
PHP
Raw Normal View History

2013-12-13 08:42:34 +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慎重修改
*/
class Users extends \Zend_Controller_Plugin_Abstract
{
private $db;
protected $events = NULL; //事件
public $table;
2014-06-04 08:25:49 +00:00
private $usertype;
2013-12-13 08:42:34 +00:00
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();
}
}
2014-06-04 08:25:49 +00:00
//初始化用户类型
public function initUserType()
{
$this->usertype = array(
'普通会员' => 'member',
'系统管理员' => 'administrator',
2014-06-05 09:49:04 +00:00
'青海省气象科学研究所' => 'meteorologic',
2014-06-11 01:58:52 +00:00
'青海省环境监测中心站' => 'qhemc',
2014-06-05 09:49:04 +00:00
'青海省水土保持局' => 'watersoil',
'青海省林业调查规划院' => 'forestry',
2014-06-11 01:58:52 +00:00
'青海省水文水资源局' => 'hydrology',
'青海省草原总站' => 'grassland',
'青海省生态环境遥感监测中心' => 'qherc'
2014-06-04 08:25:49 +00:00
);
}
//获取用户类型
public function getUserType()
{
$this->initUserType();
return $this->usertype;
}
2014-06-05 09:49:04 +00:00
//通过ID获取User信息
2014-06-04 08:25:49 +00:00
public function getUser($id)
{
$sql="select * from users where id=?";
$result=$this->db->query($sql,$id);
$rows = $result->fetch();
return $rows;
}
2014-06-05 09:49:04 +00:00
public function getUserInfo($id)
{
return $this->getUser($id);
}
2013-12-13 08:42:34 +00:00
//通过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;
}
}
public function storeNewAuthCredential($user)
{
if(get_class($user) != 'stdClass')
{
return false;
}
$auth = \Zend_Auth::getInstance();
if($auth->getStorage()->write($user))
return true;
else
return false;
}
}