提交后台页面

This commit is contained in:
123 2025-04-28 08:40:44 +08:00
parent 85a8d27795
commit 3e8c6b20f5
2 changed files with 228 additions and 228 deletions

View File

@ -1,27 +1,5 @@
package cc.iteachyou.cms.controller.admin; package cc.iteachyou.cms.controller.admin;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.DisabledAccountException;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.wf.captcha.ArithmeticCaptcha;
import com.wf.captcha.utils.CaptchaUtil;
import cc.iteachyou.cms.annotation.Log; import cc.iteachyou.cms.annotation.Log;
import cc.iteachyou.cms.annotation.Log.OperatorType; import cc.iteachyou.cms.annotation.Log.OperatorType;
import cc.iteachyou.cms.common.BaseController; import cc.iteachyou.cms.common.BaseController;
@ -36,138 +14,157 @@ import cc.iteachyou.cms.security.token.TokenManager;
import cc.iteachyou.cms.service.MenuService; import cc.iteachyou.cms.service.MenuService;
import cn.hutool.crypto.asymmetric.KeyType; import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA; import cn.hutool.crypto.asymmetric.RSA;
import com.wf.captcha.ArithmeticCaptcha;
import com.wf.captcha.utils.CaptchaUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.DisabledAccountException;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.io.IOException;
import java.util.List;
/** /**
* 用户登录相关不需要做登录限制 * 用户登录相关不需要做登录限制
*
*/ */
@Slf4j @Slf4j
@Controller @Controller
@RequestMapping("/admin/u") @RequestMapping("/admin/u")
public class UserLoginController extends BaseController { public class UserLoginController extends BaseController {
@Autowired @Autowired
private MenuService menuService; private MenuService menuService;
// 产生验证码 // 产生验证码
@RequestMapping("/getVerifyCode") @RequestMapping("/getVerifyCode")
public void getKaptcha() throws IOException { public void getKaptcha() throws IOException {
ArithmeticCaptcha captcha = new ArithmeticCaptcha(130, 48); ArithmeticCaptcha captcha = new ArithmeticCaptcha(130, 48);
captcha.getArithmeticString(); // 获取运算的公式3+2=? captcha.getArithmeticString(); // 获取运算的公式3+2=?
captcha.text(); // 获取运算的结果5 captcha.text(); // 获取运算的结果5
CaptchaUtil.out(captcha, request, response); CaptchaUtil.out(captcha, request, response);
} }
/** /**
* 登录跳转 * 登录跳转
* *
* @return * @return
*/ */
@RequestMapping("toLogin") @RequestMapping("toLogin")
public ModelAndView toLogin() { public ModelAndView toLogin() {
ModelAndView mv = new ModelAndView(); ModelAndView mv = new ModelAndView();
User user = (User) SecurityUtils.getSubject().getPrincipal(); User user = (User) SecurityUtils.getSubject().getPrincipal();
RSA rsa = new RSA(); RSA rsa = new RSA();
session.setAttribute(Constant.RSA_PRIVATE_KEY, rsa.getPrivateKeyBase64()); session.setAttribute(Constant.RSA_PRIVATE_KEY, rsa.getPrivateKeyBase64());
mv.addObject("publicKey", rsa.getPublicKeyBase64()); mv.addObject("publicKey", rsa.getPublicKeyBase64());
mv.setViewName("admin/login"); mv.setViewName("admin/login");
return mv; return mv;
} }
/** /**
* 首页跳转 * 首页跳转
* *
* @return * @return
*/ */
@RequestMapping("toIndex") @RequestMapping("toIndex")
public ModelAndView toIndex() { public ModelAndView toIndex() {
ModelAndView mv = new ModelAndView(); ModelAndView mv = new ModelAndView();
String userId = TokenManager.getUserId(); String userId = TokenManager.getUserId();
/** /**
* 查询当前用户所拥有的菜单权限 * 查询当前用户所拥有的菜单权限
*/ */
List<Menu> menus = menuService.queryListByUserId(userId); List<Menu> menus = menuService.queryListByUserId(userId);
mv.addObject("menus", menus); mv.addObject("menus", menus);
mv.setViewName("admin/index"); mv.setViewName("admin/index");
return mv; return mv;
} }
/** /**
* 登录提交 * 登录提交
* @param entity 登录的UUser *
* @param rememberMe 是否记住 * @param entity 登录的UUser
* @param request用来取登录之前Url地址用来登录后跳转到没有登录之前的页面 * @param rememberMe 是否记住
* @return * @param request用来取登录之前Url地址用来登录后跳转到没有登录之前的页面
*/ * @return
@Log(operType = OperatorType.OTHER, module = "登录模块", content = "用户登录") */
@RequestMapping(value = "login", method = RequestMethod.POST) @Log(operType = OperatorType.OTHER, module = "登录模块", content = "用户登录")
@ResponseBody @RequestMapping(value = "login", method = RequestMethod.POST)
public ResponseResult login(@RequestBody UsernamePasswordREQ entity) { @ResponseBody
ResponseResult result = null; public ResponseResult login(@RequestBody UsernamePasswordREQ entity) {
User user = new User(); ResponseResult result = null;
try { User user = new User();
// 验证码校验 try {
if(!CaptchaUtil.ver(entity.getVcode(), request)) { // 验证码校验
result = ResponseResult.Factory.newInstance(Boolean.FALSE, if (!CaptchaUtil.ver(entity.getVcode(), request)) {
StateCodeEnum.USER_CODE_ERROR.getCode(), null, result = ResponseResult.Factory.newInstance(Boolean.FALSE,
StateCodeEnum.USER_CODE_ERROR.getDescription()); StateCodeEnum.USER_CODE_ERROR.getCode(), null,
return result; StateCodeEnum.USER_CODE_ERROR.getDescription());
} return result;
}
// 清除验证码 // 清除验证码
CaptchaUtil.clear(request); CaptchaUtil.clear(request);
String privateKey = (String) session.getAttribute(Constant.RSA_PRIVATE_KEY); String privateKey = (String) session.getAttribute(Constant.RSA_PRIVATE_KEY);
RSA rsa = new RSA(privateKey, null); RSA rsa = new RSA(privateKey, null);
String username = new String(rsa.decrypt(entity.getUsername(), KeyType.PrivateKey)); String username = new String(rsa.decrypt(entity.getUsername(), KeyType.PrivateKey));
String password = new String(rsa.decrypt(entity.getPassword(), KeyType.PrivateKey)); String password = new String(rsa.decrypt(entity.getPassword(), KeyType.PrivateKey));
boolean rememberMe = entity.isRememberMe(); boolean rememberMe = entity.isRememberMe();
ByteSource salt = ByteSource.Util.bytes(username + password); ByteSource salt = ByteSource.Util.bytes(username + password);
SimpleHash sh = new SimpleHash("MD5", password, salt, 1024); SimpleHash sh = new SimpleHash("MD5", password, salt, 1024);
user.setUsername(username); user.setUsername(username);
user.setPassword(sh.toString()); user.setPassword(sh.toString());
user.setSaltByte(salt); user.setSaltByte(salt);
user = TokenManager.login(user, rememberMe, salt); user = TokenManager.login(user, rememberMe, salt);
log.info("用户名" + user.getUsername());
log.info("密码" + user.getPassword());
log.info("" + user.getSalt());
UserLoginVO userVO = new UserLoginVO();
BeanUtils.copyProperties(user, userVO);
UserLoginVO userVO = new UserLoginVO(); result = ResponseResult.Factory.newInstance(Boolean.TRUE,
BeanUtils.copyProperties(user, userVO); StateCodeEnum.HTTP_SUCCESS.getCode(), userVO,
StateCodeEnum.HTTP_SUCCESS.getDescription());
session.removeAttribute(Constant.RSA_PRIVATE_KEY);
} catch (DisabledAccountException e) {
// 帐号已经禁用
result = ResponseResult.Factory.newInstance(Boolean.FALSE,
StateCodeEnum.USER_MOBILE_EXCEPTION.getCode(), null,
StateCodeEnum.USER_MOBILE_EXCEPTION.getDescription());
} catch (Exception e) {
e.printStackTrace();
// 帐号或密码错误
result = ResponseResult.Factory.newInstance(Boolean.FALSE,
StateCodeEnum.USER_PASSWORD_ERROR.getCode(), null,
StateCodeEnum.USER_PASSWORD_ERROR.getDescription());
}
return result;
}
result = ResponseResult.Factory.newInstance(Boolean.TRUE, /**
StateCodeEnum.HTTP_SUCCESS.getCode(), userVO, * 退出
StateCodeEnum.HTTP_SUCCESS.getDescription()); *
session.removeAttribute(Constant.RSA_PRIVATE_KEY); * @return
} catch (DisabledAccountException e) { */
// 帐号已经禁用 @Log(operType = OperatorType.OTHER, module = "登录模块", content = "用户退出登录")
result = ResponseResult.Factory.newInstance(Boolean.FALSE, @RequestMapping(value = "logout", method = RequestMethod.GET)
StateCodeEnum.USER_MOBILE_EXCEPTION.getCode(), null, public String logout() {
StateCodeEnum.USER_MOBILE_EXCEPTION.getDescription()); try {
} catch (Exception e) { TokenManager.logout();
e.printStackTrace(); } catch (Exception e) {
// 帐号或密码错误 log.error("errorMessage:" + e.getMessage());
result = ResponseResult.Factory.newInstance(Boolean.FALSE, }
StateCodeEnum.USER_PASSWORD_ERROR.getCode(), null, return "redirect:/admin/toLogin";
StateCodeEnum.USER_PASSWORD_ERROR.getDescription()); }
}
return result;
}
/**
* 退出
*
* @return
*/
@Log(operType = OperatorType.OTHER, module = "登录模块", content = "用户退出登录")
@RequestMapping(value = "logout", method = RequestMethod.GET)
public String logout() {
try {
TokenManager.logout();
} catch (Exception e) {
log.error("errorMessage:" + e.getMessage());
}
return "redirect:/admin/toLogin";
}
} }

View File

@ -1,40 +1,40 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"> <html lang="en" xmlns:th="http://www.thymeleaf.org">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Dreamer CMS - 后台管理系统</title> <title>Dreamer CMS - 后台管理系统</title>
<link href="/resource/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <link href="/resource/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="/resource/css/font-awesome.min.css" rel="stylesheet" type="text/css" /> <link href="/resource/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
<link href="/resource/css/ionicons.min.css" rel="stylesheet" type="text/css" /> <link href="/resource/css/ionicons.min.css" rel="stylesheet" type="text/css"/>
<link href="/resource/css/style.css" rel="stylesheet" type="text/css" /> <link href="/resource/css/style.css" rel="stylesheet" type="text/css"/>
</head> </head>
<body> <body>
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<h1 class="panel-heading">仪表盘</h1> <h1 class="panel-heading">仪表盘</h1>
<!--breadcrumbs start --> <!--breadcrumbs start -->
<ul class="breadcrumb"> <ul class="breadcrumb">
<li><a href="/admin/dashboard/toIndex"><i class="fa fa-home"></i> 首页</a></li> <li><a href="/admin/dashboard/toIndex"><i class="fa fa-home"></i> 首页</a></li>
<li class="active">仪表盘</li> <li class="active">仪表盘</li>
</ul> </ul>
<!--breadcrumbs end --> <!--breadcrumbs end -->
</div> </div>
</div> </div>
<section class="panel"> <section class="panel">
<div class="panel-body"> <div class="panel-body">
<div class="row" style="margin-bottom:5px;"> <div class="row" style="margin-bottom:5px;">
<div class="col-md-12"> <div class="col-md-12">
欢迎使用专业的JAVA网站管理系统轻松建站的首选利器——<b>梦想家CMS内容管理系统</b> 欢迎使用专业的JAVA网站管理系统轻松建站的首选利器——<b>梦想家CMS内容管理系统</b>
</div> </div>
</div> </div>
</div> </div>
</section> </section>
<section class="panel"> <section class="panel">
<div class="panel-heading dashboard-title">信息统计</div> <div class="panel-heading dashboard-title">信息统计</div>
<div class="panel-body"> <div class="panel-body">
<div class="row" style="margin-bottom:5px;"> <div class="row" style="margin-bottom:5px;">
<div class="col-md-3"> <div class="col-md-3">
<div class="sm-st clearfix"> <div class="sm-st clearfix">
<span class="sm-st-icon st-red"><i class="fa fa-file-text-o"></i></span> <span class="sm-st-icon st-red"><i class="fa fa-file-text-o"></i></span>
@ -72,76 +72,79 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</section> </section>
<section class="panel"> <section class="panel">
<div class="panel-heading dashboard-title"> <div class="panel-heading dashboard-title">
版本信息及商业授权 版本信息及商业授权
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div class="row" style="margin-bottom:5px;"> <div class="row" style="margin-bottom:5px;">
<div class="col-md-12"> <div class="col-md-12">
<div class="fl" style="padding: 30px 30px 30px 0;"> <div class="fl" style="padding: 30px 30px 30px 0;">
<img alt="梦想家CMS内容管理系统" src="/resource/img/dreamercms-logo.png" width="100"> <img alt="梦想家CMS内容管理系统" src="/resource/img/dreamercms-logo.png" width="100">
</div> </div>
<div class="fl" style="margin-left:10px;"> <div class="fl" style="margin-left:10px;">
<b>当前系统版本为开源版V4.0.1</b> <b>当前系统版本为开源版V4.0.1</b>
<ul style="line-height: 25px;margin-top: 10px;"> <ul style="line-height: 25px;margin-top: 10px;">
<li>升级FastJson漏洞</li> <li>升级FastJson漏洞</li>
<li>修复Sql标签注入风险</li> <li>修复Sql标签注入风险</li>
<li>修复Log4j漏洞</li> <li>修复Log4j漏洞</li>
<li>修改分页标签、栏目文档标签、SQL标签Bug</li> <li>修改分页标签、栏目文档标签、SQL标签Bug</li>
<li>主题包的缩略图支持重新上传</li> <li>主题包的缩略图支持重新上传</li>
</ul> </ul>
<b>根据软件使用协议,未经商业授权的系统请务必保留官方版权。前后台页底必须保留 "Powered by I Teach You , 我教你!" 文字和链接!</b> <b>根据软件使用协议,未经商业授权的系统请务必保留官方版权。前后台页底必须保留 "Powered by I Teach You
</div> , 我教你!" 文字和链接!</b>
<div class="clearFix"></div> </div>
</div> <div class="clearFix"></div>
</div> </div>
</div> </div>
</div>
</section> </section>
<div class="row" style="margin-bottom:5px;"> <div class="row" style="margin-bottom:5px;">
<div class="col-md-4"> <div class="col-md-4">
<section class="panel"> <section class="panel">
<div class="panel-heading dashboard-title">最新文章</div> <div class="panel-heading dashboard-title">最新文章</div>
<div class="panel-body" style="height: 300px;"> <div class="panel-body" style="height: 300px;">
<ul class="newest"> <ul class="newest">
<li th:each="item : ${newest}"> <li th:each="item : ${newest}">
<a th:text="${item.title}" target="_blank" th:title="${item.title}" th:href="'/article/' + ${item.id}"></a> <a th:text="${item.title}" target="_blank" th:title="${item.title}"
</li> th:href="'/article/' + ${item.id}"></a>
</ul> </li>
</div> </ul>
</section> </div>
</div> </section>
<div class="col-md-4"> </div>
<section class="panel"> <div class="col-md-4">
<div class="panel-heading dashboard-title">开发团队</div> <section class="panel">
<div class="panel-body" style="height: 300px;"> <div class="panel-heading dashboard-title">开发团队</div>
<p>版权所有:<b><a href="http://www.iteachyou.cc" target="_blank" title="I Teach You我教你">I Tech You , 我教你!</a></b></p> <div class="panel-body" style="height: 300px;">
<p>开发团队成员:<b>王俊南</b></p> <p>版权所有:<b><a href="http://www.iteachyou.cc" target="_blank" title="I Teach You我教你">I Tech You
<p>官方网址:<b><a href="http://www.iteachyou.cc" target="_blank" title="I Teach You我教你">http://www.iteachyou.cc</a></b></p> , 我教你!</a></b></p>
<p>官方演示网址:<b><a href="http://cms.iteachyou.cc" target="_blank" title="梦想家CMS内容管理系统">http://cms.iteachyou.cc</a></b></p> <!-- <p>开发团队成员:<b></b></p>-->
<p>码云源码网址:<b><a href="https://gitee.com/iteachyou/dreamer_cms" target="_blank" title="梦想家CMS内容管理系统">https://gitee.com/iteachyou/dreamer_cms</a></b></p> <!-- <p>官方网址:<b><a href="http://www.iteachyou.cc" target="_blank" title="I Teach You我教你">http://www.iteachyou.cc</a></b></p>-->
<p>Github源码网址<b><a href="https://github.com/iteachyou-wjn/dreamer_cms" target="_blank" title="梦想家CMS内容管理系统">https://github.com/iteachyou-wjn/dreamer_cms</a></b></p> <!-- <p>官方演示网址:<b><a href="http://cms.iteachyou.cc" target="_blank" title="梦想家CMS内容管理系统">http://cms.iteachyou.cc</a></b></p>-->
<p>官方QQ群<b>①597652651</b><b>②623605199</b><b>③573574854</b></p> <!-- <p>码云源码网址:<b><a href="https://gitee.com/iteachyou/dreamer_cms" target="_blank" title="梦想家CMS内容管理系统">https://gitee.com/iteachyou/dreamer_cms</a></b></p>-->
</div> <!-- <p>Github源码网址<b><a href="https://github.com/iteachyou-wjn/dreamer_cms" target="_blank" title="梦想家CMS内容管理系统">https://github.com/iteachyou-wjn/dreamer_cms</a></b></p>-->
</section> <!-- <p>官方QQ群<b>①597652651</b>、<b>②623605199</b>、<b>③573574854</b></p>-->
</div> </div>
<div class="col-md-4"> </section>
<section class="panel"> </div>
<div class="panel-heading dashboard-title">服务器信息</div> <div class="col-md-4">
<div class="panel-body" style="height: 300px;"> <section class="panel">
<p>JVM名称<b th:text="${serverInfo.jvmName}"></b></p> <div class="panel-heading dashboard-title">服务器信息</div>
<p>JAVA版本<b th:text="${serverInfo.jreVersion}"></b></p> <div class="panel-body" style="height: 300px;">
<p>JAVA安装路径<b th:text="${serverInfo.javaPath}"></b></p> <p>JVM名称<b th:text="${serverInfo.jvmName}"></b></p>
<p>JVM总内存<b th:text="${serverInfo.jvmTotalMemory}"></b></p> <p>JAVA版本<b th:text="${serverInfo.jreVersion}"></b></p>
<p>JVM可用内存<b th:text="${serverInfo.jvmFreeMemory}"></b></p> <p>JAVA安装路径<b th:text="${serverInfo.javaPath}"></b></p>
<p>操作系统名称:<b th:text="${serverInfo.optName}"></b></p> <p>JVM总内存<b th:text="${serverInfo.jvmTotalMemory}"></b></p>
<p>操作系统架构:<b th:text="${serverInfo.optFrameWork}"></b></p> <p>JVM可用内存<b th:text="${serverInfo.jvmFreeMemory}"></b></p>
<p>数据库版本:<b th:text="${serverInfo.dbVersion}"></b></p> <p>操作系统名称:<b th:text="${serverInfo.optName}"></b></p>
</div> <p>操作系统架构:<b th:text="${serverInfo.optFrameWork}"></b></p>
</section> <p>数据库版本:<b th:text="${serverInfo.dbVersion}"></b></p>
</div> </div>
</section>
</div>
</div> </div>
<script src="/resource/js/jquery.min.js"></script> <script src="/resource/js/jquery.min.js"></script>
<script src="/resource/js/bootstrap.min.js"></script> <script src="/resource/js/bootstrap.min.js"></script>