新增多用户体系支持,每个用户问卷分离,管理员可以添加,删除用户的功能

This commit is contained in:
KeYuan 2017-07-02 01:09:05 +08:00
parent a61392452b
commit 0e4445d5bf
12 changed files with 551 additions and 14 deletions

View File

@ -153,8 +153,7 @@ public class AccountManager {
//是邮箱账号
return userDao.findUniqueBy("email", loginName);
}else{
// return userDao.findUniqueBy("loginName", loginName);
return null;
return userDao.findUniqueBy("loginName", loginName);
}
}
return null;

View File

@ -527,5 +527,25 @@ public class HibernateDao<T, ID extends Serializable> extends SimpleHibernateDao
page.setResult(result);
return page;
}
public Page<T> findPageByCri(Page<T> pageRequest, List<Criterion> criterions){
Criteria c = createCriteria(criterions);
Page<T> page = new Page<T>(pageRequest);
if (pageRequest.isCountTotal()) {
long totalCount = countCriteriaResult(c);
System.out.println("totalCount:"+totalCount);
page.setTotalItems(totalCount);
pageRequest.setTotalPage(page.getTotalPage());
}
if(pageRequest.isIslastpage()){
pageRequest.setPageNo(pageRequest.getTotalPage());
page.setPageNo(pageRequest.getPageNo());
}
setPageRequestToCriteria(c, pageRequest);
List result = c.list();
page.setResult(result);
return page;
}
}

View File

@ -131,5 +131,7 @@ public interface IHibernateDao<T, ID extends Serializable> extends ISimpleHibern
* @return
*/
public List<Object[]> findList(String hql,Object... values );
public Page<T> findPageByCri(Page<T> page, List<Criterion> criterions);
}

View File

@ -81,8 +81,9 @@ public class ShiroDbRealm extends AuthorizingRealm {
String username = (String) principals.fromRealm(getName()).iterator().next();
// User user = accountManager.findUserByLoginName(username);
User user = accountManager.findUserByLoginNameOrEmail(username);
if (user != null) {
if (user != null && "1".equals(user.getId())) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addRole("admin");
return info;
} else {
return null;

View File

@ -80,4 +80,8 @@ public abstract class BaseServiceImpl<T extends IdEntity, ID extends Serializabl
public Page<T> findPage(Page<T> page, Criterion... criterions) {
return getBaseDao().findPage(page, criterions);
}
public Page<T> findPageByCri(Page<T> page, List<Criterion> criterions) {
return getBaseDao().findPageByCri(page, criterions);
}
}

View File

@ -0,0 +1,107 @@
package com.key.dwsurvey.action;
import com.key.common.base.action.CrudActionSupport;
import com.key.common.base.entity.User;
import com.key.common.utils.RandomUtils;
import com.key.common.utils.web.Struts2Utils;
import com.key.dwsurvey.service.UserManager;
import org.apache.struts2.convention.annotation.*;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Namespaces({@Namespace("/sy/user"),@Namespace("/sy/user/nosm")})
@InterceptorRefs({ @InterceptorRef("paramsPrepareParamsStack") })
@Results({
@Result(name= CrudActionSupport.SUCCESS,location="/WEB-INF/page/content/diaowen-useradmin/list.jsp",type= Struts2Utils.DISPATCHER),
@Result(name= CrudActionSupport.INPUT,location="/WEB-INF/page/content/diaowen-useradmin/input.jsp",type= Struts2Utils.DISPATCHER),
@Result(name= CrudActionSupport.RELOAD,location="/sy/user/user-admin.action",type= Struts2Utils.REDIRECT)
})
@AllowedMethods({"checkLoginNamelUn","checkEmailUn"})
public class UserAdminAction extends CrudActionSupport<User, String> {
protected final static String USER_ROLE="userRole";
@Autowired
private UserManager userManager;
@Override
public String list() throws Exception {
try{
page=userManager.findPage(page,entity);
}catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
@Override
public String input() throws Exception {
HttpServletRequest request= Struts2Utils.getRequest();
return INPUT;
}
@Override
public String save() throws Exception {
HttpServletRequest request= Struts2Utils.getRequest();
userManager.adminSave(entity,null);
return RELOAD;
}
/**
* 账号禁用
*/
@Override
public String delete() throws Exception {
HttpServletResponse response= Struts2Utils.getResponse();
String result="false";
try{
userManager.disUser(id);
result="true";
}catch (Exception e) {
// TODO: handle exception
}
response.getWriter().write(result);
return null;
}
@Override
protected void prepareModel() throws Exception {
entity=userManager.getModel(id);
}
public void prepareExecute() throws Exception {
prepareModel();
}
public void checkLoginNamelUn() throws Exception{
HttpServletRequest request= Struts2Utils.getRequest();
HttpServletResponse response= Struts2Utils.getResponse();
String loginName=request.getParameter("loginName");
User user=userManager.findNameUn(id,loginName);
String result="true";
if(user!=null){
result="false";
}
response.getWriter().write(result);
}
public void checkEmailUn() throws Exception{
HttpServletRequest request= Struts2Utils.getRequest();
HttpServletResponse response= Struts2Utils.getResponse();
String email=request.getParameter("email");
User user=userManager.findEmailUn(id,email);
String result="true";
if(user!=null){
result="false";
}
response.getWriter().write(result);
}
}

View File

@ -8,6 +8,8 @@ public interface UserManager extends BaseService<User, String>{
public void adminSave(User entity, String[] userRoleIds);
public Page<User> findPage(Page<User> page, User entity);
public void disUser(String id);
public User findNameUn(String id, String loginName);
@ -19,5 +21,5 @@ public interface UserManager extends BaseService<User, String>{
public User findByActivationCode(String code);
public void resetUserGroup(String groupId);
}

View File

@ -47,20 +47,25 @@ public class UserManagerImpl extends BaseServiceImpl<User, String> implements Us
entity.setShaPassword(shaPassword);
// entity.setSalt(salt);
}
// List<Role> roles=new ArrayList<Role>();
// if(userRoleIds!=null){
// for (String roleId : userRoleIds) {
// Role role=new Role();
// role.setId(roleId);
// roles.add(role);
// }
// }
// entity.setRoleList(roles);
save(entity);
}
}
public Page<User> findPage(Page<User> page, User entity) {
List<Criterion> criterions=new ArrayList<Criterion>();
Integer status = entity.getStatus();
String loginName = entity.getLoginName();
criterions.add(Restrictions.eq("status", status));
System.out.println("status:"+status);
if(status!=null && !"".equals(status)){
criterions.add(Restrictions.eq("status", status));
}
if(loginName!=null && !"".equals(loginName)){
criterions.add(Restrictions.eq("loginName", loginName));
}
return super.findPageByCri(page, criterions);
}
/**
* 禁用账号
*/

View File

@ -44,6 +44,7 @@
/ic/* = user
/design/*=user
/da/*=user
/sy/*=roles[admin]
</value>
</property>
</bean>

View File

@ -0,0 +1,162 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${ctx }/js/plugs/jquery-ui-1.10.3.custom/css/mycss/jquery-ui-1.10.3.custom.css" rel="stylesheet" type="text/css" />
<title>我的账号</title>
<link href="${ctx}/js/plugs/validate/jquery.validate.css" type="text/css" rel="stylesheet" />
<script src="${ctx}/js/plugs/validate/jquery.validate.js" type="text/javascript"></script>
<script src="${ctx}/js/plugs/validate/messages_cn.js" type="text/javascript"></script>
<script src="${ctx }/js/plugs/validate/jquery.metadata.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#inputForm").validate({
rules:{
loginName:{
required:true,
remote:{
url: "${ctx}/sy/user/user-admin!checkLoginNamelUn.action", //后台处理程序
type: "post", //数据发送方式
data: { //要传递的数据
loginName: function() { return $("input[name='loginName']").val(); },
id:function(){ return $("input[name='id']").val(); }
}
}
},
email:{
required:true,
email:true,
//remote:'${ctx}/sy/yb/yang-ben!checkEmailUn.action'
remote:{
url: "${ctx}/sy/user/user-admin!checkEmailUn.action", //后台处理程序
type: "post", //数据发送方式
data: { //要传递的数据
email: function() { return $("input[name='email']").val(); },
id:function(){ return $("input[name='id']").val(); }
}
}
},
name:{required:true},
pwd:{required:true,minlength:6,maxlength:40},
},
errorPlacement: function(error, element) {
//error.appendTo(element.parent().parent());
element.parent().append(error);
}
});
$("#pwdEdit").click(function(){
var thTd=$(this).parent();
$(this).remove();
thTd.append("<input type=\"password\" name=\"pwd\" value=\"\" id=\"pwd\">");
return false;
});
});
</script>
<style type="text/css">
.ac-input-td input,.ac-input-td select{
padding: 4px! important;
font-size: 14px;
}
.red-color{
color: red;
}
</style>
</head>
<body>
<div style="margin-top: 15px;">
</div>
<div style="clear: both;"></div>
<div id="dwBody" >
<div id="dwBodyContent" class="bodyCenter" style="">
<div id="dwBodyUser">
<div class="surveyCollectMiddle">
<form id="inputForm" action="${ctx }/sy/user/nosm/user-admin!save.action" method="post" >
<input type="hidden" name="id" value="${id }" >
<div class="surveyCollectMiddleContent">
<div style="padding: 25px 45px;overflow: auto;padding-top: 35px;">
<div style="border-bottom: 1px solid #DFDFDF;padding: 5px;color: #666565;">账号信息</div>
<div style="padding: 5px;color:#666565; ">
<table width="100%">
<tr>
<td valign="top" align="left" >
<table class="ac-form-table">
<tr>
<td width="80" align="right"><span class="red-color">*&nbsp;</span>昵称</td>
<td class="ac-input-td"><input type="text" name="name" value="${loginName }" > </td>
</tr>
<tr>
<td width="80" align="right"><span class="red-color">*&nbsp;</span>登录名</td>
<td class="ac-input-td"><input type="text" name="loginName" value="${loginName }" > </td>
</tr>
<tr>
<td width="80" align="right"><span class="red-color">*&nbsp;</span>邮箱</td>
<td class="ac-input-td"><input type="text" name="email" value="${email }" > </td>
</tr>
<c:if test="${empty(id) }">
<tr>
<td width="80" align="right"><span class="red-color">*&nbsp;</span>登录密码</td>
<td class="ac-input-td"><input type="password" name="pwd" value="" id="pwd">
</td>
</tr>
</c:if>
<c:if test="${!empty(id) }">
<tr>
<td width="80" align="right"><span class="red-color">*&nbsp;</span>状态</td>
<td class="ac-input-td">
<input type="radio" name="status" value="1" >可用&nbsp;&nbsp;&nbsp;
<input type="radio" name="status" value="0" >禁用
</td>
</tr>
<tr>
<td width="80" align="right"><span class="red-color">*&nbsp;</span>登录密码</td>
<td class="ac-input-td">
<a href="#" id="pwdEdit">修改</a>
</td>
</tr>
</c:if>
</table>
</td>
</tr>
<!-- <tr>
<td>
<table class="ac-form-table">
<tr>
<td width="80" align="right">地址</td>
<td class="ac-input-td"><input type="text" > </td>
</tr>
</table>
</td>
</tr> -->
<tr>
<td height="50"><input type="submit" value="保存修改" class="sbtn25 sbtn25_1" style="margin-left: 125px;"> </td>
<td class="ac-input-td"> </td>
</tr>
</table>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$("input[name='status'][value='${status}']").prop("checked",true);
</script>
</body>
</html>

View File

@ -0,0 +1,231 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${ctx }/js/plugs/jquery-ui-1.10.3.custom/css/mycss/jquery-ui-1.10.3.custom.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="${ctx }/js/plugs/bootstrap-3.3.0-dist/dist/css/bootstrap.css">
<!-- 可选的Bootstrap主题文件一般不用引入 -->
<!-- <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css"> -->
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<!-- <script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> -->
<script src="${ctx }/js/plugs/bootstrap-3.3.0-dist/dist/js/bootstrap.js"></script>
<!-- <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> -->
<link href="${ctx }/js/plugs/font-awesome-4.2.0/css/font-awesome.css" rel="stylesheet">
<title>用户管理</title>
<script type="text/javascript">
$(document).ready(function(){
$(".checkboxAll").unbind();
$(".checkboxAll").change(function(){
if($(this).prop("checked")){
$(".quItemCheckbox").prop("checked",true);
}else{
$(".quItemCheckbox").prop("checked",false);
}
});
$(".quItemCheckbox").change(function(){
var noCheckeds=$(".quItemCheckbox").not(":checked");
if(noCheckeds[0]){
$(".checkboxAll").prop("checked",false);
}else{
$(".checkboxAll").prop("checked",true);
}
});
});
</script>
<style type="text/css">
.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default{
background: #EFEFEF;
}
.usGroupUl{
list-style: none;
padding: 5px;
}
.usGroupUl li{
list-style: none;
font-size: 14px;
}
.usGroupUl li a{
color: #333;
}
.new-dialog .ui-dialog-buttonset button{
padding: 5px 10px;
}
</style>
</head>
<body>
<input type="hidden" id="id" name="id" value="${survey.id }">
<div style="clear: both;"></div>
<div id="dwBody" style="margin-top: 15px;" >
<div id="dwBodyContent" class="bodyCenter" style="">
<div id="dwBodyUser">
<div class="surveyCollectMiddle">
<div class="surveyCollectMiddleContent">
<div style="padding: 25px 45px;overflow: auto;padding-top: 12px;">
<div style="padding: 5px;color: #666565;letter-spacing: 2px;font-size: 18px;">账号</div>
<div class="contacts_search" style="padding: 5px;color:#666565;margin-top: 15px;" >
<form action="${ctx }/sy/user/user-admin.action" method="post">
<div style="padding-left: 30px;padding-top: 8px;padding-bottom: 8px;">
<span style="font-size: 14px;vertical-align: middle;">状态&nbsp;</span>
<select name="status" style="vertical-align: middle;">
<option value="">不限</option>
<option value="1">可用</option>
<option value="0">禁用</option>
</select>&nbsp;&nbsp;
<span style="font-size: 14px;vertical-align: middle;">用户名&nbsp;</span>
<input type="text" name="loginName" value="${loginName }" class="inputS1"/>&nbsp;&nbsp;
<input type="submit" value="查询" class="sbtn25 sbtn25_1" style="font-size: 16px;"/>
<div style="padding: 5px;color: #666565;text-align: right;float: right;margin-right: 20px;">
<a href="${ctx }/sy/user/user-admin!input.action" class="user-plus active"><i class="fa fa-plus " aria-hidden="true"></i>&nbsp;添加账号</a>
</div>
</div>
</form>
</div>
<div style="margin-top: 15px;">
<div style="padding: 5px;color:#666565; ">
<div style="">
<table class="contacts-table" width="100%" cellpadding="0" cellspacing="0">
<tr>
<th style="text-align: center;" width="30"><!-- <input type="checkbox" class="checkboxAll"> --></th>
<th align="left">登录名</th>
<!-- <th align="left" >邮箱</th> -->
<th align="left" width="200">创建时间</th>
<th align="left" width="200">最后登录时间</th>
<th align="left" width="80">状态</th>
<th align="center" style="text-align: center;" width="160">操作</th>
</tr>
<c:choose>
<c:when test="${page.totalItems > 0}">
<c:forEach items="${page.result }" var="en">
<tr>
<td align="center"><%-- <input type="checkbox" class="quItemCheckbox" value="${en.id }"> --%></td>
<td align="left">${en.loginName }</td>
<%--<td align="left">${en.email }</td>--%>
<td align="left"><fmt:formatDate value="${en.createTime }" pattern="yyyy年MM月dd日 HH:mm"/></td>
<td align="left"><fmt:formatDate value="${en.createTime }" pattern="yyyy年MM月dd日 HH:mm"/></td>
<td align="left">${en.status ne 0 ? '可用':'不可用' }</td>
<td align="center">
<a class="btn btn-default" href="${ctx }/sy/user/nosm/user-admin!input.action?id=${en.id}" title="编辑"data-toggle="tooltip" data-placement="top" ><i class="fa fa-pencil-square-o"></i></a>
<a class="btn btn-default disUser_a" href="${ctx }/sy/user/nosm/user-admin!delete.action?id=${en.id}" title="禁用"data-toggle="tooltip" data-placement="top" ><i class="fa fa-trash-o" aria-hidden="true"></i></a>
</td>
</tr>
</c:forEach>
</c:when>
<c:otherwise>
<tr>
<td colspan="7">
<div style="padding: 60px;font-size: 22px;text-align: center;color: #b1aeae;">还没有数据!</div>
</td>
</tr>
</c:otherwise>
</c:choose>
</table>
<div style="padding-top: 15px;text-align: center;">
<div class="btn-group">
<c:if test="${page.pageNo > 1}">
<a href="${ctx }/sy/user/user-admin.action?page.pageNo=${page.pageNo-1}" class="btn btn-default">&lt;</a>
</c:if>
<c:if test="${page.startpage > 1}">
<a href="${ctx }/sy/user/user-admin.action?page.pageNo=1" class="btn btn-default">1</a>
<c:if test="${page.startpage > 2 }">
<span>...</span>
</c:if>
</c:if>
<c:forEach begin="${page.startpage }" end="${page.endpage }" var="en">
<c:choose>
<c:when test="${page.pageNo eq en }"><a href="${ctx }/sy/user/user-admin.action?page.pageNo=${en }" class="btn btn-default" style="background: #D3DEED;">${en }</a></c:when>
<c:otherwise><a href="${ctx }/sy/user/user-admin.action?page.pageNo=${en}" class="btn btn-default">${en }</a></c:otherwise>
</c:choose>
</c:forEach>
<c:if test="${page.totalPage > (page.endpage)}">
<c:if test="${page.totalPage > (page.endpage+1)}">
<span>...</span>
</c:if>
<a href="${ctx }/sy/user/user-admin.action?page.pageNo=${page.totalPage}" class="btn btn-default">${page.totalPage }</a>
</c:if>
<c:if test="${page.totalPage > page.pageNo}">
<a href="${ctx }/sy/user/user-admin.action?page.pageNo=${page.pageNo+1}" class="btn btn-default">&gt;</a>
</c:if>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(".disUser_a").click(function(){
var thVal=$(this).text();
var th=$(this);
if(confirm("确定要删除吗?")){
var url=$(this).attr("href");
var data="";
$.ajax({
url:url,
data:data,
type:'post',
success:function(msg){
if(msg=="true"){
$(th).parents("tr").remove();
/* if(thVal=="禁用"){
$(th).text("启用");
$(th).parents("tr").find("td:eq(4)").text("不可用");
}else{
$(th).text("禁用");
$(th).parents("tr").find("td:eq(4)").text("可用");
} */
}
}
});
}
//delete
return false;
});
$("select[name='userGroupId']").val("${userGroupId}");
$("select[name='status']").val("${status}");
resizeBodyWidth();
$(".dlcTitleBg").animate({opacity:0.6},0);
$("a").attr("hidefocus",true);
</script>
</body>
</html>

View File

@ -35,7 +35,10 @@
<ul>
<%-- <li><a href="${ctx }/" >首页</a></li> --%>
<li><a href="${ctx }/design/my-survey.action">问卷</a></li>
<shiro:hasRole name="admin" >
<li><a href="${ctx }/sy/user/user-admin.action">用户</a></li>
<li><a href="${ctx }/sy/system/sys-property!input.action">设置</a></li>
</shiro:hasRole>
<li><a href="http://support.diaowen.net/">帮助</a></li>
</ul>
</div>