添加会员管理模块

This commit is contained in:
Li Jianxuan 2014-03-03 09:10:04 +00:00
parent 5eac2e81d0
commit 8657471e73
8 changed files with 540 additions and 165 deletions

View File

@ -1,78 +1,82 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
return array(
'service_manager' => array(
'services' => array(
//'Auth' => new Sookon\Authentication\AuthenticationService(),
),
),
'controllers' => array(
'invokables' => array(
'Admin\Controller\Index' => 'Admin\Controller\IndexController',
'Admin\Controller\Article' => 'Admin\Controller\ArticleController',
'Admin\Controller\Category' => 'Admin\Controller\CategoryController',
'Admin\Controller\Metadata' => 'Admin\Controller\MetadataController',
),
),
'router' => array(
'routes' => array(
'admin' => array(
'type' => 'Segment',
'options' => array(
'route' => '/admin[/:controller[/:action[/:ac][/page/:page][/id/:id]]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'ac' => '[a-zA-Z][a-zA-Z0-9_-]*',
'page' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'module' => 'Admin',
'__NAMESPACE__' => 'Admin\Controller',
'controller' => 'Admin\Controller\Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'wildcard' => array(
'type' => 'Wildcard'
)
)
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'admin' => __DIR__ . '/../view',
),
'template_map' => array(
'layout/admin' => __DIR__ . '/../view/layout/admin.phtml',
'layout/admin/header' => __DIR__ . '/../view/layout/header.phtml',
'layout/admin/pagination' => __DIR__ . '/../view/layout/pagination.phtml',
'layout/admin/article/list' => __DIR__ . '/../view/admin/article/list.phtml',
'layout/admin/article/nav' => __DIR__ . '/../view/admin/article/nav.phtml',
'layout/admin/article/add' => __DIR__ . '/../view/admin/article/add.phtml',
'layout/admin/category/list' => __DIR__ . '/../view/admin/category/list.phtml',
'layout/admin/category/nav' => __DIR__ . '/../view/admin/category/nav.phtml',
'layout/admin/category/add' => __DIR__ . '/../view/admin/category/add.phtml',
'layout/admin/category/moved' => __DIR__ . '/../view/admin/category/moved.phtml',
'layout/admin/metadata/list' => __DIR__ . '/../view/admin/metadata/list.phtml',
'layout/admin/metadata/nav' => __DIR__ . '/../view/admin/metadata/nav.phtml',
),
),
);
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
return array(
'service_manager' => array(
'services' => array(
//'Auth' => new Sookon\Authentication\AuthenticationService(),
),
),
'controllers' => array(
'invokables' => array(
'Admin\Controller\Index' => 'Admin\Controller\IndexController',
'Admin\Controller\Article' => 'Admin\Controller\ArticleController',
'Admin\Controller\Category' => 'Admin\Controller\CategoryController',
'Admin\Controller\Metadata' => 'Admin\Controller\MetadataController',
'Admin\Controller\Users' => 'Admin\Controller\UsersController',
),
),
'router' => array(
'routes' => array(
'admin' => array(
'type' => 'Segment',
'options' => array(
'route' => '/admin[/:controller[/:action[/:ac][/page/:page][/id/:id]]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'ac' => '[a-zA-Z][a-zA-Z0-9_-]*',
'page' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'module' => 'Admin',
'__NAMESPACE__' => 'Admin\Controller',
'controller' => 'Admin\Controller\Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'wildcard' => array(
'type' => 'Wildcard'
)
)
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'admin' => __DIR__ . '/../view',
),
'template_map' => array(
'layout/admin' => __DIR__ . '/../view/layout/admin.phtml',
'layout/admin/header' => __DIR__ . '/../view/layout/header.phtml',
'layout/admin/pagination' => __DIR__ . '/../view/layout/pagination.phtml',
'layout/admin/article/list' => __DIR__ . '/../view/admin/article/list.phtml',
'layout/admin/article/nav' => __DIR__ . '/../view/admin/article/nav.phtml',
'layout/admin/article/add' => __DIR__ . '/../view/admin/article/add.phtml',
'layout/admin/category/list' => __DIR__ . '/../view/admin/category/list.phtml',
'layout/admin/category/nav' => __DIR__ . '/../view/admin/category/nav.phtml',
'layout/admin/category/add' => __DIR__ . '/../view/admin/category/add.phtml',
'layout/admin/category/moved' => __DIR__ . '/../view/admin/category/moved.phtml',
'layout/admin/metadata/list' => __DIR__ . '/../view/admin/metadata/list.phtml',
'layout/admin/metadata/nav' => __DIR__ . '/../view/admin/metadata/nav.phtml',
'layout/admin/users/list' => __DIR__ . '/../view/admin/users/list.phtml',
'layout/admin/users/nav' => __DIR__ . '/../view/admin/users/nav.phtml',
),
),
);

View File

@ -0,0 +1,98 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Admin\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Sookon\Helpers\View as view;
use Sookon\Helpers\Db;
class UsersController extends AbstractActionController
{
public $ViewModel;
function __construct($db = NULL)
{
$this->ViewModel = new ViewModel();
}
public function indexAction()
{
$users = new \Westdc\Member\Member;
$filter = new \Sookon\Search\Filter;
$keyword = isset($_GET['q']) ? $filter->mixedKeyword($_GET['q']):"";
if(!empty($keyword))
{
$this->ViewModel->setVariable('keyword',$keyword);
$users->opt->logic = "OR";
if(!is_numeric($keyword))
{
$users->opt->where = array(
"m.username LIKE '%$keyword%'",
"m.realname LIKE '%$keyword%'",
"m.unit LIKE '%$keyword%'",
"m.project LIKE '%$keyword%'",
"m.email LIKE '%$keyword%'",
"m.project_leader LIKE '%$keyword%'",
"m.project_id LIKE '%$keyword%'",
"m.project_type LIKE '%$keyword%'",
"m.project_title LIKE '%$keyword%'",
"m.address LIKE '%$keyword%'",
"m.phone LIKE '%$keyword%'",
);
}
else
$users->opt->where = array(
"m.id=$keyword",
);
}
view::addPaginator($users->fetchAll(),$this,18);
return $this->ViewModel;
}
public function viewAction()
{
$id = $this->params()->fromRoute('id');
if(empty($id) || !is_numeric($id))
{
return view::Post($this,"参数错误",-1);
}
$users = new \Westdc\Member\Member;
$this->ViewModel->setVariable("data",$users->fetch($id));
return $this->ViewModel;
}
public function editAction()
{
$id = $this->params()->fromRoute('id');
if(empty($id) || !is_numeric($id))
{
return view::Post($this,"参数错误",-1);
}
$ac = $this->params()->fromRoute('ac');
if($ac == "reset")
{
}
}
}

View File

@ -0,0 +1,84 @@
<?php
$user = \Sookon\Helpers\View::User();
?>
<div class="pagebody">
<div class="col-lg-10 col-md-8 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
<span class="pull-right"></span>
<h3 class="panel-title">所有记录</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-4">
<form method="get">
<div class="input-group">
<input type="text" class="form-control" name="q" value="<?= !empty($this->keyword) ? $this->keyword : ""?>">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">搜索</button>
</span>
</div><!-- /input-group -->
</form>
</div>
<div class="col-lg-8">
<a href="<?php echo $this->url('admin',array('controller'=>'users','action'=>'index','ac'=>'list')) ?>" class="btn btn-success">所有用户</a>
<a href="<?php echo $this->url('admin',array('controller'=>'users','action'=>'index','ac'=>'admin')) ?>" class="btn btn-success">管理员</a>
</div>
</div>
<?php if(!empty($this->paginator)) { ?>
<table class="table table-striped">
<thead>
<tr>
<th>id</th>
<th>用户名</th>
<th>姓名</th>
<th>单位</th>
<th>Email</th>
<th>添加时间</th>
<th>操作</th>
</tr>
</thead>
<?php foreach($this->paginator as $v) { ?>
<tr>
<td><?= $v['id'] ?></td>
<td><?= $v['username'] ?></td>
<td><?= $v['realname'] ?></td>
<td><?= $v['unit'] ?></td>
<td><?= $v['email'] ?></td>
<td><?= date("Y-m-d H:i",strtotime($v['ts_created'])) ?></td>
<td>
<a href="<?= $this->url('admin',array('controller'=>'users','action'=>'view','ac'=>'detail','id'=>$v['id'])) ?>">
<span class="glyphicon glyphicon-eye-open"></span>
</a>
<a href="<?= $this->url('admin',array('controller'=>'users','action'=>'edit','ac'=>'reset','id'=>$v['id'])) ?>"
onclick="return confirm('是否确定重置他的密码?')"
title="重置密码">
<span class="glyphicon glyphicon-retweet"></span>
</a>
</td>
</tr>
<?php } ?>
</table>
<?php }else{ ?>
暂无信息
<?php } ?>
</div><!-- panel-body -->
<?php if(!empty($this->paginator)) { ?>
<div class="panel-footer">
<?= $this->paginator; ?>
</div>
<?php } ?>
</div>
</div><!-- col-lg-8 -->
<div class="col-lg-2 col-md-4 col-sm-12">
<?= $this->partial("layout/admin/users/nav") ?>
</div><!-- col-lg-4 -->
</div>

View File

@ -0,0 +1,6 @@
<ul class="list-group">
<li class="list-group-item list-group-headline">
<h4>用户管理</h4>
</li>
<a class="list-group-item" href="<?php echo $this->url('admin',array('controller'=>'users','action'=>'index','ac'=>'list')) ?>">浏览所有</a>
</ul>

View File

@ -0,0 +1,66 @@
<?php
$user = \Sookon\Helpers\View::User();
?>
<div class="pagebody">
<div class="col-lg-10 col-md-8 col-sm-12">
<h3><?= $this->data['username'] ?> <small><?= $this->data['realname'] ?></small></h3>
<dl class="dl-horizontal">
<dt>ID</dt>
<dd><?= $this->data['id'] ?></dd>
<dt>用户名</dt>
<dd><?= $this->data['username'] ?></dd>
<dt>真实姓名</dt>
<dd><?= $this->data['realname'] ?></dd>
<dt>Email</dt>
<dd><?= $this->data['email'] ?></dd>
<dt>单位</dt>
<dd><?= $this->data['unit'] ?></dd>
<dt>地址</dt>
<dd><?= $this->data['address'] ?></dd>
<dt>电话</dt>
<dd><?= $this->data['phone'] ?></dd>
<dt>邮编</dt>
<dd><?= $this->data['postcode'] ?></dd>
<dt>项目名称</dt>
<dd><?= $this->data['project_title'] ?></dd>
<dt>项目编号</dt>
<dd><?= $this->data['project_id'] ?></dd>
<dt>项目类型</dt>
<dd><?= $this->data['project_type'] ?></dd>
<dt>项目</dt>
<dd><?= $this->data['project'] ?></dd>
<dt>项目负责人</dt>
<dd><?= $this->data['project_leader'] ?></dd>
<dt>注册时间</dt>
<dd><?= $this->data['ts_created'] ?></dd>
<dt>最后登录</dt>
<dd><?= $this->data['ts_last_login'] ?></dd>
</dl>
</div><!-- col-lg-8 -->
<div class="col-lg-2 col-md-4 col-sm-12">
<?= $this->partial("layout/admin/users/nav") ?>
</div><!-- col-lg-4 -->
</div>

View File

@ -27,9 +27,8 @@
<li class="dropdown" id="collapseSys">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-wrench"></i> 系统管理<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="<?= $this->url('admin',array('controller'=>'users','action'=>'files')) ?>">用户管理</a></li>
<li><a href="<?= $this->url('admin',array('controller'=>'users','action'=>'index','ac'=>'list')) ?>">用户管理</a></li>
<li><a href="<?= $this->url('admin',array('controller'=>'users','action'=>'config')) ?>">邮件模板</a></li>
</ul>
</li>
</ul>

View File

@ -1,86 +1,87 @@
<?php
namespace Sookon\Authentication;
use Zend\Permissions\Acl\Acl;
use Zend\Permissions\Acl\Resource\GenericResource as Resource;
use Sookon\Helpers\View as view;
class AclResource
{
public $acl;
public $config = array(
'Admin\Controller\Index',
'Admin\Controller\Article',
'Admin\Controller\Category',
'Admin\Controller\Metadata',
//index
'Application\Controller\Index',
//account
'Application\Controller\Account' => array(
'login',
'logout',
'register',
'forgotpassword',
'getpassword',
'captcha',
'index'
),
//service
'Application\Controller\Service' => array(
'upload',
'delatt',
'thumb',
'bigthumb'
),
'Article\Controller\Article' => array(
'index',
'view'
),
'Article\Controller\Category' => array(
'index',
'list'
),
'Metadata\Controller\Index',
);
function __construct(Acl &$acl)
{
$this->acl = $acl;
$this->loadResource();
$acl = $this->acl;
}
public function loadResource()
{
foreach($this->config as $index => $resource)
{
if(!is_array($resource))
{
$this->acl->addResource(new Resource($resource));
continue;
}
$this->acl->addResource(new Resource($index));
foreach($resource as $action)
{
if($this->acl->hasResource($action))
{
continue;
}
$this->acl->addResource(new Resource($action),$index);
}
}
}
<?php
namespace Sookon\Authentication;
use Zend\Permissions\Acl\Acl;
use Zend\Permissions\Acl\Resource\GenericResource as Resource;
use Sookon\Helpers\View as view;
class AclResource
{
public $acl;
public $config = array(
'Admin\Controller\Index',
'Admin\Controller\Article',
'Admin\Controller\Category',
'Admin\Controller\Metadata',
'Admin\Controller\Users',
//index
'Application\Controller\Index',
//account
'Application\Controller\Account' => array(
'login',
'logout',
'register',
'forgotpassword',
'getpassword',
'captcha',
'index'
),
//service
'Application\Controller\Service' => array(
'upload',
'delatt',
'thumb',
'bigthumb'
),
'Article\Controller\Article' => array(
'index',
'view'
),
'Article\Controller\Category' => array(
'index',
'list'
),
'Metadata\Controller\Index',
);
function __construct(Acl &$acl)
{
$this->acl = $acl;
$this->loadResource();
$acl = $this->acl;
}
public function loadResource()
{
foreach($this->config as $index => $resource)
{
if(!is_array($resource))
{
$this->acl->addResource(new Resource($resource));
continue;
}
$this->acl->addResource(new Resource($index));
foreach($resource as $action)
{
if($this->acl->hasResource($action))
{
continue;
}
$this->acl->addResource(new Resource($action),$index);
}
}
}
}

117
vendor/Westdc/Member/Member.php vendored Normal file
View File

@ -0,0 +1,117 @@
<?php
namespace Westdc\Member;
use Sookon\Helpers\View as view;
use Sookon\Helpers\Dbh as dbh;
use Sookon\Helpers\Pdo;
use Sookon\Helpers\Config;
use Sookon\Helpers\Table;
use Zend\Http\PhpEnvironment\Request;
class Member
{
private $db; //传入PDO对象
private $config; //站点设置
private $table;
public $opt;
protected $events = NULL;
function __construct()
{
$this->db = new Pdo;
$this->config = Config::get();
$this->table = new Table;
$this->opt = new \stdClass();
$this->opt->sort = "DESC";
$this->opt->logic = "AND";
}
public function fetchAll()
{
$wheresql = array();
if(isset($this->opt->where) && !empty($this->opt->where))
$wheresql = array_merge($wheresql,$this->opt->where);
if(count($wheresql)>0)
{
$wheresql = " WHERE \r\n ".join($wheresql," ".$this->opt->logic." \r\n ");
}else{
$wheresql = '';
}
if(!empty($this->opt->order))
{
$order = $this->opt->order;
}else{
$order = "m.id";
}
$sql = "SELECT
m.*
FROM {$this->table->member} m
$wheresql
ORDER BY $order {$this->opt->sort}";
if(!empty($this->opt->start))
{
$sql .= " START {$this->opt->start} ";
}
if(!empty($this->opt->limit)){
$sql .= " LIMIT {$this->opt->limit} ";
}
$rs = $this->db->query($sql);
return $rs->fetchAll();
}
public function fetch($id)
{
if(is_numeric($id))
{
$sql = "SELECT * FROM {$this->table->member} WHERE id=$id";
}else if(\Sookon\Helpers\Uuid::test($id)){
$sql = "SELECT * FROM {$this->table->member} WHERE uuid='$id'";
}else{
return false;
}
$rs = $this->db->query($sql);
return $rs->fetch();
}
public function resetPassword($id)
{
$user = $this->fetch($id);
if(empty($user))
{
return "参数错误";
}
$activetion = uniqid();
$sql = "UPDATE {$this->table->member} SET activation='$activetion' WHERE id=$id";
$state = $this->db->exec($sql);
if($state)
{
$data = array(
'user' => empty($user['realname']) ? $user['username'] : $user['realname'],
'username' => $user['username'],
'url' => view::getHostLink()."/account/fetchpwd/".$username."/".$activetion
);
}else{
return false;
}
}
}