easy-ui
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>后台管理-进销存管理系统</title>
<link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/default/easyui.css"></link>
<link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/icon.css"></link>
<style type="text/css">
.clock {
float:right;
width: 300px;
height: 30px;
padding-left: 20px;
color: rgb(0, 76, 126);
background: url(/static/images/clock.gif) no-repeat;
font-size: 14px;
}
.userInfo{
float:left;
padding-left: 20px;
padding-top: 30px;
}
</style>
<script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
function showTime(){
var date = new Date();
this.year = date.getFullYear();
this.month = date.getMonth() + 1;
this.date = date.getDate();
this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[date.getDay()];
this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
$("#clock").text("现在是:" + this.year + "年" + this.month + "月" + this.date + "日 " + this.hour + ":" + this.minute + ":" + this.second + " " + this.day);
}
$(document).ready(function() {
window.setInterval("showTime()",1000);
$("#userInfo").load("/user/loadUserInfo"); // 加载用户信息
});
</script>
</head>
<body class="easyui-layout">
<div region="north" style="height: 72px;">
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="381px" style="background:url(/static/images/top_left.jpg)">
</td>
<td style="background:url(/static/images/top_center.jpg)">
<div id="userInfo" class="userInfo"></div>
</td>
<td valign="bottom" width="544px" style="background:url(/static/images/top_right.jpg)">
<div id="clock" class="clock"></div>
</td>
</tr>
</table>
</div>
<div region="center">
</div>
<div region="west" style="width: 200px" title="导航菜单" split="true" iconCls="icon-navigation">
</div>
<div region="south" style="height: 30px;padding: 5px" align="center">
Copyright © 2012-2017 南通小锋网络科技有限公司 版权所有
</div>
</body>
</html>
package com.java1234.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import com.java1234.entity.Role;
import com.java1234.service.RoleService;
import com.java1234.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.java1234.entity.User;
import com.java1234.util.StringUtil;
/**
* 用户Controller
* @author Administrator
*
*/
@Controller
@RequestMapping("/user")
public class UserController {
@Resource
private UserService userService;
@Resource
private RoleService roleService;
/**
* 用户登录判断
* @param imageCode
* @param user
* @param bindingResult
* @param session
* @return
*/
@ResponseBody
@RequestMapping("/login")
public Map<String,Object> login(String imageCode,@Valid User user,BindingResult bindingResult,HttpSession session){
Map<String,Object> map=new HashMap<String,Object>();
if(StringUtil.isEmpty(imageCode)){
map.put("success", false);
map.put("errorInfo", "请输入验证码!");
return map;
}
if(!session.getAttribute("checkcode").equals(imageCode)){
map.put("success", false);
map.put("errorInfo", "验证码输入错误!");
return map;
}
if(bindingResult.hasErrors()){
map.put("success", false);
map.put("errorInfo", bindingResult.getFieldError().getDefaultMessage());
return map;
}
Subject subject=SecurityUtils.getSubject();
UsernamePasswordToken token=new UsernamePasswordToken(user.getUserName(), user.getPassword());
try{
subject.login(token);
String userName=(String) SecurityUtils.getSubject().getPrincipal();
User currentUser=userService.findByUserName(userName);
session.setAttribute("currentUser",currentUser);
List<Role> roleList=roleService.findByUserId(currentUser.getId());
map.put("roleList",roleList);
map.put("roleSize",roleList.size());
map.put("success", true);
return map;
}catch(Exception e){
e.printStackTrace();
map.put("success", false);
map.put("errorInfo", "用户名或者密码错误!");
return map;
}
}
/**
* 保存角色信息
* @param roleId
* @param session
* @return
* @throws Exception
*/
@ResponseBody
@RequestMapping("/saveRole")
public Map<String,Object> saveRole(Integer roleId,HttpSession session)throws Exception{
Map<String,Object> map=new HashMap<String,Object>();
// Role currentRole=roleService
Role currentRole=roleService.findById(roleId);
session.setAttribute("currentRole",currentRole);
map.put("success",true);
return map;
}
/**
* 加载当前用户信息
* @param session
* @return
* @throws Exception
*/
@ResponseBody
@GetMapping("/locadUserInfo")
public String loadUserInfo(HttpSession session)throws Exception{
User currentUser=(User) session.getAttribute("currentUser");
Role currentRole=(Role) session.getAttribute("currentRole");
return "欢迎您:"+currentUser.getTrueName()+" [ "+currentRole.getName()+" ]";
}
}
本文含有隐藏内容,请 开通VIP 后查看