parent
31ac90019b
commit
43cc8cc3da
1218
log/onlineoj.log
1218
log/onlineoj.log
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,6 @@
|
||||||
package top.weiyuexin.config;
|
package top.weiyuexin.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
@ -7,9 +8,15 @@ import top.weiyuexin.interceptor.LoginInterceptor;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class InterceptorConfig implements WebMvcConfigurer {
|
public class InterceptorConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public LoginInterceptor loginInterceptor() {
|
||||||
|
return new LoginInterceptor();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
registry.addInterceptor(new LoginInterceptor())
|
registry.addInterceptor(loginInterceptor())
|
||||||
.addPathPatterns("/index.html/**");
|
.addPathPatterns("/index.html/**");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
package top.weiyuexin.controller;
|
package top.weiyuexin.controller;
|
||||||
|
|
||||||
import cn.hutool.crypto.digest.DigestUtil;
|
import cn.hutool.crypto.digest.DigestUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import top.weiyuexin.pojo.User;
|
import top.weiyuexin.pojo.User;
|
||||||
import top.weiyuexin.pojo.vo.R;
|
import top.weiyuexin.pojo.vo.R;
|
||||||
|
import top.weiyuexin.pojo.vo.UserVo;
|
||||||
import top.weiyuexin.service.ArticleService;
|
import top.weiyuexin.service.ArticleService;
|
||||||
import top.weiyuexin.service.ContestService;
|
import top.weiyuexin.service.ContestService;
|
||||||
import top.weiyuexin.service.ProblemService;
|
import top.weiyuexin.service.ProblemService;
|
||||||
|
@ -132,4 +135,27 @@ public class AdminController {
|
||||||
return R.error("修改失败,请重试");
|
return R.error("修改失败,请重试");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("/user/modifyPassword")
|
||||||
|
@ResponseBody
|
||||||
|
public R modifyPassword(UserVo userVo) {
|
||||||
|
User user = new User();
|
||||||
|
user.setPassword(DigestUtil.md5Hex(userVo.getOldPassword()));
|
||||||
|
user.setUsername(userVo.getUsername());
|
||||||
|
if (user.getId()==null){
|
||||||
|
|
||||||
|
user = userService.getByNameAndPasswordAndIsAdmin(user.getUsername(),user.getPassword());
|
||||||
|
}
|
||||||
|
if (user!=null){
|
||||||
|
user.setPassword(DigestUtil.md5Hex(userVo.getNewPassword()));
|
||||||
|
if (userService.updateById(user)) {
|
||||||
|
return R.success("修改成功");
|
||||||
|
} else {
|
||||||
|
return R.error("修改失败,请重试");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return R.error("密码不正确,请重试");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class EvaluationController {
|
||||||
public W getPage(@RequestParam("page") Integer page,
|
public W getPage(@RequestParam("page") Integer page,
|
||||||
@RequestParam("limit") Integer limit,
|
@RequestParam("limit") Integer limit,
|
||||||
@RequestParam(value = "search", required = false) String search) {
|
@RequestParam(value = "search", required = false) String search) {
|
||||||
|
|
||||||
// IPage<Evaluation> Ipage = evaluationService.getPage(page, limit, evaluation);
|
// IPage<Evaluation> Ipage = evaluationService.getPage(page, limit, evaluation);
|
||||||
// //如果当前页码值大于当前页码值,那么重新执行查询操作,使用最大页码值作为当前页码值
|
// //如果当前页码值大于当前页码值,那么重新执行查询操作,使用最大页码值作为当前页码值
|
||||||
// if (page > Ipage.getPages()) {
|
// if (page > Ipage.getPages()) {
|
||||||
|
@ -65,7 +66,12 @@ public class EvaluationController {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// Ipage.setRecords(evaluations);
|
// Ipage.setRecords(evaluations);
|
||||||
|
if (search==null){
|
||||||
|
search="";
|
||||||
|
}
|
||||||
|
|
||||||
List<Evaluation> list = evaluationService.list(new LambdaQueryWrapper<Evaluation>().orderByDesc(Evaluation::getId));
|
List<Evaluation> list = evaluationService.list(new LambdaQueryWrapper<Evaluation>().orderByDesc(Evaluation::getId));
|
||||||
|
String finalSearch = search;
|
||||||
List<Evaluation> collect = list.stream().filter(x -> {
|
List<Evaluation> collect = list.stream().filter(x -> {
|
||||||
Integer userId = x.getUserId();
|
Integer userId = x.getUserId();
|
||||||
User user = userService.getById(userId);
|
User user = userService.getById(userId);
|
||||||
|
@ -77,7 +83,7 @@ public class EvaluationController {
|
||||||
if (problem != null) {
|
if (problem != null) {
|
||||||
x.setProblemName(problem.getTitle());
|
x.setProblemName(problem.getTitle());
|
||||||
}
|
}
|
||||||
return (user != null && x.getUserName().contains(search)) || (problem != null && x.getProblemName().contains(search) || x.getLanguage().contains(search));
|
return (user != null && x.getUserName().contains(finalSearch)) || (problem != null && x.getProblemName().contains(finalSearch) || x.getLanguage().contains(finalSearch));
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
// 获取分页参数
|
// 获取分页参数
|
||||||
int currentPage = page - 1; // Java下标从0开始,所以需要减1
|
int currentPage = page - 1; // Java下标从0开始,所以需要减1
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package top.weiyuexin.interceptor;
|
package top.weiyuexin.interceptor;
|
||||||
|
|
||||||
|
import cn.hutool.crypto.digest.DigestUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
import top.weiyuexin.service.UserService;
|
||||||
|
|
||||||
import javax.servlet.http.Cookie;
|
import javax.servlet.http.Cookie;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -17,8 +20,12 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
* @Date: 2023/4/27 17:19
|
* @Date: 2023/4/27 17:19
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Component
|
|
||||||
public class LoginInterceptor implements HandlerInterceptor {
|
public class LoginInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
UserService userService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
Cookie[] cookies = request.getCookies();
|
Cookie[] cookies = request.getCookies();
|
||||||
|
@ -33,7 +40,7 @@ public class LoginInterceptor implements HandlerInterceptor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println(username+" "+password);
|
System.out.println(username+" "+password);
|
||||||
if (username==null || password==null){
|
if (username==null || password==null || userService.getByNameAndPasswordAndIsAdmin(username, DigestUtil.md5Hex(password))==null){
|
||||||
response.sendRedirect("/login");
|
response.sendRedirect("/login");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package top.weiyuexin.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserVo {
|
||||||
|
private String username;
|
||||||
|
private String oldPassword;
|
||||||
|
private String newPassword;
|
||||||
|
}
|
|
@ -18,12 +18,12 @@
|
||||||
<div style="margin: 10px 10px 10px 10px">
|
<div style="margin: 10px 10px 10px 10px">
|
||||||
<form class="layui-form layui-form-pane" action="">
|
<form class="layui-form layui-form-pane" action="">
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<div class="layui-inline">
|
<!-- <div class="layui-inline">-->
|
||||||
<label class="layui-form-label">作者</label>
|
<!-- <label class="layui-form-label">作者</label>-->
|
||||||
<div class="layui-input-inline">
|
<!-- <div class="layui-input-inline">-->
|
||||||
<input type="text" name="authorName" autocomplete="off" class="layui-input">
|
<!-- <input type="text" name="authorName" autocomplete="off" class="layui-input">-->
|
||||||
</div>
|
<!-- </div>-->
|
||||||
</div>
|
<!-- </div>-->
|
||||||
<!-- <div class="layui-inline">-->
|
<!-- <div class="layui-inline">-->
|
||||||
<!-- <label class="layui-form-label">标签</label>-->
|
<!-- <label class="layui-form-label">标签</label>-->
|
||||||
<!-- <div class="layui-input-inline">-->
|
<!-- <div class="layui-input-inline">-->
|
||||||
|
@ -116,7 +116,7 @@
|
||||||
if (data.field.title == null) {
|
if (data.field.title == null) {
|
||||||
data.field.title = "";
|
data.field.title = "";
|
||||||
}
|
}
|
||||||
param += "&authorId=" + data.field.authorName;
|
// param += "&title=" + data.field.authorName;
|
||||||
// param += "&type=" + data.field.type;
|
// param += "&type=" + data.field.type;
|
||||||
param += "&title=" + data.field.title;
|
param += "&title=" + data.field.title;
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,12 @@
|
||||||
<div style="margin: 10px 10px 10px 10px">
|
<div style="margin: 10px 10px 10px 10px">
|
||||||
<form class="layui-form layui-form-pane" action="">
|
<form class="layui-form layui-form-pane" action="">
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<div class="layui-inline">
|
<!-- <div class="layui-inline">-->
|
||||||
<label class="layui-form-label">作者</label>
|
<!-- <label class="layui-form-label">作者</label>-->
|
||||||
<div class="layui-input-inline">
|
<!-- <div class="layui-input-inline">-->
|
||||||
<input type="text" name="authorName" autocomplete="off" class="layui-input">
|
<!-- <input type="text" name="authorName" autocomplete="off" class="layui-input">-->
|
||||||
</div>
|
<!-- </div>-->
|
||||||
</div>
|
<!-- </div>-->
|
||||||
<!-- <div class="layui-inline">-->
|
<!-- <div class="layui-inline">-->
|
||||||
<!-- <label class="layui-form-label">标签</label>-->
|
<!-- <label class="layui-form-label">标签</label>-->
|
||||||
<!-- <div class="layui-input-inline">-->
|
<!-- <div class="layui-input-inline">-->
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
<!-- </div>-->
|
<!-- </div>-->
|
||||||
<!-- </div>-->
|
<!-- </div>-->
|
||||||
<div class="layui-inline">
|
<div class="layui-inline">
|
||||||
<label class="layui-form-label">题目</label>
|
<label class="layui-form-label">作者或题目</label>
|
||||||
<div class="layui-input-inline">
|
<div class="layui-input-inline">
|
||||||
<input type="text" name="title" autocomplete="off" class="layui-input">
|
<input type="text" name="title" autocomplete="off" class="layui-input">
|
||||||
</div>
|
</div>
|
||||||
|
@ -116,9 +116,9 @@
|
||||||
if (data.field.title == null) {
|
if (data.field.title == null) {
|
||||||
data.field.title = "";
|
data.field.title = "";
|
||||||
}
|
}
|
||||||
param += "&authorId=" + data.field.authorName;
|
// param += "&authorId=" + data.field.authorName;
|
||||||
// param += "&type=" + data.field.type;
|
// param += "&type=" + data.field.type;
|
||||||
param += "&title=" + data.field.title;
|
param += "&search=" + data.field.title;
|
||||||
|
|
||||||
table.render({
|
table.render({
|
||||||
elem: '#currentTableId',
|
elem: '#currentTableId',
|
||||||
|
|
|
@ -111,7 +111,7 @@
|
||||||
}
|
}
|
||||||
param += "&authorName=" + data.field.authorName;
|
param += "&authorName=" + data.field.authorName;
|
||||||
param += "&type=" + data.field.type;
|
param += "&type=" + data.field.type;
|
||||||
param += "&title=" + data.field.title;
|
param += "&search=" + data.field.title;
|
||||||
|
|
||||||
table.render({
|
table.render({
|
||||||
elem: '#currentTableId',
|
elem: '#currentTableId',
|
||||||
|
|
|
@ -57,6 +57,27 @@
|
||||||
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
|
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
|
||||||
<script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
|
<script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
|
||||||
<script>
|
<script>
|
||||||
|
function getCookie(name) {
|
||||||
|
var nameEQ = name + '=';
|
||||||
|
var ca = document.cookie.split(';');
|
||||||
|
for (var i = 0; i < ca.length; i++) {
|
||||||
|
var c = ca[i];
|
||||||
|
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
|
||||||
|
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setCookie(name, value, days) {
|
||||||
|
var expires = '';
|
||||||
|
if (days) {
|
||||||
|
var date = new Date();
|
||||||
|
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||||
|
expires = '; expires=' + date.toUTCString();
|
||||||
|
}
|
||||||
|
document.cookie = name + '=' + (value || '') + expires + '; path=/';
|
||||||
|
}
|
||||||
|
|
||||||
layui.use(['form', 'miniTab'], function () {
|
layui.use(['form', 'miniTab'], function () {
|
||||||
var form = layui.form,
|
var form = layui.form,
|
||||||
layer = layui.layer,
|
layer = layui.layer,
|
||||||
|
@ -79,15 +100,22 @@
|
||||||
} else if (checkPassword == "") {
|
} else if (checkPassword == "") {
|
||||||
layer.msg("请重新输入确认密码");
|
layer.msg("请重新输入确认密码");
|
||||||
} else if (newPassword == checkPassword) {
|
} else if (newPassword == checkPassword) {
|
||||||
|
let username=getCookie('username');
|
||||||
|
console.log(username)
|
||||||
//使用Ajax提交修改
|
//使用Ajax提交修改
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/user/update", //请求地址
|
url: "/user/modifyPassword", //请求地址
|
||||||
dataType: "json", //数据格式
|
dataType: "json", //数据格式
|
||||||
type: "PUT", //请求方式
|
type: "PUT", //请求方式
|
||||||
async: false,
|
async: false,
|
||||||
data: {"password": newPassword},
|
data: {
|
||||||
|
"newPassword": newPassword,
|
||||||
|
"username": username,
|
||||||
|
"oldPassword": oldPassword,
|
||||||
|
},
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (data.flag) {//删除成功
|
if (data.code===200) {//删除成功
|
||||||
|
setCookie("password", newPassword, -1)
|
||||||
layer.msg("密码修改成功,下次登录时请使用新密码");
|
layer.msg("密码修改成功,下次登录时请使用新密码");
|
||||||
} else {
|
} else {
|
||||||
layer.msg(data.msg)
|
layer.msg(data.msg)
|
||||||
|
@ -96,7 +124,6 @@
|
||||||
error: function (data) {
|
error: function (data) {
|
||||||
layer.msg("服务异常,请联系管理员");
|
layer.msg("服务异常,请联系管理员");
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
//两次输入的密码不同
|
//两次输入的密码不同
|
||||||
|
|
Loading…
Reference in New Issue