修改子平台用户登录及管理的相关功能

This commit is contained in:
Li Jianxuan 2014-06-05 09:53:18 +00:00
parent 4d8c3abbce
commit 71fac4e412
11 changed files with 478 additions and 415 deletions

View File

@ -1,7 +1,8 @@
<?php <?php
use Helpers\View as view; use Helpers\View as view;
use \Users\Local; use Helpers\PDO;
use Helpers\dbh; use Users\Users;
class Admin_UserController extends Zend_Controller_Action class Admin_UserController extends Zend_Controller_Action
{ {
function preDispatch() function preDispatch()
@ -34,57 +35,21 @@ class Admin_UserController extends Zend_Controller_Action
function listAction() function listAction()
{ {
$select=$this->db->select(); $select=$this->db->select();
$select->from('users')
$select->from('users')
->where('usertype = ?', 'member') ->where('usertype = ?', 'member')
->order('users.id desc'); ->order('users.id desc');
view::addPaginator($select,$this,20);
}//listAction
#添加本地用户
function localAction()
{
$this->view->ac = $ac = $this->_getParam('ac');
$submit = $this->_getParam('submit');
$local = new Local();
if(empty($ac)) $paginator = Zend_Paginator::factory($select);
{ $paginator->setCurrentPageNumber($this->_getParam('page'));
$select=$this->db->select(); $paginator->setItemCountPerPage(30);
$paginator->setView($this->view);
$select->from(array('u'=>'users','l'=>'users_local')) Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
->join(array('l'=>'users_local'),'u.id=l.uid') $this->view->paginator=$paginator;
->order('u.id desc');
view::addPaginator($select,$this,20);
return;
}
if($ac=='addLocal')
{
if(view::isXmlHttpRequest($this))
{
$status = $local->addLocalUser();
if($status !== true)
{
$this->jsonexit(array('error'=>$status));
return true;
}else{
$this->jsonexit(array('success'=>1));
return true;
}
}else{
}
}
if($ac == 'delete')
{
view::Post($this,$local->deleteUser($this->_getParam('id')),-1);
return;
}
}//listAction }//listAction
function searchAction() function searchAction()
@ -204,10 +169,10 @@ class Admin_UserController extends Zend_Controller_Action
if (isset($id)) if (isset($id))
{ {
try { try {
$sql="select * from users where id=?"; $user = new \Users\Users;
$result=$this->db->query($sql,$id); $this->view->infos=$user->getUser($id);
$rows = $result->fetch(); $this->view->usertypes = $user->getUserType();
$this->view->infos=$rows;
} catch (Exception $e) { } catch (Exception $e) {
$this->messenger->addMessage($e->getMessage()); $this->messenger->addMessage($e->getMessage());
} }
@ -276,6 +241,7 @@ class Admin_UserController extends Zend_Controller_Action
$updates=array(); $updates=array();
if (isset($id)) if (isset($id))
{ {
if(!empty($newpwd)&&!empty($cfnewpwd)) if(!empty($newpwd)&&!empty($cfnewpwd))
{ {
if($newpwd==$cfnewpwd) if($newpwd==$cfnewpwd)
@ -303,6 +269,7 @@ class Admin_UserController extends Zend_Controller_Action
} catch (Exception $e) { } catch (Exception $e) {
$this->messenger->addMessage($e->getMessage()); $this->messenger->addMessage($e->getMessage());
} }
$this->_redirect("/admin/user/show/id/$id"); $this->_redirect("/admin/user/show/id/$id");
} }
else { else {

View File

@ -2,51 +2,46 @@
$this->headTitle($this->config->title->site); $this->headTitle($this->config->title->site);
$this->headTitle('后台管理'); $this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - '); $this->headTitle()->setSeparator(' - ');
# $this->headLink()->appendStylesheet('/css/admin.css'); $this->headLink()->appendStylesheet('/css/admin.css');
$this->breadcrumb('<a href="/">首页</a>'); $this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin/">后台首页</a>'); $this->breadcrumb('<a href="/admin/">后台首页</a>');
$this->breadcrumb('<a href="/admin/user">用户管理</a>'); $this->breadcrumb('<a href="/admin/user">用户管理</a>');
$this->breadcrumb()->setSeparator(' > '); $this->breadcrumb()->setSeparator(' > ');
?> ?>
<div id="leftPanel">
<style> <?= $this->partial('user/left.phtml'); ?>
table thead tr th {background:#EBF2F6;color:#444;}
.high{background:#444;color:#FFF;}
</style>
<div class="row-fluid">
<div class="span3"><?= $this->partial('user/left.phtml'); ?></div>
<div class="span9">
<h3>管理员列表</h3>
<hr />
<table class="table table-bordered table-hover table-condensed"><thead>
<thead>
<tr>
<th>用户名</th>
<th>电子邮箱</th>
<th>用户类型</th>
<th>真实姓名</th>
<th>电话</th>
<th>操作</th>
</tr>
</thead>
<?php if (count($this->paginator)): ?>
<?php $autoindex=0;?>
<?php foreach ($this->paginator as $item): ?>
<?php $autoindex++;?>
<tr class="<?php if($autoindex%2 == 0) echo 'even'; else echo 'odd'; ?>">
<td><?= $item['username']?></td>
<td><?= $item['email']; ?></td>
<td><?= $item['usertype']; ?></td>
<td><?= $item['realname']; ?></td>
<td><?= $item['phone']; ?></td>
<td>
<a href='/admin/user/show/id/<?= $item['id'];?>'>查看详细</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</table>
<div class="pagenavi"><?= $this->paginator; ?></div>
</div>
</div> </div>
<div id="rightPanel">
<div class="title">管理员列表</div>
<div class=""><a href="/admin/user/adminlist/ac/sync">同步管理员到geonetwork</a></div>
<table>
<thead>
<tr>
<td width='150'>用户名</td>
<td width='250'>电子邮箱</td>
<td width='100'>用户类型</td>
<td width='150'>真实姓名</td>
<td width='150'>电话</td>
<td width='150'>操作</td>
</tr>
</thead>
<?php if (count($this->paginator)): ?>
<?php $autoindex=0;?>
<?php foreach ($this->paginator as $item): ?>
<?php $autoindex++;?>
<tr class="<?php if($autoindex%2 == 0) echo 'even'; else echo 'odd'; ?>">
<td><?= $item['username']?></td>
<td><?= $item['email']; ?></td>
<td><?= $item['usertype']; ?></td>
<td><?= $item['realname']; ?></td>
<td><?= $item['phone']; ?></td>
<td>
<a href='/admin/user/show/id/<?= $item['id'];?>'>查看详细</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</table>
<div class="pagenavi"><?= $this->paginator; ?></div>
</div>

View File

@ -2,26 +2,42 @@
$this->headTitle($this->config->title->site); $this->headTitle($this->config->title->site);
$this->headTitle('后台管理'); $this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - '); $this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/admin.css');
$this->breadcrumb('<a href="/">首页</a>'); $this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('后台管理首页'); $this->breadcrumb('后台管理首页');
$this->breadcrumb()->setSeparator(' > '); $this->breadcrumb()->setSeparator(' > ');
?> ?>
<div id="leftPanel"> <div class="row-fluid">
<?= $this->partial('user/left.phtml'); ?> <div class="span3">
</div> <?= $this->partial('user/left.phtml'); ?>
</div>
<div id="rightPanel">
<div><h4>用户总数: <?php echo $this->su['total'];?>,其中管理员: <?php echo $this->suadmin['total'];?></h4></div> <div class="span9">
<hr /> <h3>用户总数: <?php echo $this->su['total'];?>,其中管理员: <?php echo $this->suadmin['total'];?></h3>
<div> <hr />
<h4>搜索用户</h4>
<form action="/admin/user/search/" method="get"> <form action="/admin/user/search/" method="get">
<input type="hidden" name="search" value='1' /> <div class="control-group">
<div>姓名 <input type="text" name="realname" /></div> <label class="control-label" for="inputName">姓名/用户名</label>
<div>单位 <input type="text" name="unit" /></div> <div class="controls">
<div>项目 <input type="text" name="project" /></div> <input type="text" id="inputName" placeholder="Name or Username" name="realname" class="input-xxlarge">
<div><input type="submit" class="btn btn-success" value="搜索" /></div> </div>
</form> </div>
</div> <div class="control-group">
<label class="control-label" for="inputUnit">单位</label>
<div class="controls">
<input type="text" id="inputUnit" placeholder="Unit" name="unit" class="input-xxlarge">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputProject">项目</label>
<div class="controls">
<input type="text" id="inputProject" placeholder="Project" name="project" class="input-xxlarge">
</div>
</div>
<div class="control-group">
<input type="hidden" name="search" value="1" />
<button type="submit" class="btn">搜索</button>
</div>
</form>
</div>
</div> </div>

View File

@ -1,7 +1,6 @@
<ul class="nav nav-pills nav-stacked well"> <ul class="nav nav-pills nav-stacked well">
<span class="label"><h4>用户管理</h4></span> <span class="label"><h4>用户管理</h4></span>
<li><a href="/admin/user/">用户管理首页</a></li> <li><a href="/admin/user/">用户管理首页</a></li>
<li><a href="/admin/user/local">本地账户</a></li>
<li><a href="/admin/user/adminlist">管理员列表</a></li> <li><a href="/admin/user/adminlist">管理员列表</a></li>
<li><a href="/admin/user/list">查看所有账户</a></li> <li><a href="/admin/user/list">查看所有账户</a></li>
<li><a href="/admin/user/group">用户组管理</a></li> <li><a href="/admin/user/group">用户组管理</a></li>

View File

@ -7,76 +7,70 @@
$this->breadcrumb('<a href="/admin/user">用户管理</a>'); $this->breadcrumb('<a href="/admin/user">用户管理</a>');
$this->breadcrumb()->setSeparator(' > '); $this->breadcrumb()->setSeparator(' > ');
?> ?>
<style>
table thead tr th {background:#EBF2F6;color:#444;}
.high{background:#444;color:#FFF;}
</style>
<div class="row-fluid"> <div class="row-fluid">
<div class="span3"> <div class="span3">
<div id="leftPanel"><?= $this->partial('user/left.phtml'); ?></div> <?= $this->partial('user/left.phtml'); ?>
</div> </div>
<div class="span9">
<div class="span9"> <h3>用户列表</h3>
<?php if ($this->msg or $this->messages) :?> <hr />
<div id="message"> <?php if ($this->msg or $this->messages) :?>
<?php if ($this->msg) : ?> <div class="alert alert-success">
<p><?php echo $this->msg; ?></p> <button type="button" class="close" data-dismiss="alert">&times;</button>
<?php endif; if ($this->messages): foreach($this->messages as $msg): ?> <?php if ($this->msg) : ?>
<p><?php echo $msg; ?></p> <?php echo $this->msg; ?>
<?php endforeach;endif; ?> <?php endif; if ($this->messages): foreach($this->messages as $msg): ?>
</div> <?php echo $msg; ?>
<?php endif; ?> <?php endforeach;endif; ?>
</div>
<?php endif; ?>
<div id="rightPanel">
<h3>用户列表</h3> <div class="search form-inline">
<hr /> <form action="/admin/user/search/" method="get">
<div class="search"> <input type="hidden" name="search" value='1' />
<form action="/admin/user/search/" method="get" class="search input-append">
<input type="hidden" name="search" value='1' /> <label>姓名</label><input type="text" name="realname" value="<?php echo $this->realname; ?>" />
<ul class="inline"> <label>单位</label><input type="text" name="unit" value="<?php echo $this->unit; ?>" />
<li><label>姓名</label><input type="text" name="realname" value="<?php echo $this->realname; ?>" class="search-query"/></li> <label>项目</label><input type="text" name="project" value="<?php echo $this->project; ?>" />
<li><label>单位</label><input type="text" name="unit" value="<?php echo $this->unit; ?>" class="search-query"/></li> <button type="submit" value="搜索" class="btn btn-success">搜索</button>
<li><label>项目</label><input type="text" name="project" value="<?php echo $this->project; ?>" class="search-query"/></li>
<li><input type="submit" class="btn" value="搜索" /></li> </form>
</ul> </div><!-- search DIV -->
</form>
</div><!-- search DIV --> <hr />
<table class="table table-bordered table-hover table-condensed"><thead> <table class="table table-hover">
<tr> <thead>
<th>用户名</th> <tr>
<th>电子邮箱</th> <td width='150'>用户名</td>
<th>用户类型</th> <td width='250'>电子邮箱</td>
<th>单位</th> <td width='100'>用户组</td>
<th>真实姓名</th> <td width='200'>单位</td>
<th>操作</th> <td width='100'>真实姓名</td>
</tr> <td width='150'>操作</td>
</thead><!-- table's head --> </tr>
<?php if (count($this->paginator)): ?> </thead><!-- table's head -->
<?php $autoindex=0;?> <?php if (count($this->paginator)): ?>
<?php foreach ($this->paginator as $item): ?> <?php $autoindex=0;?>
<?php $autoindex++;?> <?php foreach ($this->paginator as $item): ?>
<tr> <?php $autoindex++;?>
<td><?= $item['username']?></td> <tr class="<?php if($autoindex%2 == 0) echo 'even'; else echo 'odd'; ?>">
<td><?= $item['email']; ?></td> <td><?= $item['username']?></td>
<td><?= $item['usertype']; ?></td> <td><?= $item['email']; ?></td>
<td><?= $item['unit']; ?></td> <td><?= $item['usertype']; ?></td>
<td><?= $item['realname']; ?></td> <td><?= $item['unit']; ?></td>
<td> <td><?= $item['realname']; ?></td>
<a href='/admin/user/delete/id/<?= $item['id'];?>/uname/<?= $item['username'];?>' onclick="return confirm('确定将此记录删除?')">删除</a> <td>
<a href='/admin/user/show/id/<?= $item['id'];?>'>查看详细</a> <a href='/admin/user/delete/id/<?= $item['id'];?>/uname/<?= $item['username'];?>' onclick="return confirm('确定将此记录删除?')">删除</a>
<a href='/admin/user/fetchpwd/email/<?= $item['email'];?>/id/<?= $item['id'];?>' onclick="return confirm('是否确定为他重置密码?')">重置密码</a> <a href='/admin/user/show/id/<?= $item['id'];?>'>查看详细</a>
<a href='/admin/user/up/id/<?= $item['id'];?>' onclick="return confirm('确定将该用户提升为评审专家?')">提升为评审专家</a> <a href='/admin/user/fetchpwd/email/<?= $item['email'];?>/id/<?= $item['id'];?>' onclick="return confirm('是否确定为他重置密码?')">重置密码</a>
<a href="/admin/user/userauth/uid/<?= $item['id'];?>">编辑权限</a> <a href='/admin/user/up/id/<?= $item['id'];?>' onclick="return confirm('确定将该用户提升为评审专家?')">提升为评审专家</a>
</td> <a href="/admin/user/userauth/uid/<?= $item['id'];?>">编辑权限</a>
</tr> </td>
<?php endforeach; ?> </tr>
<?php endif; ?> <?php endforeach; ?>
</table> <?php endif; ?>
<div class="pagenavi"><?= $this->paginator; ?></div> </table>
</div> <div class="pagenavi"><?= $this->paginator; ?></div>
</div> </div><!-- span9 -->
</div> </div>

View File

@ -2,72 +2,52 @@
$this->headTitle($this->config->title->site); $this->headTitle($this->config->title->site);
$this->headTitle('后台管理'); $this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - '); $this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/admin.css');
$this->breadcrumb('<a href="/">首页</a>'); $this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin/">后台首页</a>'); $this->breadcrumb('<a href="/admin/">后台首页</a>');
$this->breadcrumb('<a href="/admin/user">用户管理</a>'); $this->breadcrumb('<a href="/admin/user">用户管理</a>');
$this->breadcrumb()->setSeparator(' > '); $this->breadcrumb()->setSeparator(' > ');
?> ?>
<div id="leftPanel"> <div class="row-fluid">
<?= $this->partial('user/left.phtml'); ?> <div class="span3">
</div> <?= $this->partial('user/left.phtml'); ?>
</div>
<?php if ($this->msg or $this->messages) :?> <div class="span9">
<div id="message"> <form name="form1" method="post" action="/admin/user/edit">
<?php if ($this->msg) : ?> <table class="table">
<p><?php echo $this->msg; ?></p> <tr><td width="100">ID</td><td width="600"><?= $this->infos['id'];?></td></tr>
<?php endif; if ($this->messages): foreach($this->messages as $msg): ?> <tr><td>用户名</td><td><?= $this->infos['username'];?></td></tr>
<p><?php echo $msg; ?></p> <tr><td>真实姓名</td><td><?= $this->infos['realname'];?></td></tr>
<?php endforeach;endif; ?> <tr><td>电子邮箱</td><td><?= $this->infos['email'];?></td></tr>
</div> <tr><td>注册时间</td><td><?=$this->infos['ts_created'];?></td></tr>
<?php endif; ?> <tr><td>最后登陆时间</td><td><?= $this->infos['ts_last_login'];?></td></tr>
<tr><td>单位</td><td><?= $this->infos['unit'];?></td></tr>
<div id="rightPanel"> <tr><td>地址</td><td><?= $this->infos['address'];?></td></tr>
<form name="form1" method="post" action="/admin/user/edit"> <tr><td>电话</td><td><?= $this->infos['phone'];?></td></tr>
<table> <tr><td>项目</td><td><?= $this->infos['project'];?></td></tr>
<tr><td width="100">ID</td><td width="600"><?= $this->infos['id'];?></td></tr> <tr><td>用户组</td><td>
<tr><td>用户名</td><td><?= $this->infos['username'];?></td></tr> <select name="usertype">
<tr><td>真实姓名</td><td><?= $this->infos['realname'];?></td></tr> <?php foreach($this->usertypes as $k=>$v){ ?>
<tr><td>电子邮箱</td><td><?= $this->infos['email'];?></td></tr> <option value="<?= $v ?>" <?= $this->infos['usertype'] == $v ? 'selected="selected"':"" ?>><?= $k ?></option>
<tr><td>注册时间</td><td><?=$this->infos['ts_created'];?></td></tr> <?php } ?>
<tr><td>最后登陆时间</td><td><?= $this->infos['ts_last_login'];?></td></tr> </select>
<tr><td>单位</td><td><?= $this->infos['unit'];?></td></tr> </td></tr>
<tr><td>地址</td><td><?= $this->infos['address'];?></td></tr> <tr><td>用户密码</td><td><input type='password' name="newpwd" /></td></tr>
<tr><td>电话</td><td><?= $this->infos['phone'];?></td></tr> <tr><td>确认用户密码</td><td><input type='password' name="cfnewpwd" /></td></tr>
<tr><td>项目</td><td><?= $this->infos['project'];?></td></tr> </table>
<tr><td>用户权限</td><td> <input type='hidden' value="<?php echo $this->infos['id'];?>" name='id' />
<select name="usertype"> <input type="submit" value="提交" class="btn btn-primary" />
<?php </form>
<form name="lostpwd" action="/admin/user/fetchpwd">
if ($this->infos['usertype']=='member') <input type="hidden" name="id" value="<?= $this->infos['id'];?>" />
<input type="hidden" name="email" value="<?= $this->infos['email'];?>" />
{ echo " <input type="submit" value="为他执行Eamil重置密码" class="btn btn-default" />
<option value='member' selected='selected'>普通会员</option> </form>
<option value='administrator'>系统管理员</option> <form name="lostpwd" action="/admin/user/delete">
";} <input type="hidden" name="id" value="<?= $this->infos['id'];?>" />
<input type="hidden" name="uname" value="<?= $this->infos['username'];?>" />
else if($this->infos['usertype']=='administrator') <input type="submit" value="删除该用户" class="btn btn-default" />
</form>
{ echo "<option value='administrator' selected='selected'>系统管理员</option> <a href="/admin/user/userauth/uid/<?= $this->infos['id'];?>">编辑权限</a>
<option value='member'>普通会员</option> </div>
";} </div>
?>
</select>
</td></tr>
<tr><td>用户密码</td><td><input type='password' name="newpwd" /></td></tr>
<tr><td>确认用户密码</td><td><input type='password' name="cfnewpwd" /></td></tr>
</table>
<input type='hidden' value="<?php echo $this->infos['id'];?>" name='id' />
<input type="submit" value="提交" />
</form>
<form name="lostpwd" action="/admin/user/fetchpwd">
<input type="hidden" name="id" value="<?= $this->infos['id'];?>" />
<input type="hidden" name="email" value="<?= $this->infos['email'];?>" />
<input type="submit" value="为他执行Eamil重置密码"/>
</form>
<form name="lostpwd" action="/admin/user/delete">
<input type="hidden" name="id" value="<?= $this->infos['id'];?>" />
<input type="hidden" name="uname" value="<?= $this->infos['username'];?>" />
<input type="submit" value="删除该用户"/>
</form>
<a href="/admin/user/userauth/uid/<?= $this->infos['id'];?>">编辑权限</a>

View File

@ -249,206 +249,143 @@ class AccountController extends Zend_Controller_Action
//$this->view->messages = $this->messenger->getMessages(); //$this->view->messages = $this->messenger->getMessages();
} }
function registerAction() function registerAction()
{ {
$form = new RegisterForm(); $request = new \Zend_Controller_Request_Http();
$this->view->form = $form; if($request->isXmlHttpRequest())
{
if ($this->_request->isPost()) { $this->_helper->layout->disableLayout();
$formData = $this->_request->getPost(); $this->_helper->viewRenderer->setNoRender();
if ($form->isValid($formData)) {
$ut = new UsersTable(); $account = new Account();
$u = $ut->createRow(); $data = $account->getParam($this->_request);
$u->username = $form->getValue('username');
$u->password = $form->getValue('password'); $result = $account->register($data);
$u->email=$form->getValue('email');
if ($form->getValue('realname')) $u->realname=$form->getValue('realname'); if(!empty($result))
if ($form->getValue('phone')) $u->phone=$form->getValue('phone'); {
if ($form->getValue('address')) $u->address=$form->getValue('address'); $this->jsonexit($result);
if ($form->getValue('unit')) $u->unit=$form->getValue('unit'); return true;
if ($form->getValue('project')) $u->project=$form->getValue('project'); }
if ($u->save()) {
//发送欢迎邮件 $this->jsonexit(array('error'=>'|o| 服务器掉链子了,请重试'));
$mail=new WestdcMailer($this->view->config->smtp);
$body=file_get_contents($this->view->config->register->email->template); return true;
$body=str_replace("[username]",$formData['username'],$body); }else{
$mail->setBodyText($body); //$this->_helper->layout->disableLayout();
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); }
$mail->addTo($formData['email']);
//中文标题有乱码在1.5版本中尚未解决
//ref: http://framework.zend.com/issues/browse/ZF-2532
$mail->setSubject('欢迎使用中国西部环境与生态数据中心');
$mail->send();
//自动登录系统 $success=false;
$this->login($formData['username'],$formData['password']);
$this->_redirect('/'); $auth = Zend_Auth::getInstance();
} if ($auth->hasIdentity())
} else { $this->_redirect('/');
$form->populate($formData);
} $submit = $this->_getParam('submit');
} if(!empty($submit))
} {
$account = new Account();
$this->view->data = $data = $account->getParam($this->_request);
$result = $account->register($data);
if(!empty($result))
{
if(isset($result['error']))
{
$this->view->place = $result['place'];
$this->view->error = $result['error'];
return true;
}
if(isset($result['success']))
{
$this->_redirect('/');
return true;
}
}else{
$this->view->error = "处理中出现问题";
return true;
}
}
}//用户注册
function loginAction() function loginAction()
{ {
$success=false; $request = new \Zend_Controller_Request_Http();
if($request->isXmlHttpRequest())
{
}
$captcha = new Captcha();
$success=false;
$options = array( $options = array(
'module' => $this->_request->getModuleName(), 'module' => $this->_request->getModuleName(),
'controller' => $this->_request->getControllerName(), 'controller' => $this->_request->getControllerName(),
'action' => $this->_request->getActionName(), 'action' => $this->_request->getActionName(),
); );
$auth = Zend_Auth::getInstance(); $auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) if ($auth->hasIdentity())
{ {
view::Post($this,"您已经登录,无需重复登录",-1); if($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login")
return true; {
$this->_redirect("/");
}else{
$this->_redirect($_SERVER['REQUEST_URI']);
}
} }
$tohref = $this->_request->getParam('href'); $tohref = $this->_request->getParam('href');
if(($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login")) if($_SERVER['REQUEST_URI'] !== "/account/login")
{ {
$this->view->href = $_SERVER['REQUEST_URI']; $this->view->href = $_SERVER['REQUEST_URI'];
} }else{
$this->view->href = "/";
if($tohref == "/account/login")
{
$this->view->href = $tohref = "/";
} }
if(!empty($tohref)) if(!empty($tohref))
{ {
$this->view->href = $tohref; $this->view->href = $tohref;
} }
$captcha = new Captcha();
//登录表单提交 $submit = $this->_getParam("submit");
if(!$this->_getParam('submit')) if(!empty($submit))
{ {
$this->view->captcha = $captcha->setCaptcha(); $data = array(
return false; 'username' => $this->_getParam('username'),
} 'password' => $this->_getParam('password')
);
$url = "http://sanjiangyuan/account/login";
$param = array(
'username' => $this->_getParam('username'),
'password' => $this->_getParam('password'),
'captchaword' => trim($this->_request->getParam('captcha'))
);
$captchaword = $param['captchaword'];
#用户名校验
if(strlen($param['username'])<6)
{
$this->view->error = '用户名不能少于6个字符';
$this->view->captcha = $captcha->setCaptcha();
return true;
}
if(strlen($param['username'])>20)
{
$this->view->error = '用户名不能超过20个字符';
$this->view->captcha = $captcha->setCaptcha();
return true;
}
if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,19}$/",$param['username']))
{
$this->view->error = '用户名只能包含英文字母及数字';
$this->view->captcha = $captcha->setCaptcha();
return true;
}
#密码校验
$match = "/[\"|'|\\\]/i";
if(preg_match($match,$param['password']) )
{
$this->view->error = '密码中包含非法字符,请重新输入';
$this->view->captcha = $captcha->setCaptcha();
return true;
}
if(empty($param['password']))
{
$this->view->error = '请输入密码';
$this->view->captcha = $captcha->setCaptcha();
return true;
}
if(strlen($param['password'])<6)
{
$this->view->error ='密码太短';
$this->view->captcha = $captcha->setCaptcha();
return true;
}
if(strlen($param['password'])>20)
{
$this->view->error ="密码长度不能超过20个字符";
$this->view->captcha = $captcha->setCaptcha();
return true;
}
#验证码校验
if(empty($captchaword)) $account = new Account();
$result = $account->login($data);
if(!empty($result))
{ {
$this->view->error = "请输入验证码"; if(isset($result['error']))
{
$this->view->error = $result['error'];
$this->view->captcha = $captcha->setCaptcha();
return true;
}
if(isset($result['success']))
{
$this->_redirect($this->view->href);
return true;
}
}else{
$this->view->captcha = $captcha->setCaptcha(); $this->view->captcha = $captcha->setCaptcha();
$this->view->error = "处理中出现问题";
return true; return true;
} }
if(!isset($_SESSION['captcha']))
{
$_SESSION['captcha'] = md5(time());
}
if ($captchaword != $_SESSION['captcha']) {
$this->view->captcha = $captcha->setCaptcha();
$this->view->error = "验证码错误";
return true;
}
$encoded_param = json_encode($param,JSON_NUMERIC_CHECK);
$encoded_param = \Helpers\MCrypt::encrypt($encoded_param,"DY7567");
$curl = new Curl();
$curl->port = 80;
$curl->initOptions(array('verifyssl'=>false));
$curl->H = array(
'X-Requested-With: XMLHttpRequest'
);
$data = $curl->request($url,array('data'=>$encoded_param),"POST");
$KEY = \Helpers\MCrypt::decrypt($data['response'],"CH6668");
$cache_data = json_decode($KEY);
if (isset($cache_data -> error))
{
$this->view->error =$cache_data -> error;
return;
}
$Users = new Users();
if(!$Users -> storeNewAuthCredential($cache_data))
{
$this-> view->error ="登录失败,请重新登录。";
return;
}else{
view::Post($this,"登录成功!",$tohref);
} }
$this->view->captcha = $captcha->setCaptcha(); $this->view->captcha = $captcha->setCaptcha();
return true; }//登陆
}
function captchaAction() function captchaAction()

View File

@ -0,0 +1,144 @@
<?php
namespace Users;
use Zend_Acl;
use Zend_Acl_Role;
use Zend_Acl_Resource;
class AclManager extends \Zend_Controller_Plugin_Abstract
{
// default user role if not logged or (or invalid role found)
private $_defaultRole = 'guest';
// the action to dispatch if a user doesn't have sufficient privileges
private $_authController = array(
'module'=>'',
'controller' => 'account',
'action' => 'login'
);
private $_adminRole;
public function __construct(\Zend_Auth $auth)
{
$config = \Zend_Registry::get('config');
$this->_adminRole = $config->auth->identifier;
$this->db=\Zend_Registry::get('db');
$this->auth = $auth;
$this->acl = new Zend_Acl();
// add the different user roles
$this->acl->addRole(new Zend_Acl_Role($this->_defaultRole));
$this->acl->addRole(new Zend_Acl_Role('member'));
$this->acl->addRole(new Zend_Acl_Role($this->_adminRole), 'member');
// add the resources we want to have control over
$this->acl->add(new Zend_Acl_Resource('account'));
$this->acl->add(new Zend_Acl_Resource('data'));
$this->acl->add(new Zend_Acl_Resource('water'));
$this->acl->add(new Zend_Acl_Resource('admin'));
$this->acl->add(new Zend_Acl_Resource('upload'));
$this->acl->add(new Zend_Acl_Resource('author'));
$this->acl->add(new Zend_Acl_Resource('heihe'));
// allow access to everything for all users by default
// except for the account management and administration areas
$this->acl->allow();
$this->acl->deny(null, 'account');
$this->acl->deny(null, 'admin');
$this->acl->deny(null, 'author');
// add an exception so guests can log in or register
// in order to gain privilege
$this->acl->allow('guest', 'account', array('login',
'logout',
'captcha',
'fetchpwd',
'register',
'registercomplete'));
$this->acl->deny('guest','data',array('download','order'));
$this->acl->deny('guest','water',array('download','order'));
$this->acl->deny('guest','heihe',array('submit'));
// allow members access to the account management area
$this->acl->allow('guest','author',array('index'));
$this->acl->allow('member', 'account');
$this->acl->allow('member', 'author');
// allows administrators access to the admin area
$this->acl->allow($this->_adminRole, 'admin');
}
/**
* preDispatch
*
* Before an action is dispatched, check if the current user
* has sufficient privileges. If not, dispatch the default
* action instead
*
* @param Zend_Controller_Request_Abstract $request
*/
public function preDispatch(\Zend_Controller_Request_Abstract $request)
{
$phpSessId = $request->getParam('PHPSESSID');
if (!empty($phpSessId) && session_id() != $phpSessId) {
session_destroy();
session_id($phpSessId);
session_start();
}
// check if a user is logged in and has a valid role,
// otherwise, assign them the default role (guest)
if(!$this->auth->hasIdentity())
{
$mb = new \member();
$mb->db=$this->db;
if($mb->checkcookie())
{
$auth = Zend_Auth::getInstance();
$authAdapter = new Zend_Auth_Adapter_DbTable($this->db);
$authAdapter->setTableName('users')
->setIdentityColumn('username')
->setCredentialColumn('password');
$authAdapter->setIdentity($mb->user)->setCredential($mb->srpwd);
$result = $auth->authenticate($authAdapter);
if ($result->isValid()) {
$data = $authAdapter->getResultRowObject(null,'password');
//头像
include_once("Avatar.php");
$avatar = new Avatar();
$data->avatar = $avatar->Get($data->email,40);
//组ID
include_once("Users.php");
$usr = new Users($this->db);
$data->gid = $usr->getGroup($data->id);
$auth->getStorage()->write($data);
$this->db->query("update users set ts_last_login=now() where username=?",array($mb->user));
}
}
}
if ($this->auth->hasIdentity())
$role = $this->auth->getIdentity()->usertype;
else
$role = $this->_defaultRole;
if (!$this->acl->hasRole($role))
$role = $this->_defaultRole;
// the ACL resource is the requested controller name
$resource = $request->controller;
if ($request->module<>"default") $resource=$request->module;
// the ACL privilege is the requested action name
$privilege = $request->action;
if ($request->module<>"default") $privilege = $request->controller;
// if we haven't explicitly added the resource, check
// the default global permissions
if (!$this->acl->has($resource))
$resource = null;
// access denied - reroute the request to the default action handler
if (!$this->acl->isAllowed($role, $resource, $privilege)) {
$request->setModuleName($this->_authController['module']);
$request->setControllerName($this->_authController['controller']);
$request->setActionName($this->_authController['action']);
}
}
}

View File

@ -26,7 +26,7 @@ class Local extends \Zend_Controller_Plugin_Abstract
$this->db = $db; $this->db = $db;
} }
$this->config = \Zend_Registry::get('6config'); $this->config = \Zend_Registry::get('config');
$this->table = new \Helpers\Table(); $this->table = new \Helpers\Table();

View File

@ -37,6 +37,37 @@ class Users extends \Zend_Controller_Plugin_Abstract
} }
} }
//初始化用户类型
public function initUserType()
{
$this->usertype = array(
'普通会员' => 'member',
$this->config->auth->groupname => $this->config->auth->indentifier
);
}
//获取用户类型
public function getUserType()
{
$this->initUserType();
return $this->usertype;
}
//通过ID获取User信息
public function getUser($id)
{
$sql="select * from users where id=?";
$result=$this->db->query($sql,$id);
$rows = $result->fetch();
return $rows;
}
public function getUserInfo($id)
{
return $this->getUser($id);
}
//通过email地址返回用户信息是否存在 //通过email地址返回用户信息是否存在
public function userExists($email = NULL) public function userExists($email = NULL)
{ {

View File

@ -4,7 +4,7 @@ ini_set('display_errors', 1);
date_default_timezone_set('Asia/Shanghai'); date_default_timezone_set('Asia/Shanghai');
// directory setup and class loading // directory setup and class loading
set_include_path('.' . PATH_SEPARATOR . '../include/' set_include_path('.' . PATH_SEPARATOR . 'F:/library/zf1/library'
. PATH_SEPARATOR . 'D:/library/zf1' . PATH_SEPARATOR . 'D:/library/zf1'
. PATH_SEPARATOR . '../application/models' . PATH_SEPARATOR . '../application/models'
. PATH_SEPARATOR . '../application/module' . PATH_SEPARATOR . '../application/module'
@ -40,7 +40,7 @@ $frontController->setControllerDirectory(array(
'default' => '../application/default/controllers', 'default' => '../application/default/controllers',
'admin' => '../application/admin/controllers')); 'admin' => '../application/admin/controllers'));
$frontController->registerPlugin(new CustomControllerAclManager($auth)); $frontController->registerPlugin(new \Users\AclManager($auth));
Zend_Layout::startMvc(array('layoutPath'=>'../application/layouts')); Zend_Layout::startMvc(array('layoutPath'=>'../application/layouts'));
$router = new Zend_Controller_Router_Rewrite(); $router = new Zend_Controller_Router_Rewrite();
$router->addConfig($config, 'routes'); $router->addConfig($config, 'routes');