merge heihedata branche from r4135 to r4146
This commit is contained in:
parent
5f3c8e8cae
commit
7b7699f5f5
|
@ -1,5 +1,5 @@
|
|||
<ul>
|
||||
<li class="title">数据管理</li>
|
||||
<ul class="nav nav-pills nav-stacked well">
|
||||
<span class="label"><h4>数据管理</h4></span>
|
||||
<li><a href="/admin/data/md">元数据管理</a></li>
|
||||
<li><a href="/admin/data/newdata">新建元数据</a></li>
|
||||
<li><a href="/admin/data/author">数据作者管理</a></li>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<ul>
|
||||
<li class="title">申请管理与在线下载记录</li>
|
||||
<ul class="nav nav-pills nav-stacked well">
|
||||
<span class="label"><h4>申请管理与在线下载记录</h4></span>
|
||||
<li><a href="/admin/down/offlineapp">离线数据申请管理</a></li>
|
||||
<li><a href="/admin/down/offlineapps">离线数据申请管理(新)</a></li>
|
||||
<li><a href="/admin/down/offline">离线数据服务记录</a></li>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<ul class="nav nav-list">
|
||||
<li class="title">新闻中心</li>
|
||||
<ul class="nav nav-pills nav-stacked well">
|
||||
<span class="label"><h4>新闻中心</h4></span>
|
||||
<li><a href="/admin/news">新闻中心首页</a></li>
|
||||
<li><a href="/admin/news/catlog">栏目管理</a></li>
|
||||
<li><a href="/admin/news/catlog/add/1">栏目添加</a></li>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<ul>
|
||||
<li class="title">信息统计</li>
|
||||
<ul class="nav nav-pills nav-stacked well">
|
||||
<span class="label"><h4>信息统计</h4></span>
|
||||
<li><a href="/admin/stat/">统计概况</a></li>
|
||||
<li><a href="/admin/stat/unit">分单位统计</a></li>
|
||||
<li><a href="/admin/stat/month">分月统计</a></li>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<ul>
|
||||
<li class="title">系统管理</li>
|
||||
<ul class="nav nav-pills nav-stacked well">
|
||||
<span class="label"><h4>系统管理</h4></span>
|
||||
<li><a href="/admin/sys/emailtext">邮件模板管理</a></li>
|
||||
<!--<li><a href="/admin/sys/seekspace">文献平台同步</a></li>-->
|
||||
<li><a href="/admin/sys/message">管理消息</a></li>
|
||||
<li><a href="/admin/sys/ftptest">数据FTP测试</a></li>
|
||||
<li><a href="/admin/sys/recovery">数据恢复进展</a></li>
|
||||
<li><a href="/admin/sys/recovery">数据恢复进展</a></li>
|
||||
<li><a href="/admin/sys/problem">问题数据检查</a></li>
|
||||
<li><a href="/admin/sys/regions">GN地点管理</a></li>
|
||||
</ul>
|
|
@ -1,5 +1,5 @@
|
|||
<ul>
|
||||
<li class="title">用户管理</li>
|
||||
<ul class="nav nav-pills nav-stacked well">
|
||||
<span class="label"><h4>用户管理</h4></span>
|
||||
<li><a href="/admin/user/">用户管理首页</a></li>
|
||||
<li><a href="/admin/user/list">普通用户列表</a></li>
|
||||
<li><a href="/admin/user/adminlist">管理员列表</a></li>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<ul>
|
||||
<li><a href="/admin/watermd/replace">正则替换工具</a></li>
|
||||
<li><a href="/admin/watermd/citetitle">引用的标题替换</a></li>
|
||||
<li><a href="/admin/watermd/filesize">文件大小处理</a></li>
|
||||
<li><a href="/admin/watermd/uselimit">使用声明处理</a></li>
|
||||
<li><a href="/admin/watermd/contact">联系人替换</a></li>
|
||||
<li><a href="/admin/watermd/keyword">关键词替换</a></li>
|
||||
<ul class="nav nav-pills nav-stacked well">
|
||||
<li><a href="/admin/watermd/replace">正则替换工具</a></li>
|
||||
<li><a href="/admin/watermd/citetitle">引用的标题替换</a></li>
|
||||
<li><a href="/admin/watermd/filesize">文件大小处理</a></li>
|
||||
<li><a href="/admin/watermd/uselimit">使用声明处理</a></li>
|
||||
<li><a href="/admin/watermd/contact">联系人替换</a></li>
|
||||
<li><a href="/admin/watermd/keyword">关键词替换</a></li>
|
||||
</ul>
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
$this->headTitle($this->config->title->site);
|
||||
$this->headTitle('用户登录');
|
||||
$this->headTitle()->setSeparator(' - ');
|
||||
$this->breadcrumb('<a href="/">首页</a>');
|
||||
$this->breadcrumb('<a href="/account/login">用户登录</a>');
|
||||
$this->breadcrumb()->setSeparator(' > ');
|
||||
?>
|
||||
<div class="row-fluid">
|
||||
<?php if(!empty($this->error)) { ?>
|
||||
<?= $this->error ?>
|
||||
<?php } ?>
|
||||
<form method="post" class="form-horizontal">
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="username">用户名</label>
|
||||
<div class="controls">
|
||||
<input id="username" type="text" value="" name="username" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="password">密码</label>
|
||||
<div class="controls">
|
||||
<input id="password" type="password" value="" name="password" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="confirm_password">确认密码</label>
|
||||
<div class="controls">
|
||||
<input id="confirm_password" type="password" value="" name="confirm_password" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<input type="hidden" name="submit" value="1" />
|
||||
<input type="hidden" name="salt" value="<?= $this->salt ?>" />
|
||||
<button type="submit" class="btn">提交</button>
|
||||
<a href="/account/login">登录 </a> <a href="/account/register">注册新用户</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
|
@ -53,13 +53,13 @@
|
|||
<div class="control-group ">
|
||||
<label class="control-label">工作单位</label>
|
||||
<div class="controls">
|
||||
<input type="text" name="unit" value="<?php echo empty($this->info['unit']) ? "":$this->info['unit']; ?>" class="span8" />
|
||||
<input type="text" name="unit" value="<?php echo empty($this->info['unit']) ? "":$this->info['unit']; ?>" class="input-block-level" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group ">
|
||||
<label class="control-label">联系地址</label>
|
||||
<div class="controls">
|
||||
<input type="text" name="address" value="<?php echo empty($this->info['address']) ? "":$this->info['address']; ?>" class="span8" />
|
||||
<input type="text" name="address" value="<?php echo empty($this->info['address']) ? "":$this->info['address']; ?>" class="input-block-level" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group ">
|
||||
|
@ -107,13 +107,13 @@
|
|||
<div class="control-group ">
|
||||
<label class="control-label">项目名称</label>
|
||||
<div class="controls">
|
||||
<input type="text" name="project_title" value="<?php echo empty($this->info['project_title']) ? "":$this->info['project_title']; ?>" class="span8" />
|
||||
<input type="text" name="project_title" value="<?php echo empty($this->info['project_title']) ? "":$this->info['project_title']; ?>" class="input-block-level" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group ">
|
||||
<label class="control-label">项目简介</label>
|
||||
<div class="controls">
|
||||
<textarea name="project" class="span8"><?php echo empty($this->info['project']) ? "":$this->info['project']; ?></textarea>
|
||||
<textarea name="project" class="input-block-level"><?php echo empty($this->info['project']) ? "":$this->info['project']; ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
|
|
|
@ -1,24 +1,55 @@
|
|||
<?php
|
||||
$this->headTitle($this->config->title->site);
|
||||
$this->headTitle('用户登录');
|
||||
$this->headTitle()->setSeparator(' - ');
|
||||
$this->headLink()->appendStylesheet('/css/register.css');
|
||||
$this->breadcrumb('<a href="/">首页</a>');
|
||||
$this->breadcrumb('<a href="/account/fetchpwd">找回密码</a>');
|
||||
$this->breadcrumb()->setSeparator(' > ');
|
||||
?>
|
||||
<?php if (!empty($this->messages)) : ?>
|
||||
<div id="message">
|
||||
<?php
|
||||
foreach ($this->messages as $info)echo $info;
|
||||
?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($this->form) : ?>
|
||||
<div id="info">
|
||||
<?php echo $this->form;?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div id="tool">
|
||||
<a href="/account/login">登录 </a> <a href="/account/register">注册新用户</a>
|
||||
</div>
|
||||
<?php
|
||||
$this->headTitle($this->config->title->site);
|
||||
$this->headTitle('用户登录');
|
||||
$this->headTitle()->setSeparator(' - ');
|
||||
$this->headLink()->appendStylesheet('/css/register.css');
|
||||
$this->breadcrumb('<a href="/">首页</a>');
|
||||
$this->breadcrumb('<a href="/account/fetchpwd">找回密码</a>');
|
||||
$this->breadcrumb()->setSeparator(' > ');
|
||||
?>
|
||||
<div class="row-fluid">
|
||||
<?php if(!empty($this->error)) { ?>
|
||||
<?= $this->error ?>
|
||||
<?php } ?>
|
||||
<form method="post" class="form-horizontal">
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="email">E-mail</label>
|
||||
<div class="controls">
|
||||
<input id="email" type="text" value="" name="email" />
|
||||
<span class="help-block">请输入注册时填写的Email地址</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="captcha">验证码</label>
|
||||
<div class="controls">
|
||||
<input id="captcha" type="text" value="" name="captcha" />
|
||||
<img id="captcha_img" src="<?php echo $this->captcha ?>" style="cursor:pointer" />
|
||||
<a href="javascript:void(0);" onclick="changecaptcha()">看不清?</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<input type="hidden" name="submit" value="1" />
|
||||
<?php if(!empty($this->href)){?>
|
||||
<input type="hidden" name="href" value="<?= $this->href ?>" />
|
||||
<?php }?>
|
||||
<button type="submit" class="btn">提交</button>
|
||||
<a href="/account/login">登录 </a> <a href="/account/register">注册新用户</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
$('#captcha_img').click(function(e) {
|
||||
changecaptcha();
|
||||
});
|
||||
function changecaptcha(){
|
||||
$.ajax({
|
||||
url:"/account/captcha",
|
||||
data:"<?= time() ?>",
|
||||
success: function(src){
|
||||
document.getElementById('captcha_img').src = src;
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
|
@ -29,7 +29,7 @@
|
|||
</div>
|
||||
<? }else{ ?>
|
||||
<div class="alert alert-error alert-login">
|
||||
<?= $this->error ?>
|
||||
<?= $this->error['error'] ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="control-group">
|
||||
|
|
|
@ -479,7 +479,7 @@ endforeach;
|
|||
<a class="jiathis_counter_style"></a>
|
||||
</div>
|
||||
<!-- JiaThis Button END -->
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<script src="/js/metadata-view.js"></script>
|
||||
|
@ -554,4 +554,4 @@ var bound = {
|
|||
<p>没有找到对应的元数据。</p>
|
||||
<?php endif;?>
|
||||
</div>
|
||||
<!--<script type="text/javascript" src="http://v3.jiathis.com/code_mini/jia.js?uid=1336100079460458" charset="utf-8"></script>-->
|
||||
<script type="text/javascript" src="http://v3.jiathis.com/code_mini/jia.js?uid=1336100079460458" charset="utf-8"></script>
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
namespace Helpers;
|
||||
|
||||
class Captcha extends \Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
public $captcha;
|
||||
|
||||
private $sessionName = "captcha";
|
||||
private $imgDir = "images/captcha";
|
||||
|
||||
function __construct($db = NULL)
|
||||
{
|
||||
$this->loadCaptcha();
|
||||
}
|
||||
|
||||
public function loadCaptcha()
|
||||
{
|
||||
$this->captcha = new \Zend_Captcha_Image(array(
|
||||
'captcha' => 'Image',
|
||||
'wordLen' => 4,
|
||||
'fontsize'=>16,
|
||||
'width' => 100,
|
||||
'height' => 38,
|
||||
'dotNoiseLevel'=>2,
|
||||
'lineNoiseLevel'=>1,
|
||||
'timeout' => 300,
|
||||
'font' => '../data/fonts/ggbi.ttf',
|
||||
'imgDir' => $this->imgDir,
|
||||
'imgUrl' => '/images/captcha',
|
||||
));
|
||||
}
|
||||
|
||||
public function setCaptcha(){
|
||||
if(!is_dir($this->imgDir))
|
||||
{
|
||||
mkdir($this->imgDir);
|
||||
}
|
||||
|
||||
$this->captcha->generate();
|
||||
$_SESSION[$this->sessionName] = $this->captcha->getWord();
|
||||
$url = $this->captcha->getImgUrl()
|
||||
.$this->captcha->getId()
|
||||
.$this->captcha->getSuffix();
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function isValid($captchaword)
|
||||
{
|
||||
if($captchaword == $_SESSION[$this->sessionName])
|
||||
{
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -121,7 +121,12 @@ class Mail
|
|||
|
||||
$this->subject = $subject;
|
||||
$this->body = $body;
|
||||
$this->type = $row['type'];
|
||||
if(isset($row['type']))
|
||||
{
|
||||
$this->type = $row['type'];
|
||||
}else{
|
||||
$this->type = "text";
|
||||
}
|
||||
|
||||
}//加载模板
|
||||
|
||||
|
|
|
@ -1,372 +1,377 @@
|
|||
<?php
|
||||
namespace Users;
|
||||
|
||||
use \Helpers\View as view;
|
||||
use \Helpers\dbh as dbh;
|
||||
use \Users\Member;
|
||||
use \Mail\Mail;
|
||||
use \Users\Listener\AccountListener;
|
||||
use \Users\Listener\EditListener;
|
||||
use \Users\Listener\PwdListener;
|
||||
|
||||
class Account extends \Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
public $memberTable = "users";
|
||||
public $FieldIndex = "id";
|
||||
public $FieldUsername = "username";
|
||||
public $FieldPasword = "password";
|
||||
public $FieldLastlogin = "ts_last_login";
|
||||
public $FieldEmail = "email";
|
||||
public $FieldLastloginIp = "last_login_ip";
|
||||
public $GravatarEmailField = "gravatar_email";
|
||||
public $FieldRealname = "realname";
|
||||
|
||||
public $RoleMember = "member";
|
||||
|
||||
private $db;
|
||||
protected $events = NULL; //事件
|
||||
|
||||
/*
|
||||
需要挂载的事件分别放在不同的listener中,将各种操作进行模块化细分
|
||||
*/
|
||||
function __construct($initializingListener = TRUE,$db = NULL)
|
||||
{
|
||||
if(empty($db))
|
||||
{
|
||||
$this->db = \Zend_Registry::get('db');
|
||||
}else{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
$this->config = \Zend_Registry::get('config');
|
||||
|
||||
if($initializingListener === TRUE)
|
||||
{
|
||||
$this->loadListener();
|
||||
}
|
||||
}
|
||||
|
||||
public function loadListener()
|
||||
{
|
||||
//主要操作,账号注册,登录,设置session等
|
||||
$AccountListener = new AccountListener();
|
||||
@$this->events()->attachAggregate($AccountListener);
|
||||
|
||||
//账户编辑
|
||||
$EditListener = new EditListener();
|
||||
@$this->events()->attachAggregate($EditListener);
|
||||
|
||||
//账户安全性(找回密码)
|
||||
$PwdListener = new PwdListener();
|
||||
@$this->events()->attachAggregate($PwdListener);
|
||||
}
|
||||
|
||||
public function events(\Zend_EventManager_EventCollection $events = NULL)
|
||||
{
|
||||
if ($events !== NULL) {
|
||||
$this->events = $events;
|
||||
} elseif ($this->events === NULL) {
|
||||
$this->events = new \Zend_EventManager_EventManager(__CLASS__);
|
||||
}
|
||||
return $this->events;
|
||||
}
|
||||
|
||||
//获取账号信息,数组
|
||||
public function getAccountInfo($id = 0)
|
||||
{
|
||||
if($id == 0)
|
||||
{
|
||||
$id = view::User('id');
|
||||
}
|
||||
$sql = "SELECT * FROM {$this->memberTable} WHERE id=$id";
|
||||
$rs = $this->db->query($sql);
|
||||
return $rs->fetch();
|
||||
}
|
||||
|
||||
//注册
|
||||
public function register($data)
|
||||
{
|
||||
$params = compact('data');
|
||||
$results = $this->events()->trigger('register.checkParam', $this, $params);
|
||||
$cache_data = $results->bottom();
|
||||
|
||||
if($cache_data !== true)
|
||||
{
|
||||
if(!is_array($cache_data))
|
||||
{
|
||||
return array('error'=>$cache_data);
|
||||
}else{
|
||||
return $cache_data;
|
||||
}
|
||||
}
|
||||
|
||||
$results = $this->events()->trigger('register.checkUser', $this, $params);
|
||||
$cache_data = $results->bottom();
|
||||
|
||||
if($cache_data !== true)
|
||||
{
|
||||
if(!is_array($cache_data))
|
||||
{
|
||||
return array('error'=>$cache_data);
|
||||
}else{
|
||||
return $cache_data;
|
||||
}
|
||||
}
|
||||
|
||||
$loginData = array(
|
||||
'username'=>$data['username'],
|
||||
'password'=>$data['password']
|
||||
);
|
||||
|
||||
$data['password'] = md5($data['password']);
|
||||
$data['usertype'] = "member";
|
||||
unset($data['confirm_password']);
|
||||
|
||||
$dbh = new dbh();
|
||||
|
||||
$id = $dbh->insert($this->memberTable,$data,true);
|
||||
|
||||
if(!empty($id) && is_numeric($id))
|
||||
{
|
||||
$this->storeLogin($loginData);
|
||||
$mb = new Member();
|
||||
$mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); //username, md5(password)
|
||||
$params = compact('data','id');
|
||||
$results = $this->events()->trigger('register.success', $this, $params);
|
||||
return array("success" => 1);
|
||||
}else{
|
||||
if($id === false)
|
||||
{
|
||||
return array('error'=>'服务器开小差了,请稍后再试');
|
||||
}else{
|
||||
return array('error'=>'服务器处理中遇到错误,请联系管理员');
|
||||
}
|
||||
}
|
||||
|
||||
}//register
|
||||
|
||||
//登陆
|
||||
public function login($data)
|
||||
{
|
||||
$results = $this->events()->trigger('login.checkParam', $this, compact('data'));
|
||||
$cache_data = $results->bottom();
|
||||
|
||||
if($cache_data !== true)
|
||||
{
|
||||
if(!is_array($cache_data))
|
||||
{
|
||||
return array('error'=>$cache_data);
|
||||
}else{
|
||||
return $cache_data;
|
||||
}
|
||||
}
|
||||
|
||||
$state = $this->storeLogin($data);
|
||||
|
||||
$mb = new Member();
|
||||
$mb->putcookie($data[$this->FieldUsername],md5($data[$this->FieldPasword]));
|
||||
|
||||
return $state;
|
||||
}//login
|
||||
|
||||
//storeLogin
|
||||
//将登录信息保存在session和cookie中
|
||||
public function storeLogin($data,$md5verify = true)
|
||||
{
|
||||
$auth = \Zend_Auth::getInstance();
|
||||
$authAdapter = new \Zend_Auth_Adapter_DbTable($this->db);
|
||||
$authAdapter->setTableName($this->memberTable)
|
||||
->setIdentityColumn($this->FieldUsername)
|
||||
->setCredentialColumn($this->FieldPasword);
|
||||
|
||||
if($data[$this->FieldPasword] == 0)
|
||||
{
|
||||
$password = "0";
|
||||
}else{
|
||||
if($md5verify === false)
|
||||
{
|
||||
$password = $data[$this->FieldPasword];
|
||||
}else{
|
||||
$password = md5($data[$this->FieldPasword]);
|
||||
}
|
||||
}
|
||||
|
||||
$authAdapter->setIdentity($data[$this->FieldUsername])->setCredential($password);
|
||||
|
||||
$result = $auth->authenticate($authAdapter);
|
||||
if ($result->isValid()) {
|
||||
|
||||
$user = $authAdapter->getResultRowObject(null,$this->FieldPasword);
|
||||
$email = $user->email;
|
||||
$results = $this->events()->trigger('login.success.createAvatar', $this, compact('email'));
|
||||
$user->avatar = $results->bottom();
|
||||
$auth->getStorage()->write($user);
|
||||
|
||||
$id = $user->id;
|
||||
@$results = $this->events()->trigger('login.success.updateStatus', $this, compact('id'));
|
||||
|
||||
return array('success'=>1);
|
||||
}
|
||||
return array('error'=>'处理中发现错误,请重试');
|
||||
}
|
||||
|
||||
//注册信息参数
|
||||
public function getParam(\Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$data = array(
|
||||
'username'=>$request->getParam('username'),
|
||||
'password'=>$request->getParam('password'),
|
||||
'confirm_password'=>$request->getParam('confirm_password'),
|
||||
'email'=>$request->getParam('email'),
|
||||
'realname'=>$request->getParam('realname')
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
|
||||
//获取用户账户修改参数
|
||||
public function getEditParam(\Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$type = $request->getParam('type');
|
||||
|
||||
if($type == "general")
|
||||
{
|
||||
$data = array(
|
||||
'realname'=>$request->getParam('realname'),
|
||||
'signature'=>$request->getParam('signature'),
|
||||
'description'=>$request->getParam('description')
|
||||
);
|
||||
}
|
||||
|
||||
if($type == "password")
|
||||
{
|
||||
$data = array(
|
||||
'password' => $request->getParam('password'),
|
||||
'password_new'=>$request->getParam('password_new'),
|
||||
'password_confirm'=>$request->getParam('password_confirm')
|
||||
);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
//编辑
|
||||
public function edit($data,$type)
|
||||
{
|
||||
$results = $this->events()->trigger('edit.checkParam', $this, compact('data','type'));
|
||||
$cache_data = $results->bottom();
|
||||
|
||||
if($cache_data !== true)
|
||||
{
|
||||
return $cache_data;
|
||||
}
|
||||
|
||||
if($type == "general")
|
||||
{
|
||||
$data['signature'] = htmlspecialchars($data['signature']);
|
||||
$data['description'] = htmlspecialchars($data['description']);
|
||||
}else if($type == "password")
|
||||
{
|
||||
$data['password'] = md5($data['password_new']);
|
||||
unset($data['password_new']);
|
||||
unset($data['password_confirm']);
|
||||
}else{
|
||||
return "参数错误";
|
||||
}
|
||||
|
||||
$dbh = new dbh();
|
||||
$uid = view::User('id');
|
||||
if($dbh->update($this->memberTable,$data," id=$uid") === true)
|
||||
{
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//找回密码
|
||||
public function getMyPassword($email)
|
||||
{
|
||||
$results = $this->events()->trigger('pwd.forgot.checkParam', $this, compact('email'));
|
||||
$cache_data = $results->bottom();
|
||||
|
||||
if($cache_data !== true)
|
||||
{
|
||||
return $cache_data;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM {$this->memberTable} WHERE email='$email'";
|
||||
$rs = $this->db->query($sql);
|
||||
$row = $rs->fetch();
|
||||
|
||||
if(!isset($row['username']) || empty($row['username']))
|
||||
{
|
||||
return array('error'=>"此邮箱并未注册",'place'=>'email');
|
||||
}
|
||||
|
||||
$salt = md5($email.'---'.$row['username']);
|
||||
|
||||
$sql = "UPDATE {$this->memberTable} SET salt='$salt' WHERE id={$row['id']}";
|
||||
$state = $this->db->exec($sql);
|
||||
|
||||
if($state<1)
|
||||
{
|
||||
return array('error'=>"处理中出现错误,请重试",'place'=>'email');
|
||||
}
|
||||
|
||||
$mail_template = "forgotpassword";
|
||||
$mail_data = array(
|
||||
'name'=>$row['realname'],
|
||||
'link'=> view::getHostLink().'/account/getpassword/salt/'.$salt
|
||||
);
|
||||
|
||||
$mail = new Mail();
|
||||
|
||||
$mail->loadTemplate($mail_template,$mail_data);
|
||||
$mail->addTo($email,$row['realname']);
|
||||
$mail->send();
|
||||
|
||||
return array("success"=>1);
|
||||
}
|
||||
|
||||
//重置密码
|
||||
public function resetPassword($data)
|
||||
{
|
||||
$results = $this->events()->trigger('pwd.reset.checkParam', $this, compact('data'));
|
||||
$cache_data = $results->bottom();
|
||||
|
||||
if($cache_data !== true)
|
||||
{
|
||||
return $cache_data;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM {$this->memberTable} WHERE salt=?";
|
||||
$sth = $this->db->prepare($sql);
|
||||
$sth->execute(array($data['salt']));
|
||||
$row = $sth->fetch();
|
||||
|
||||
if(!isset($row['username']) || empty($row['username']))
|
||||
{
|
||||
return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password');
|
||||
}
|
||||
|
||||
if($row['username'] !== $data['username'])
|
||||
{
|
||||
return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password');
|
||||
}
|
||||
|
||||
$sql = "UPDATE {$this->memberTable} SET password='".md5($data['password'])."',salt='' WHERE id={$row['id']}";
|
||||
$this->db->exec($sql);
|
||||
|
||||
$mail_template = "getpassworded";
|
||||
$mail_data = array(
|
||||
'name'=>$row['realname'],
|
||||
);
|
||||
$mail = new Mail();
|
||||
$mail->loadTemplate($mail_template,$mail_data);
|
||||
$mail->addTo($row['email'],$row['realname']);
|
||||
$mail->send();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
<?php
|
||||
namespace Users;
|
||||
|
||||
use \Helpers\View as view;
|
||||
use \Helpers\dbh as dbh;
|
||||
use \Users\Member;
|
||||
use \Mail\Mail;
|
||||
use \Users\Listener\AccountListener;
|
||||
use \Users\Listener\EditListener;
|
||||
use \Users\Listener\PwdListener;
|
||||
|
||||
class Account extends \Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
public $memberTable = "users";
|
||||
public $FieldIndex = "id";
|
||||
public $FieldUsername = "username";
|
||||
public $FieldPasword = "password";
|
||||
public $FieldLastlogin = "ts_last_login";
|
||||
public $FieldEmail = "email";
|
||||
public $FieldLastloginIp = "last_login_ip";
|
||||
public $GravatarEmailField = "gravatar_email";
|
||||
public $FieldRealname = "realname";
|
||||
|
||||
public $RoleMember = "member";
|
||||
public $getPwdEmailTemplate = "users-changepassword"; //找回密码的邮件模板名称
|
||||
public $PwdChangedEmailTemplate = "users-password-changed"; //密码修改后的邮件模板
|
||||
|
||||
private $db;
|
||||
protected $events = NULL; //事件
|
||||
private $config;
|
||||
|
||||
/*
|
||||
需要挂载的事件分别放在不同的listener中,将各种操作进行模块化细分
|
||||
*/
|
||||
function __construct($initializingListener = TRUE,$db = NULL)
|
||||
{
|
||||
if(empty($db))
|
||||
{
|
||||
$this->db = \Zend_Registry::get('db');
|
||||
}else{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
$this->config = \Zend_Registry::get('config');
|
||||
|
||||
if($initializingListener === TRUE)
|
||||
{
|
||||
$this->loadListener();
|
||||
}
|
||||
}
|
||||
|
||||
public function loadListener()
|
||||
{
|
||||
//主要操作,账号注册,登录,设置session等
|
||||
$AccountListener = new AccountListener();
|
||||
@$this->events()->attachAggregate($AccountListener);
|
||||
|
||||
//账户编辑
|
||||
$EditListener = new EditListener();
|
||||
@$this->events()->attachAggregate($EditListener);
|
||||
|
||||
//账户安全性(找回密码)
|
||||
$PwdListener = new PwdListener();
|
||||
@$this->events()->attachAggregate($PwdListener);
|
||||
}
|
||||
|
||||
public function events(\Zend_EventManager_EventCollection $events = NULL)
|
||||
{
|
||||
if ($events !== NULL) {
|
||||
$this->events = $events;
|
||||
} elseif ($this->events === NULL) {
|
||||
$this->events = new \Zend_EventManager_EventManager(__CLASS__);
|
||||
}
|
||||
return $this->events;
|
||||
}
|
||||
|
||||
//获取账号信息,数组
|
||||
public function getAccountInfo($id = 0)
|
||||
{
|
||||
if($id == 0)
|
||||
{
|
||||
$id = view::User('id');
|
||||
}
|
||||
$sql = "SELECT * FROM {$this->memberTable} WHERE id=$id";
|
||||
$rs = $this->db->query($sql);
|
||||
return $rs->fetch();
|
||||
}
|
||||
|
||||
//注册
|
||||
public function register($data)
|
||||
{
|
||||
$params = compact('data');
|
||||
$results = $this->events()->trigger('register.checkParam', $this, $params);
|
||||
$cache_data = $results->bottom();
|
||||
|
||||
if($cache_data !== true)
|
||||
{
|
||||
if(!is_array($cache_data))
|
||||
{
|
||||
return array('error'=>$cache_data);
|
||||
}else{
|
||||
return $cache_data;
|
||||
}
|
||||
}
|
||||
|
||||
$results = $this->events()->trigger('register.checkUser', $this, $params);
|
||||
$cache_data = $results->bottom();
|
||||
|
||||
if($cache_data !== true)
|
||||
{
|
||||
if(!is_array($cache_data))
|
||||
{
|
||||
return array('error'=>$cache_data);
|
||||
}else{
|
||||
return $cache_data;
|
||||
}
|
||||
}
|
||||
|
||||
$loginData = array(
|
||||
'username'=>$data['username'],
|
||||
'password'=>$data['password']
|
||||
);
|
||||
|
||||
$data['password'] = md5($data['password']);
|
||||
$data['usertype'] = "member";
|
||||
unset($data['confirm_password']);
|
||||
|
||||
$dbh = new dbh();
|
||||
|
||||
$id = $dbh->insert($this->memberTable,$data,true);
|
||||
|
||||
if(!empty($id) && is_numeric($id))
|
||||
{
|
||||
$this->storeLogin($loginData);
|
||||
$mb = new Member();
|
||||
$mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); //username, md5(password)
|
||||
$params = compact('data','id');
|
||||
$results = $this->events()->trigger('register.success', $this, $params);
|
||||
return array("success" => 1);
|
||||
}else{
|
||||
if($id === false)
|
||||
{
|
||||
return array('error'=>'服务器开小差了,请稍后再试');
|
||||
}else{
|
||||
return array('error'=>'服务器处理中遇到错误,请联系管理员');
|
||||
}
|
||||
}
|
||||
|
||||
}//register
|
||||
|
||||
//登陆
|
||||
public function login($data)
|
||||
{
|
||||
$results = $this->events()->trigger('login.checkParam', $this, compact('data'));
|
||||
$cache_data = $results->bottom();
|
||||
|
||||
if($cache_data !== true)
|
||||
{
|
||||
if(!is_array($cache_data))
|
||||
{
|
||||
return array('error'=>$cache_data);
|
||||
}else{
|
||||
return $cache_data;
|
||||
}
|
||||
}
|
||||
|
||||
$state = $this->storeLogin($data);
|
||||
|
||||
$mb = new Member();
|
||||
$mb->putcookie($data[$this->FieldUsername],md5($data[$this->FieldPasword]));
|
||||
|
||||
return $state;
|
||||
}//login
|
||||
|
||||
//storeLogin
|
||||
//将登录信息保存在session和cookie中
|
||||
public function storeLogin($data,$md5verify = true)
|
||||
{
|
||||
$auth = \Zend_Auth::getInstance();
|
||||
$authAdapter = new \Zend_Auth_Adapter_DbTable($this->db);
|
||||
$authAdapter->setTableName($this->memberTable)
|
||||
->setIdentityColumn($this->FieldUsername)
|
||||
->setCredentialColumn($this->FieldPasword);
|
||||
|
||||
if($data[$this->FieldPasword] === 0)
|
||||
{
|
||||
$password = "0";
|
||||
}else{
|
||||
if($md5verify == false)
|
||||
{
|
||||
$password = $data[$this->FieldPasword];
|
||||
}else{
|
||||
$password = md5($data[$this->FieldPasword]);
|
||||
}
|
||||
}
|
||||
|
||||
$authAdapter->setIdentity($data[$this->FieldUsername])->setCredential($password);
|
||||
$result = $auth->authenticate($authAdapter);
|
||||
|
||||
if ($result->isValid()) {
|
||||
|
||||
$user = $authAdapter->getResultRowObject(null,$this->FieldPasword);
|
||||
$email = $user->email;
|
||||
$results = $this->events()->trigger('login.success.createAvatar', $this, compact('email'));
|
||||
$user->avatar = $results->bottom();
|
||||
$auth->getStorage()->write($user);
|
||||
|
||||
$id = $user->id;
|
||||
@$results = $this->events()->trigger('login.success.updateStatus', $this, compact('id'));
|
||||
|
||||
return array('success'=>1);
|
||||
}else{
|
||||
return array("error"=>"用户信息验证失败,请重新登录");
|
||||
}
|
||||
return array('error'=>'处理中发现错误,请重试');
|
||||
}
|
||||
|
||||
//注册信息参数
|
||||
public function getParam(\Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$data = array(
|
||||
'username'=>$request->getParam('username'),
|
||||
'password'=>$request->getParam('password'),
|
||||
'confirm_password'=>$request->getParam('confirm_password'),
|
||||
'email'=>$request->getParam('email'),
|
||||
'realname'=>$request->getParam('realname')
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
|
||||
//获取用户账户修改参数
|
||||
public function getEditParam(\Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$type = $request->getParam('type');
|
||||
|
||||
if($type == "general")
|
||||
{
|
||||
$data = array(
|
||||
'realname'=>$request->getParam('realname'),
|
||||
'signature'=>$request->getParam('signature'),
|
||||
'description'=>$request->getParam('description')
|
||||
);
|
||||
}
|
||||
|
||||
if($type == "password")
|
||||
{
|
||||
$data = array(
|
||||
'password' => $request->getParam('password'),
|
||||
'password_new'=>$request->getParam('password_new'),
|
||||
'password_confirm'=>$request->getParam('password_confirm')
|
||||
);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
//编辑
|
||||
public function edit($data,$type)
|
||||
{
|
||||
$results = $this->events()->trigger('edit.checkParam', $this, compact('data','type'));
|
||||
$cache_data = $results->bottom();
|
||||
|
||||
if($cache_data !== true)
|
||||
{
|
||||
return $cache_data;
|
||||
}
|
||||
|
||||
if($type == "general")
|
||||
{
|
||||
$data['signature'] = htmlspecialchars($data['signature']);
|
||||
$data['description'] = htmlspecialchars($data['description']);
|
||||
}else if($type == "password")
|
||||
{
|
||||
$data['password'] = md5($data['password_new']);
|
||||
unset($data['password_new']);
|
||||
unset($data['password_confirm']);
|
||||
}else{
|
||||
return "参数错误";
|
||||
}
|
||||
|
||||
$dbh = new dbh();
|
||||
$uid = view::User('id');
|
||||
if($dbh->update($this->memberTable,$data," id=$uid") === true)
|
||||
{
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//找回密码
|
||||
public function getMyPassword($email)
|
||||
{
|
||||
$results = $this->events()->trigger('pwd.forgot.checkParam', $this, compact('email'));
|
||||
$cache_data = $results->bottom();
|
||||
|
||||
if($cache_data !== true)
|
||||
{
|
||||
return $cache_data;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM {$this->memberTable} WHERE email='$email'";
|
||||
$rs = $this->db->query($sql);
|
||||
$row = $rs->fetch();
|
||||
|
||||
if(!isset($row['username']) || empty($row['username']))
|
||||
{
|
||||
return array('error'=>"此邮箱并未注册",'place'=>'email');
|
||||
}
|
||||
|
||||
$salt = md5($email.'--'.time().'--'.$row['username']);
|
||||
|
||||
$sql = "UPDATE {$this->memberTable} SET salt='$salt' WHERE id={$row['id']}";
|
||||
$state = $this->db->exec($sql);
|
||||
|
||||
if($state<1)
|
||||
{
|
||||
return array('error'=>"处理中出现错误,请重试",'place'=>'email');
|
||||
}
|
||||
|
||||
$mail_data = array(
|
||||
'name'=>$row['realname'],
|
||||
'link'=> view::getHostLink().'/account/fetchpwd/?salt='.$salt,
|
||||
'site' => $this->config->title->site
|
||||
);
|
||||
|
||||
$mail = new Mail();
|
||||
|
||||
$mail->loadTemplate($this->getPwdEmailTemplate,$mail_data);
|
||||
$mail->addTo($email,$row['realname']);
|
||||
$mail->send();
|
||||
|
||||
return array("success"=>1);
|
||||
}
|
||||
|
||||
//重置密码
|
||||
public function resetPassword($data)
|
||||
{
|
||||
$results = $this->events()->trigger('pwd.reset.checkParam', $this, compact('data'));
|
||||
$cache_data = $results->bottom();
|
||||
|
||||
if($cache_data !== true)
|
||||
{
|
||||
return $cache_data;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM {$this->memberTable} WHERE salt=?";
|
||||
$sth = $this->db->prepare($sql);
|
||||
$sth->execute(array($data['salt']));
|
||||
$row = $sth->fetch();
|
||||
|
||||
if(!isset($row['username']) || empty($row['username']))
|
||||
{
|
||||
return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password');
|
||||
}
|
||||
|
||||
if($row['username'] !== $data['username'])
|
||||
{
|
||||
return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password');
|
||||
}
|
||||
|
||||
$sql = "UPDATE {$this->memberTable} SET password='".md5($data['password'])."',salt='' WHERE id={$row['id']}";
|
||||
$this->db->exec($sql);
|
||||
|
||||
$mail_data = array(
|
||||
'name' => $row['realname'],
|
||||
'site' => $this->config->title->site
|
||||
);
|
||||
$mail = new Mail();
|
||||
$mail->loadTemplate($this->PwdChangedEmailTemplate,$mail_data);
|
||||
$mail->addTo($row['email'],$row['realname']);
|
||||
$mail->send();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace \Users;
|
||||
namespace Users;
|
||||
|
||||
class Member
|
||||
{
|
||||
|
|
|
@ -45,9 +45,9 @@ class LoginOperate implements \Users\Event\LoginEvent
|
|||
|
||||
if(!empty($data['username']))
|
||||
{
|
||||
if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/",$data['username']))
|
||||
if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{2,15}$/",$data['username']))
|
||||
{
|
||||
return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在5到25个字符之间",'place'=>'username');
|
||||
return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在3到25个字符之间",'place'=>'username');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,6 +106,10 @@ class LoginOperate implements \Users\Event\LoginEvent
|
|||
|
||||
}//loginSuccess
|
||||
|
||||
|
||||
//检查token表记录
|
||||
public function checkOAuthToken()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -58,6 +58,11 @@ class PwdOperate implements \Users\Event\PwdEvent
|
|||
{
|
||||
$data = $e->getParam('data');
|
||||
|
||||
if(empty($data['salt']))
|
||||
{
|
||||
return array('error'=>"密钥不正确,请重新申请","place"=>'salt');
|
||||
}
|
||||
|
||||
if(empty($data['username']))
|
||||
{
|
||||
return array('error'=>"请输入用户名",'place'=>'username');
|
||||
|
@ -70,12 +75,12 @@ class PwdOperate implements \Users\Event\PwdEvent
|
|||
|
||||
if(strlen($data['password']) < 6)
|
||||
{
|
||||
return array('error'=>"密码长度太短,为了安全最少输入6位哦",'place'=>'password');
|
||||
return array('error'=>"密码长度太短,为了安全最少输入6位",'place'=>'password');
|
||||
}
|
||||
|
||||
if(strlen($data['password']) > 14)
|
||||
{
|
||||
return array('error'=>"密码太长,亲您记得住吗?不要超过14位哦",'place'=>'password');
|
||||
return array('error'=>"密码太长,请不要超过14位",'place'=>'password');
|
||||
}
|
||||
|
||||
if(empty($data['confirm_password']))
|
||||
|
|
Loading…
Reference in New Issue