package com.perfree.controller;
import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.core.util.RandomUtil;
import com.perfree.base.BaseController;
import com.perfree.commons.*;
import com.perfree.model.Menu;
import com.perfree.model.Option;
import com.perfree.model.Role;
import com.perfree.model.User;
import com.perfree.service.*;
import io.swagger.annotations.ApiOperation;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.io.IOException;
import java.io.Writer;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
/**
* 控制首页地址
*/
@Controller
public class SystemController extends BaseController {
private final Logger logger = LoggerFactory.getLogger(SystemController.class);
private static final CacheManager cacheManager = CacheManager.newInstance();
@Autowired
private UserService userService;
@Autowired
private SEOService seoService;
@Autowired
private MailService mailService;
@Autowired
private UpdateService updateService;
@Autowired
private RoleService roleService;
@Autowired
private RssServices rssServices;
@Value("${shiro.timeout}")
private Long timeout;
@Value("${server.port}")
private int serverPort;
/**
* 后台首页
* @return String
*/
@RequestMapping("/admin")
@RequiresRoles(value={Constants.ROLE_ADMIN, Constants.ROLE_EDITOR, Constants.ROLE_CONTRIBUTE,
Constants.ROLE_USER}, logical= Logical.OR)
public String adminIndex(Model model) {
model.addAttribute("user", getUser());
return view("static/admin/pages/index.html");
}
@PostMapping("/admin/menu/getAdminMenu")
@ResponseBody
@RequiresRoles(value={Constants.ROLE_ADMIN, Constants.ROLE_EDITOR, Constants.ROLE_CONTRIBUTE,
Constants.ROLE_USER}, logical= Logical.OR)
public ResponseBean getAdminMenu() {
List<Menu> menus = getMenuByUserIdAndType(1);
return ResponseBean.success("success", menus);
}
/**
* 前台首页
* @return String
*/
@RequestMapping("/")
@FrontViewNodeRender
public String index(Model model) {
model.addAttribute("url", Constants.URL_ARTICLE_LIST);
return view(currentThemePage() + "/index.html");
}
/**
* 登陆页
* @return String
*/
@RequestMapping("/login")
public String login() {
return view("/login.html", "/login.html", "static/admin/pages/login/login.html");
}
@RequestMapping("/html/{name}")
@FrontViewNodeRender
public String renderHtml(@PathVariable String name) {
return view(currentThemePage() + "/html/" + name + ".html");
}
/**
* 注册页
* @return String
*/
@RequestMapping("/register")
public String register() {
return view("/register.html", "/register.html", "static/admin/pages/register/register.html");
}
/**
* 忘记密码
* @return String
*/
@RequestMapping("/restPassword")
public String restPassword() {
return view("/restPassword.html", "/restPassword.html", "static/admin/pages/restPassword/restPassword.html");
}
/**
* 忘记密码
* @return String
*/
@RequestMapping("/restPasswordStep2")
public String restPasswordStep2() {
return view("/restPassword-step2.html", "/restPassword-step2.html", "static/admin/pages/restPassword/restPassword-step2.html");
}
/**
* 登录
* @return ResponseBean
*/
@RequestMapping(method = RequestMethod.POST, path = "/doLogin")
@ResponseBody
@SuppressWarnings("all")
@AccessCacheLock
public ResponseBean doLogin(@RequestBody User user,Boolean rememberMe, HttpSession session, HttpServletResponse response) {
if(rememberMe == null) {
rememberMe = false;
}
int count = 1;
Ehcache cache = cacheManager.getEhcache("loginCache");
try {
String isOpenCaptcha = OptionCacheUtil.getDefaultValue(Constants.OPTION_WEB_OPEN_CAPTCHA, Constants.OPEN_CAPTCHA);
if (Constants.OPEN_CAPTCHA.equals(isOpenCaptcha) && (StringUtils.isBlank(user.getCaptcha()) ||
!user.getCaptcha().toUpperCase().equals(session.getAttribute("CAPTCHA_CODE").toString()))){
return ResponseBean.fail("验证码错误", null);
}
Element element = cache.get(user.getAccount());
if(element == null){
cache.put(new Element(user.getAccount(), 1));
} else {
count = Integer.parseInt(element.getObjectValue().toString());
}
if (count >= 8) {
return ResponseBean.fail("账户已被锁定,请10分钟后再试", null);
}
UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(user.getAccount(),user.getPassword(),rememberMe);
Subject subject = SecurityUtils.getSubject();
subject.login(usernamePasswordToken);
User userByAccount = userService.getUserByAccount(user.getAccount());
String md5Hash = new Md5Hash(userByAccount.getPassword(), user.getSalt()).toString();
String token = JwtUtils.sign(userByAccount.getAccount(), md5Hash);
userByAccount.setPassword(null);
userByAccount.setSalt(null);
HashMap<String, Object> result = new HashMap<>();
result.put("user", userByAccount);
result.put("token", token);
subject.getSession().setTimeout(timeout * 1000 * 60);
return ResponseBean.success("登录成功", result);
}catch (IncorrectCredentialsException e) {
session.removeAttribute("CAPTCHA_CODE");
if (count < 8) {
cache.put(new Element(user.getAccount(), ++count));
count--;
}
if (count >= 5 && count < 8) {
return ResponseBean.fail("用户名或密码错误,还有" + (8 - count) + "次将锁定该账户10分钟", e.getMessage());
}
if (count >= 8) {
return ResponseBean.fail("用户名或密码错误,账户已被锁定,请10分钟后再试", e.getMessage());
}
return ResponseBean.fail("用户名或密码错误", e.getMessage());
}catch (UnknownAccountException e) {
session.removeAttribute("CAPTCHA_CODE");
return ResponseBean.fail("账户不存在", e.getMessage());
}catch (Exception e) {
session.removeAttribute("CAPTCHA_CODE");
return ResponseBean.fail("系统异常", e.getMessage());
}
}
/**
* @description 重置密码 step1
* @return com.perfree.common.ResponseBean
* @author Perfree
*/
@RequestMapping(method = RequestMethod.POST, path = "/doRestPassword")
@ResponseBody
@AccessCacheLock
public ResponseBean doRestPassword(@RequestBody User user, HttpSess
没有合适的资源?快使用搜索试试~ 我知道了~
基于Java技术的PerfreeBlog博客/CMS建站平台设计源码
共1774个文件
js:574个
html:322个
java:244个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 33 浏览量
2024-09-30
06:54:03
上传
评论
收藏 31.8MB ZIP 举报
温馨提示
该源码是一款基于Java技术的PerfreeBlog博客/CMS建站平台,融合了丰富的主题和扩展插件功能,旨在为用户提供全新的创作体验。项目包含1743个文件,涵盖了574个JavaScript文件、322个HTML文件、244个Java文件、161个CSS文件等多种类型,支持包括TypeScript和Shell在内的多种编程语言,旨在为用户打造一个灵活、高效的内容管理系统。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java技术的PerfreeBlog博客/CMS建站平台设计源码 (1774个子文件)
AUTHORS 6KB
start.bat 54B
animate.css 120KB
layui.css 80KB
editormd.css 76KB
editormd.min.css 60KB
toast.css 59KB
editormd.preview.css 55KB
editormd.preview.min.css 44KB
font-awesome.css 37KB
font-awesome.min.css 30KB
ambiance.css 26KB
loading.css 25KB
select.css 19KB
layer.css 14KB
main.css 13KB
style.css 13KB
ckEditor.css 12KB
article.css 12KB
layout.css 11KB
admin.css 9KB
viewer.css 9KB
style.css 9KB
codemirror.css 9KB
awesome.css 8KB
icon.css 8KB
codemirror.css 8KB
viewer.min.css 8KB
viewer.min.css 8KB
laydate.css 8KB
iconfont.css 8KB
article.css 8KB
notice.css 7KB
notice.css 7KB
layer.css 7KB
metroStyle.css 6KB
zTreeStyle.css 6KB
perfree-comment.css 6KB
tab.css 6KB
journal.css 5KB
codemirror.min.css 5KB
dtree.css 5KB
menu.css 5KB
notyf.min.css 5KB
mdn-like.css 5KB
solarized.css 5KB
dtreefont.css 4KB
cropper.css 4KB
index.css 3KB
merge.css 3KB
comment.css 3KB
merge.css 3KB
restPassword.css 3KB
install.css 3KB
login.css 3KB
button.css 3KB
lint.css 3KB
register.css 3KB
lint.css 3KB
frame.css 3KB
xq-dark.css 3KB
index.css 3KB
main.css 3KB
link.css 3KB
archive.css 2KB
lesser-dark.css 2KB
archive.css 2KB
pastel-on-dark.css 2KB
xq-light.css 2KB
demo.css 2KB
tomorrow-night-eighties.css 2KB
editormd.logo.css 2KB
dracula.css 2KB
erlang-dark.css 2KB
console1.css 2KB
zenburn.css 2KB
dashboard.css 2KB
twilight.css 2KB
midnight.css 2KB
page_create.css 2KB
vibrant-ink.css 2KB
mbo.css 2KB
tern.css 2KB
base16-dark.css 2KB
base16-light.css 2KB
login.css 2KB
tern.css 2KB
article_create.css 2KB
3024-night.css 2KB
paraiso-dark.css 2KB
paraiso-light.css 2KB
table.css 2KB
tomorrow-night-bright.css 2KB
3024-day.css 2KB
code.css 2KB
blackboard.css 2KB
console2.css 2KB
colorforth.css 2KB
editormd.logo.min.css 2KB
the-matrix.css 2KB
共 1774 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18
资源评论
wjs2024
- 粉丝: 2357
- 资源: 5471
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 算法竞赛中的离散化 概念总结和基本操作全解
- 算法竞赛位运算(简单易懂)
- 常用一维二维 前缀和与差分算法模板总结
- SAR成像算法+后向投影(BP)算法+星载平台实测数据
- 横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横
- 基于Java和HTML的留言墙、验证码、计算器基础项目设计源码
- 基于JAVA C/C++的嵌入式设备组网平台物联网框架设计源码
- 基于Java开发的高性能全文检索工具包jsearch设计源码
- 基于多语言技术的pt遨游助手手机版设计源码
- 基于若依框架的染云盘V1.0.2设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功