新增个人资料更新,优化shiro配置代码
This commit is contained in:
parent
b902d6b63b
commit
29ee1d510f
|
@ -22,7 +22,7 @@ import com.github.pagehelper.Page;
|
|||
import com.github.pagehelper.PageHelper;
|
||||
import com.len.base.BaseController;
|
||||
import com.len.base.CurrentUser;
|
||||
import com.len.core.shiro.ShiroUtil;
|
||||
import com.len.core.shiro.Principal;
|
||||
import com.len.entity.BaseTask;
|
||||
import com.len.entity.LeaveOpinion;
|
||||
import com.len.entity.SysRoleUser;
|
||||
|
@ -31,17 +31,6 @@ import com.len.exception.MyException;
|
|||
import com.len.service.RoleUserService;
|
||||
import com.len.service.UserLeaveService;
|
||||
import com.len.util.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.activiti.bpmn.model.BpmnModel;
|
||||
import org.activiti.engine.*;
|
||||
import org.activiti.engine.history.HistoricActivityInstance;
|
||||
|
@ -56,20 +45,24 @@ import org.activiti.engine.impl.pvm.process.ActivityImpl;
|
|||
import org.activiti.engine.runtime.ProcessInstance;
|
||||
import org.activiti.engine.task.Task;
|
||||
import org.activiti.image.HMProcessDiagramGenerator;
|
||||
import org.activiti.image.ProcessDiagramGenerator;
|
||||
import org.activiti.image.impl.DefaultProcessDiagramGenerator;
|
||||
import org.activiti.spring.ProcessEngineFactoryBean;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhuxiaomeng
|
||||
* @date 2018/1/21.
|
||||
|
@ -167,7 +160,7 @@ public class UserLeaveController extends BaseController {
|
|||
Map<String, Object> variables = taskService.getVariables(task.getId());
|
||||
Object o = variables.get(leaveOpinionList);
|
||||
if (o != null) {
|
||||
/*获取历史审核信息*/
|
||||
/*获取历史审核信息*/
|
||||
leaveList = (List<LeaveOpinion>) o;
|
||||
}
|
||||
} else {
|
||||
|
@ -245,17 +238,14 @@ public class UserLeaveController extends BaseController {
|
|||
userLeave.setProcessInstanceId("2018");//模拟数据
|
||||
leaveService.insertSelective(userLeave);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
userLeave.setUrlpath("/leave/readOnlyLeave/"+userLeave.getId());
|
||||
map.put("baseTask",(BaseTask) userLeave);
|
||||
userLeave.setUrlpath("/leave/readOnlyLeave/" + userLeave.getId());
|
||||
map.put("baseTask", userLeave);
|
||||
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process_leave", map);
|
||||
userLeave.setProcessInstanceId(processInstance.getId());
|
||||
UserLeave userLeave1 = leaveService.selectByPrimaryKey(userLeave.getId());
|
||||
BeanUtil.copyNotNullBean(userLeave, userLeave1);
|
||||
userLeave1.setUrlpath("/leave/readOnlyLeave/"+userLeave.getId());
|
||||
userLeave1.setUrlpath("/leave/readOnlyLeave/" + userLeave.getId());
|
||||
leaveService.updateByPrimaryKeySelective(userLeave1);
|
||||
if (processInstance == null) {
|
||||
return JsonUtil.error("未识别key");
|
||||
}
|
||||
j.setMsg("请假申请成功");
|
||||
return j;
|
||||
}
|
||||
|
@ -283,13 +273,12 @@ public class UserLeaveController extends BaseController {
|
|||
sysRoleUser.setUserId(user.getId());
|
||||
List<SysRoleUser> userRoles = roleUserService.selectByCondition(sysRoleUser);
|
||||
List<String> roleString = new ArrayList<String>();
|
||||
for(SysRoleUser sru:userRoles)
|
||||
{
|
||||
for (SysRoleUser sru : userRoles) {
|
||||
roleString.add(sru.getRoleId());
|
||||
}
|
||||
List<Task> taskList = taskService.createTaskQuery().taskCandidateUser(user.getId()).list();
|
||||
List<Task> assigneeList =taskService.createTaskQuery().taskAssignee(user.getId()).list();
|
||||
List<Task> candidateGroup =taskService.createTaskQuery().taskCandidateGroupIn(roleString).list();
|
||||
List<Task> assigneeList = taskService.createTaskQuery().taskAssignee(user.getId()).list();
|
||||
List<Task> candidateGroup = taskService.createTaskQuery().taskCandidateGroupIn(roleString).list();
|
||||
taskList.addAll(assigneeList);
|
||||
taskList.addAll(candidateGroup);
|
||||
List<com.len.entity.Task> tasks = new ArrayList<>();
|
||||
|
@ -302,8 +291,7 @@ public class UserLeaveController extends BaseController {
|
|||
for (Task task1 : taskList) {
|
||||
objectMap = new HashMap<>();
|
||||
String taskId = task1.getId();
|
||||
if(taskSet.contains(taskId))
|
||||
{
|
||||
if (taskSet.contains(taskId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -315,18 +303,14 @@ public class UserLeaveController extends BaseController {
|
|||
taskEntity.setReason(userLeave.getReason());
|
||||
taskEntity.setUrlpath(userLeave.getUrlpath());
|
||||
/**如果是自己*/
|
||||
if (user.getId().equals(userLeave.getUserId()) ) {
|
||||
if( map.get("flag")!=null)
|
||||
{
|
||||
if(!(boolean) map.get("flag"))
|
||||
{
|
||||
if (user.getId().equals(userLeave.getUserId())) {
|
||||
if (map.get("flag") != null) {
|
||||
if (!(boolean) map.get("flag")) {
|
||||
objectMap.put("flag", true);
|
||||
}else
|
||||
{
|
||||
} else {
|
||||
objectMap.put("flag", false);
|
||||
}
|
||||
}else
|
||||
{
|
||||
} else {
|
||||
objectMap.put("flag", true);
|
||||
}
|
||||
} else {
|
||||
|
@ -354,7 +338,7 @@ public class UserLeaveController extends BaseController {
|
|||
public JsonUtil complete(LeaveOpinion op, HttpServletRequest request) {
|
||||
Map<String, Object> variables = taskService.getVariables(op.getTaskId());
|
||||
|
||||
CurrentUser user = ShiroUtil.getCurrentUse();
|
||||
CurrentUser user = Principal.getCurrentUse();
|
||||
op.setCreateTime(new Date());
|
||||
op.setOpId(user.getId());
|
||||
op.setOpName(user.getRealName());
|
||||
|
@ -364,17 +348,13 @@ public class UserLeaveController extends BaseController {
|
|||
|
||||
//判断节点是否已经拒绝过一次了
|
||||
Object needend = variables.get("needend");
|
||||
if(needend!=null && (boolean ) needend && (!op.isFlag()) )
|
||||
{
|
||||
map.put("needfinish",-1); //结束
|
||||
}else
|
||||
{
|
||||
if(op.isFlag())
|
||||
{
|
||||
map.put("needfinish",1);//通过下一个节点
|
||||
}else
|
||||
{
|
||||
map.put("needfinish",0);//不通过
|
||||
if (needend != null && (boolean) needend && (!op.isFlag())) {
|
||||
map.put("needfinish", -1); //结束
|
||||
} else {
|
||||
if (op.isFlag()) {
|
||||
map.put("needfinish", 1);//通过下一个节点
|
||||
} else {
|
||||
map.put("needfinish", 0);//不通过
|
||||
}
|
||||
}
|
||||
//审批信息叠加
|
||||
|
@ -396,6 +376,7 @@ public class UserLeaveController extends BaseController {
|
|||
/**
|
||||
* 追踪图片成图
|
||||
* 增加历史流程
|
||||
*
|
||||
* @param request
|
||||
* @param resp
|
||||
* @param processInstanceId
|
||||
|
@ -404,14 +385,12 @@ public class UserLeaveController extends BaseController {
|
|||
@GetMapping("getProcImage")
|
||||
public void getProcImage(HttpServletRequest request, HttpServletResponse resp, String processInstanceId)
|
||||
throws IOException {
|
||||
InputStream imageStream = generateStream(request,resp,processInstanceId,true);
|
||||
if(imageStream==null)
|
||||
{
|
||||
InputStream imageStream = generateStream(request, resp, processInstanceId, true);
|
||||
if (imageStream == null) {
|
||||
return;
|
||||
}
|
||||
InputStream imageNoCurrentStream = generateStream(request,resp,processInstanceId,false);
|
||||
if(imageNoCurrentStream==null)
|
||||
{
|
||||
InputStream imageNoCurrentStream = generateStream(request, resp, processInstanceId, false);
|
||||
if (imageNoCurrentStream == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -450,35 +429,29 @@ public class UserLeaveController extends BaseController {
|
|||
throws IOException {
|
||||
JSONObject result = new JSONObject();
|
||||
JSONArray shineProImages = new JSONArray();
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
InputStream imageStream = generateStream(request,resp,processInstanceId,true);
|
||||
if(imageStream!=null)
|
||||
{
|
||||
String imageCurrentNode = Base64Utils.ioToBase64(imageStream);
|
||||
if(StringUtils.isNotBlank(imageCurrentNode))
|
||||
{
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
InputStream imageStream = generateStream(request, resp, processInstanceId, true);
|
||||
if (imageStream != null) {
|
||||
String imageCurrentNode = Base64Utils.ioToBase64(imageStream);
|
||||
if (StringUtils.isNotBlank(imageCurrentNode)) {
|
||||
shineProImages.add(imageCurrentNode);
|
||||
}
|
||||
}
|
||||
InputStream imageNoCurrentStream = generateStream(request,resp,processInstanceId,false);
|
||||
if(imageNoCurrentStream!=null)
|
||||
{
|
||||
String imageNoCurrentNode = Base64Utils.ioToBase64(imageNoCurrentStream);
|
||||
if(StringUtils.isNotBlank(imageNoCurrentNode))
|
||||
{
|
||||
InputStream imageNoCurrentStream = generateStream(request, resp, processInstanceId, false);
|
||||
if (imageNoCurrentStream != null) {
|
||||
String imageNoCurrentNode = Base64Utils.ioToBase64(imageNoCurrentStream);
|
||||
if (StringUtils.isNotBlank(imageNoCurrentNode)) {
|
||||
shineProImages.add(imageNoCurrentNode);
|
||||
}
|
||||
}
|
||||
result.put("id",UUID.randomUUID().toString());
|
||||
result.put("errorNo",0);
|
||||
result.put("images",shineProImages);
|
||||
result.put("id", UUID.randomUUID().toString());
|
||||
result.put("errorNo", 0);
|
||||
result.put("images", shineProImages);
|
||||
return result.toJSONString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public InputStream generateStream(HttpServletRequest request, HttpServletResponse resp, String processInstanceId,boolean needCurrent)
|
||||
{
|
||||
public InputStream generateStream(HttpServletRequest request, HttpServletResponse resp, String processInstanceId, boolean needCurrent) {
|
||||
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
|
||||
HistoricProcessInstance historicProcessInstance =
|
||||
historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
|
||||
|
@ -488,26 +461,26 @@ public class UserLeaveController extends BaseController {
|
|||
List<HistoricActivityInstance> historicActivityInstanceList = new ArrayList<>();
|
||||
if (processInstance != null) {
|
||||
processDefinitionId = processInstance.getProcessDefinitionId();
|
||||
if(needCurrent)
|
||||
{
|
||||
if (needCurrent) {
|
||||
currentActivityIdList = this.runtimeService.getActiveActivityIds(processInstance.getId());
|
||||
}
|
||||
} if (historicProcessInstance != null) {
|
||||
processDefinitionId = historicProcessInstance.getProcessDefinitionId();
|
||||
historicActivityInstanceList =
|
||||
historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).orderByHistoricActivityInstanceId().asc().list();
|
||||
for (HistoricActivityInstance activityInstance : historicActivityInstanceList) {
|
||||
executedActivityIdList.add(activityInstance.getActivityId());
|
||||
}
|
||||
}
|
||||
if (historicProcessInstance != null) {
|
||||
processDefinitionId = historicProcessInstance.getProcessDefinitionId();
|
||||
historicActivityInstanceList =
|
||||
historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).orderByHistoricActivityInstanceId().asc().list();
|
||||
for (HistoricActivityInstance activityInstance : historicActivityInstanceList) {
|
||||
executedActivityIdList.add(activityInstance.getActivityId());
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(processDefinitionId) || executedActivityIdList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//高亮线路id集合
|
||||
ProcessDefinitionEntity definitionEntity = (ProcessDefinitionEntity)repositoryService.getProcessDefinition(processDefinitionId);
|
||||
List<String> highLightedFlows = getHighLightedFlows(definitionEntity,historicActivityInstanceList);
|
||||
ProcessDefinitionEntity definitionEntity = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processDefinitionId);
|
||||
List<String> highLightedFlows = getHighLightedFlows(definitionEntity, historicActivityInstanceList);
|
||||
|
||||
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
|
||||
//List<String> activeActivityIds = runtimeService.getActiveActivityIds(processInstanceId);
|
||||
|
@ -518,17 +491,18 @@ public class UserLeaveController extends BaseController {
|
|||
|
||||
InputStream imageStream = diagramGenerator.generateDiagram(
|
||||
bpmnModel, "png",
|
||||
executedActivityIdList,highLightedFlows,
|
||||
executedActivityIdList, highLightedFlows,
|
||||
processEngine.getProcessEngineConfiguration().getActivityFontName(),
|
||||
processEngine.getProcessEngineConfiguration().getLabelFontName(),
|
||||
"宋体",
|
||||
null, 1.0,currentActivityIdList);
|
||||
null, 1.0, currentActivityIdList);
|
||||
|
||||
return imageStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取需要高亮的线
|
||||
*
|
||||
* @param processDefinitionEntity
|
||||
* @param historicActivityInstances
|
||||
* @return
|
||||
|
|
|
@ -43,9 +43,9 @@
|
|||
<div class="layui-col-md12">
|
||||
<div class="layui-btn-group">
|
||||
<@shiro.hasPermission name="control:del">
|
||||
<button class="layui-btn layui-btn-normal" id="processGroup" data-type="assignee">
|
||||
<#-- <button class="layui-btn layui-btn-normal" id="processGroup" data-type="assignee">
|
||||
<i class="layui-icon"></i>节点处理人设置
|
||||
</button>
|
||||
</button>-->
|
||||
</@shiro.hasPermission>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -131,7 +131,7 @@
|
|||
}
|
||||
});
|
||||
}
|
||||
,assignee:function(){
|
||||
/*,assignee:function(){
|
||||
var checkStatus = table.checkStatus('actList')
|
||||
, data = checkStatus.data;
|
||||
if (data.length !=1) {
|
||||
|
@ -139,7 +139,7 @@
|
|||
return false;
|
||||
}
|
||||
assignee(data[0].id,data[0].deploymentId);
|
||||
}
|
||||
}*/
|
||||
,reload:function(){
|
||||
$('#deploymentId').val('');
|
||||
$('#name').val('');
|
||||
|
@ -194,7 +194,7 @@
|
|||
* 流程绑定节点
|
||||
* @param id
|
||||
*/
|
||||
function assignee(id,deploymentId){
|
||||
/* function assignee(id,deploymentId){
|
||||
var index =
|
||||
layer.open({
|
||||
id: 'assignee',
|
||||
|
@ -208,7 +208,7 @@
|
|||
content: 'goAssignee/'+deploymentId
|
||||
});
|
||||
layer.full(index);
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
</script>
|
||||
|
|
|
@ -3,11 +3,8 @@ package com.len.core;
|
|||
import com.len.base.CurrentMenu;
|
||||
import com.len.base.CurrentRole;
|
||||
import com.len.base.CurrentUser;
|
||||
import com.len.core.shiro.ShiroUtil;
|
||||
import com.len.core.shiro.Principal;
|
||||
import com.len.entity.SysUser;
|
||||
import com.len.service.MenuService;
|
||||
import com.len.service.RoleMenuService;
|
||||
import com.len.service.RoleUserService;
|
||||
import com.len.service.SysUserService;
|
||||
import com.len.util.JWTUtil;
|
||||
import com.len.util.JwtToken;
|
||||
|
@ -46,10 +43,10 @@ public class BlogRealm extends AuthorizingRealm {
|
|||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
|
||||
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
|
||||
String name = (String) principalCollection.getPrimaryPrincipal();
|
||||
JWTUtil.getUsername(name);
|
||||
CurrentUser user = (CurrentUser) principalCollection.getPrimaryPrincipal();
|
||||
JWTUtil.getUsername(user.getUsername());
|
||||
//根据用户获取角色 根据角色获取所有按钮权限
|
||||
CurrentUser cUser = (CurrentUser) ShiroUtil.getSession().getAttribute("curentUser");
|
||||
CurrentUser cUser = (CurrentUser) Principal.getSession().getAttribute("currentPrincipal");
|
||||
for (CurrentRole cRole : cUser.getCurrentRoleList()) {
|
||||
info.addRole(cRole.getId());
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ public abstract class BaseServiceImpl<T, E extends Serializable> implements Base
|
|||
* @return
|
||||
*/
|
||||
public T addValue(T record, boolean flag) {
|
||||
CurrentUser currentUser = (CurrentUser) SecurityUtils.getSubject().getSession().getAttribute("curentUser");
|
||||
CurrentUser currentUser = (CurrentUser) SecurityUtils.getSubject().getSession().getAttribute("currentPrincipal");
|
||||
//统一处理公共字段
|
||||
Class<?> clazz = record.getClass();
|
||||
String operator, operateDate;
|
||||
|
|
|
@ -20,7 +20,7 @@ public class CommonUtil {
|
|||
public static CurrentUser getUser() {
|
||||
org.apache.shiro.subject.Subject subject = SecurityUtils.getSubject();
|
||||
Session session = subject.getSession();
|
||||
return (CurrentUser) session.getAttribute("curentUser");
|
||||
return (CurrentUser) session.getAttribute("currentPrincipal");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.len.controller;
|
|||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.len.core.annotation.Log;
|
||||
import com.len.core.shiro.ShiroUtil;
|
||||
import com.len.core.shiro.Principal;
|
||||
import com.len.entity.SysMenu;
|
||||
import com.len.entity.SysUser;
|
||||
import com.len.service.MenuService;
|
||||
|
@ -89,12 +89,12 @@ public class LoginController {
|
|||
}
|
||||
CustomUsernamePasswordToken token = new CustomUsernamePasswordToken(user.getUsername().trim(),
|
||||
user.getPassword(), "UserLogin");
|
||||
Subject subject = ShiroUtil.getSubject();
|
||||
Subject subject = Principal.getSubject();
|
||||
String msg = null;
|
||||
try {
|
||||
subject.login(token);
|
||||
if (subject.isAuthenticated()) {
|
||||
userService.setMenuAndRoles(token.getUsername());
|
||||
//userService.setMenuAndRoles(token.getUsername());
|
||||
token.getUsername();
|
||||
return "redirect:/main";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package com.len.controller;
|
||||
|
||||
import com.len.base.CurrentUser;
|
||||
import com.len.core.annotation.Log;
|
||||
import com.len.core.shiro.Principal;
|
||||
import com.len.entity.SysUser;
|
||||
import com.len.service.SysUserService;
|
||||
import com.len.util.BeanUtil;
|
||||
import com.len.util.Checkbox;
|
||||
import com.len.util.JsonUtil;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhuxiaomeng
|
||||
* @date 2019-04-05.
|
||||
* @email 154040976@qq.com
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/person")
|
||||
public class PersonController {
|
||||
|
||||
@Autowired
|
||||
SysUserService userService;
|
||||
|
||||
@GetMapping()
|
||||
public String toPerson(Model model) {
|
||||
CurrentUser principal = Principal.getPrincipal();
|
||||
if (principal == null) {
|
||||
return "/login";
|
||||
}
|
||||
String id = principal.getId();
|
||||
|
||||
List<Checkbox> checkboxList = userService.getUserRoleByJson(id);
|
||||
SysUser user = userService.selectByPrimaryKey(id);
|
||||
model.addAttribute("user", user);
|
||||
return "/system/person/me";
|
||||
}
|
||||
|
||||
@ApiOperation(value = "/updateUser", httpMethod = "POST", notes = "更新用户")
|
||||
@Log(desc = "更新用户", type = Log.LOG_TYPE.UPDATE)
|
||||
@PostMapping(value = "updateUser")
|
||||
@ResponseBody
|
||||
public JsonUtil updatePerson(SysUser user) {
|
||||
JsonUtil jsonUtil = new JsonUtil();
|
||||
jsonUtil.setFlag(false);
|
||||
if (user == null) {
|
||||
jsonUtil.setMsg("获取数据失败");
|
||||
return jsonUtil;
|
||||
}
|
||||
SysUser oldUser = userService.selectByPrimaryKey(user.getId());
|
||||
BeanUtil.copyNotNullBean(user, oldUser);
|
||||
userService.updateByPrimaryKeySelective(oldUser);
|
||||
jsonUtil.setFlag(true);
|
||||
jsonUtil.setMsg("修改成功");
|
||||
userService.updateCurrent(user);
|
||||
return jsonUtil;
|
||||
}
|
||||
}
|
|
@ -171,6 +171,7 @@ public class UserController extends BaseController {
|
|||
}
|
||||
jsonUtil.setFlag(true);
|
||||
jsonUtil.setMsg("修改成功");
|
||||
userService.updateCurrent(user);
|
||||
} catch (MyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.len.core.annotation;
|
|||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.len.base.CurrentUser;
|
||||
import com.len.core.shiro.ShiroUtil;
|
||||
import com.len.core.shiro.Principal;
|
||||
import com.len.entity.SysLog;
|
||||
import com.len.mapper.SysLogMapper;
|
||||
import com.len.util.IpUtil;
|
||||
|
@ -11,10 +11,7 @@ import java.lang.reflect.Method;
|
|||
import java.util.Date;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.UnavailableSecurityManagerException;
|
||||
import org.apache.shiro.mgt.SecurityManager;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.After;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
|
@ -87,7 +84,7 @@ public class LogAspect {
|
|||
}
|
||||
log.setParam(buffer.toString());
|
||||
try {
|
||||
CurrentUser currentUser = ShiroUtil.getCurrentUse();
|
||||
CurrentUser currentUser = Principal.getCurrentUse();
|
||||
log.setUserName(currentUser.getUsername());
|
||||
} catch (UnavailableSecurityManagerException e) {
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ public class PermissionFilter extends AuthorizationFilter {
|
|||
|
||||
Subject sub = getSubject(servletRequest, servletResponse);
|
||||
Session session= sub.getSession();
|
||||
CurrentUser user= (CurrentUser) session.getAttribute("curentUser");
|
||||
CurrentUser user= (CurrentUser) session.getAttribute("currentPrincipal");
|
||||
log.info("user:{}",user);
|
||||
if(user==null) {
|
||||
return false;
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.len.base.CurrentRole;
|
|||
import com.len.base.CurrentUser;
|
||||
import com.len.entity.SysUser;
|
||||
import com.len.service.SysUserService;
|
||||
import com.len.util.BeanUtil;
|
||||
import com.len.util.JWTUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authc.*;
|
||||
|
@ -41,18 +42,18 @@ public class LoginRealm extends AuthorizingRealm {
|
|||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
|
||||
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
|
||||
String name = (String) principalCollection.getPrimaryPrincipal();
|
||||
CurrentUser user = (CurrentUser) principalCollection.getPrimaryPrincipal();
|
||||
Set<String> realmNames = principalCollection.getRealmNames();
|
||||
List<String> realmNameList = new ArrayList<>(realmNames);
|
||||
if ("BlogLogin".equals(realmNameList.get(0))) {
|
||||
String[] roles = JWTUtil.getRoles(name);
|
||||
String[] roles = JWTUtil.getRoles(user.getUsername());
|
||||
assert roles != null;
|
||||
for (String role : roles) {
|
||||
info.addRole(role);
|
||||
}
|
||||
} else {
|
||||
//根据用户获取角色 根据角色获取所有按钮权限
|
||||
CurrentUser cUser = (CurrentUser) ShiroUtil.getSession().getAttribute("curentUser");
|
||||
CurrentUser cUser = (CurrentUser) Principal.getSession().getAttribute("currentPrincipal");
|
||||
for (CurrentRole cRole : cUser.getCurrentRoleList()) {
|
||||
info.addRole(cRole.getId());
|
||||
}
|
||||
|
@ -86,7 +87,11 @@ public class LoginRealm extends AuthorizingRealm {
|
|||
if (s == null) {
|
||||
throw new UnknownAccountException("账户密码不正确");
|
||||
}
|
||||
CurrentUser user=new CurrentUser();
|
||||
BeanUtil.copyNotNullBean(s,user);
|
||||
user.setPassword(null);
|
||||
userService.setMenuAndRoles(username);
|
||||
ByteSource byteSource = ByteSource.Util.bytes(username);
|
||||
return new SimpleAuthenticationInfo(username, s.getPassword(), byteSource, getName());
|
||||
return new SimpleAuthenticationInfo(user, s.getPassword(), byteSource, getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.len.core.shiro;
|
||||
|
||||
import com.len.base.CurrentUser;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
/**
|
||||
* @author zhuxiaomeng
|
||||
* @date 2017/12/28.
|
||||
* @email 154040976@qq.com
|
||||
*/
|
||||
public class Principal {
|
||||
|
||||
/**
|
||||
* 获取用户主题
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Subject getSubject() {
|
||||
return SecurityUtils.getSubject();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户对象
|
||||
* @return
|
||||
*/
|
||||
public static CurrentUser getPrincipal() {
|
||||
return (CurrentUser) getSubject().getPrincipal();
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前session
|
||||
* @return
|
||||
*/
|
||||
public static Session getSession() {
|
||||
return getSubject().getSession();
|
||||
}
|
||||
|
||||
public static CurrentUser getCurrentUse() {
|
||||
return (CurrentUser) getSession().getAttribute("currentPrincipal");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package com.len.core.shiro;
|
||||
|
||||
import com.len.base.CurrentUser;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
/**
|
||||
* @author zhuxiaomeng
|
||||
* @date 2017/12/28.
|
||||
* @email 154040976@qq.com
|
||||
*/
|
||||
public class ShiroUtil {
|
||||
|
||||
public static Subject getSubject(){
|
||||
return SecurityUtils.getSubject();
|
||||
}
|
||||
|
||||
public static Session getSession(){
|
||||
return getSubject().getSession();
|
||||
}
|
||||
public static CurrentUser getCurrentUse(){
|
||||
return (CurrentUser) getSession().getAttribute("curentUser");
|
||||
}
|
||||
|
||||
}
|
|
@ -66,4 +66,6 @@ public interface SysUserService extends BaseService<SysUser,String> {
|
|||
List<SysUser> getUserByRoleId(String roleId);
|
||||
|
||||
public void setMenuAndRoles(String username);
|
||||
|
||||
public void updateCurrent(SysUser user);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.len.base.CurrentMenu;
|
|||
import com.len.base.CurrentRole;
|
||||
import com.len.base.CurrentUser;
|
||||
import com.len.base.impl.BaseServiceImpl;
|
||||
import com.len.core.shiro.ShiroUtil;
|
||||
import com.len.core.shiro.Principal;
|
||||
import com.len.entity.SysMenu;
|
||||
import com.len.entity.SysRole;
|
||||
import com.len.entity.SysRoleUser;
|
||||
|
@ -25,14 +25,14 @@ import com.len.util.Md5Util;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author zhuxiaomeng
|
||||
|
@ -215,7 +215,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUser, String> impleme
|
|||
s.setUsername(username);
|
||||
s = this.selectOne(s);
|
||||
CurrentUser currentUser = new CurrentUser(s.getId(), s.getUsername(), s.getAge(), s.getEmail(), s.getPhoto(), s.getRealName());
|
||||
Subject subject = ShiroUtil.getSubject();
|
||||
Subject subject = Principal.getSubject();
|
||||
/*角色权限封装进去*/
|
||||
//根据用户获取菜单
|
||||
Session session = subject.getSession();
|
||||
|
@ -226,7 +226,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUser, String> impleme
|
|||
|
||||
|
||||
List<CurrentMenu> currentMenuList = new ArrayList<>();
|
||||
List<SysRole> roleList = new ArrayList<>();
|
||||
Set<SysRole> roleList = new HashSet<>();
|
||||
for (SysMenu m : menuList) {
|
||||
CurrentMenu currentMenu = new CurrentMenu();
|
||||
BeanUtil.copyNotNullBean(m, currentMenu);
|
||||
|
@ -234,7 +234,6 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUser, String> impleme
|
|||
roleList.addAll(m.getRoleList());
|
||||
}
|
||||
|
||||
roleList = new ArrayList<>(new HashSet<>(roleList));
|
||||
List<CurrentRole> currentRoleList = new ArrayList<>();
|
||||
|
||||
for (SysRole r : roleList) {
|
||||
|
@ -244,6 +243,22 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUser, String> impleme
|
|||
}
|
||||
currentUser.setCurrentRoleList(currentRoleList);
|
||||
currentUser.setCurrentMenuList(currentMenuList);
|
||||
session.setAttribute("curentUser", currentUser);
|
||||
session.setAttribute("currentPrincipal", currentUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新session头像
|
||||
*/
|
||||
@Override
|
||||
public void updateCurrent(SysUser sysUser) {
|
||||
CurrentUser principal = Principal.getPrincipal();
|
||||
if(principal.getId().equals(sysUser.getId())){
|
||||
//当前用户
|
||||
CurrentUser currentUse = Principal.getCurrentUse();
|
||||
Session session=Principal.getSession();
|
||||
currentUse.setPhoto(sysUser.getPhoto());
|
||||
session.setAttribute("currentPrincipal",currentUse);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,11 +52,11 @@
|
|||
</li>
|
||||
<li class="layui-nav-item">
|
||||
<a href="javascript:;">
|
||||
<#assign currentUser = Session["curentUser"]>
|
||||
<#assign currentUser = Session["currentPrincipal"]>
|
||||
<img src="${re.contextPath}/images/${currentUser.photo}" class="layui-nav-img">${currentUser.username}
|
||||
</a>
|
||||
<dl class="layui-nav-child">
|
||||
<dd><a href="javascript:;" kit-target data-options="{url:'basic.html',icon:'',title:'基本资料',id:'966'}"><span>基本资料</span></a></dd>
|
||||
<dd><a href="javascript:;" kit-target data-options="{url:'/person',icon:'',title:'基本资料',id:'966'}"><span>基本资料</span></a></dd>
|
||||
<dd><a href="javascript:;">安全设置</a></dd>
|
||||
</dl>
|
||||
</li>
|
||||
|
|
|
@ -0,0 +1,192 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>个人信息</title>
|
||||
<link rel="stylesheet" href="/plugin/layui/css/layui.css">
|
||||
<script type="text/javascript" src="/plugin/jquery/jquery-3.2.1.min.js"></script>
|
||||
<script type="text/javascript" src="/plugin/layui/layui.all.js" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="/plugin/tools/tool.js"></script>
|
||||
<script type="text/javascript" src="/plugin/tools/update-setting.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<form class="layui-form layui-form-pane" style="margin-left: 20px;">
|
||||
<div class="layui-form-item">
|
||||
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
|
||||
<legend style="font-size:16px;">头像上传</legend>
|
||||
</fieldset>
|
||||
<div class="layui-input-inline">
|
||||
<div class="layui-upload-drag" style="margin-left:10%;" id="test10">
|
||||
<i style="font-size:30px;" class="layui-icon"></i>
|
||||
<p style="font-size: 10px">点击上传,或将文件拖拽到此处</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-input-inline">
|
||||
|
||||
<div id="demo2" style="margin-top: 20px;margin-left: 50px">
|
||||
<img src="/images/${re.contextPath}/${user.photo}" width="100px" height="100px" class="layui-upload-img layui-circle">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
|
||||
<legend style="font-size:16px;">基础信息</legend>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="uname" class="layui-form-label">
|
||||
<span class="x-red">*</span>用户名
|
||||
</label>
|
||||
<div class="layui-input-inline">
|
||||
<input value="${user.id}" type="hidden" name="id">
|
||||
<input type="text" id="uname" value="${user.username}" readonly lay-verify="username"
|
||||
autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
<div id="ms" class="layui-form-mid layui-word-aux">
|
||||
<span class="x-red">*</span><span id="ums">将会成为您唯一的登入名</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-inline">
|
||||
<label for="realName" class="layui-form-label">
|
||||
<span class="x-red">*</span>真实姓名
|
||||
</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" id="realName" value="${user.realName}" name="realName" lay-verify="realName" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<label for="age" class="layui-form-label">
|
||||
<span class="x-red">*</span>年龄
|
||||
</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" id="age" name="age" value="${user.age}" lay-verify="number"
|
||||
autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label for="email" class="layui-form-label">
|
||||
<span class="x-red"></span>邮箱
|
||||
</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="email" id="email" value="${user.email}" style="width: 93%" name="email" lay-verify="email"
|
||||
autocomplete="off" class="layui-input">
|
||||
<input id="photo" value="${user.photo}" name="photo" type="hidden">
|
||||
</div>
|
||||
</div>
|
||||
<a class="layui-btn layui-btn-normal" lay-filter="*" lay-submit>
|
||||
更新
|
||||
</a>
|
||||
</form>
|
||||
</body>
|
||||
<script>
|
||||
var flag;
|
||||
$(function () {
|
||||
let name='${user.username}';
|
||||
if($('#uname').val()===name)
|
||||
flag=true;
|
||||
let uNameFun=$('#uname');
|
||||
uNameFun.on('blur',function(){
|
||||
let uName=uNameFun.val();
|
||||
if(uName.match(/[\u4e00-\u9fa5]/)) return;
|
||||
if(!/(.+){3,12}$/.test(uName)) return;
|
||||
|
||||
if(uName!=''&&uName!=name) {
|
||||
$.ajax({
|
||||
url: 'checkUser?uname=' + uname, async: false, type: 'get', success: function (data) {
|
||||
flag = data.flag;
|
||||
$('#ms').find('span').remove();
|
||||
if (!data.flag) {
|
||||
msg = data.msg;
|
||||
$('#ms').append("<span style='color: red;'>"+data.msg+"</span>");
|
||||
// layer.msg(msg,{icon: 5,anim: 6});
|
||||
}else{
|
||||
flag=true;
|
||||
$('#ms').append("<span style='color: green;'>用户名可用</span>");
|
||||
}
|
||||
},beforeSend:function(){
|
||||
$('#ms').find('span').remove();
|
||||
$('#ms').append("<span>验证ing</span>");
|
||||
}
|
||||
});
|
||||
}else{
|
||||
flag=true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
layui.use(['form','layer','upload'], function(){
|
||||
$ = layui.jquery;
|
||||
var form = layui.form
|
||||
,layer = layui.layer,
|
||||
upload = layui.upload;
|
||||
upload.render({
|
||||
elem: '#test10'
|
||||
,url: '/user/upload'
|
||||
,before: function(obj){
|
||||
//预读,不支持ie8
|
||||
obj.preview(function(index, file, result){
|
||||
$('#demo2').find('img').remove();
|
||||
$('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" width="100px" height="100px" class="layui-upload-img layui-circle">');
|
||||
});
|
||||
},done: function(res){
|
||||
if(!res.flag){
|
||||
layer.msg(res.msg,{icon: 5,anim: 6});
|
||||
}else{
|
||||
$("#photo").val(res.msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//自定义验证规则
|
||||
form.verify({
|
||||
username: function(value){
|
||||
if(value.trim()==""){
|
||||
return "用户名不能为空";
|
||||
}
|
||||
if(value.match(/[\u4e00-\u9fa5]/)){
|
||||
return "用户名不能为中文";
|
||||
}
|
||||
if(!/(.+){3,12}$/.test(value)){
|
||||
return "用户名必须3到12位";
|
||||
}
|
||||
if(typeof(flag)=='undefined'){
|
||||
return "用户名验证ing";
|
||||
}
|
||||
if(!flag){
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
,email:function(value){
|
||||
if(value!=""){
|
||||
if(!/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(value)){
|
||||
return "邮箱格式不正确";
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//监听提交
|
||||
form.on('submit(*)', function(data){
|
||||
$.ajax({
|
||||
url:'/person/updateUser',
|
||||
type:'post',
|
||||
data:data.field,
|
||||
traditional: true,
|
||||
success:function(d){
|
||||
if(d.flag){
|
||||
window.top.layer.msg(d.msg,{icon:6,offset: 'rb',area:['200px','80px'],anim:2});
|
||||
}else{
|
||||
layer.msg(d.msg,{icon:5});
|
||||
}
|
||||
},error:function(e){
|
||||
layer.msg('发生错误',{icon:6});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</html>
|
Loading…
Reference in New Issue