package com.itcgg.smartschool.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itcgg.smartschool.pojo.Admin;
import com.itcgg.smartschool.pojo.LoginForm;
import com.itcgg.smartschool.pojo.Student;
import com.itcgg.smartschool.pojo.Teacher;
import com.itcgg.smartschool.service.AdminService;
import com.itcgg.smartschool.service.StudentService;
import com.itcgg.smartschool.service.TeacherService;
import com.itcgg.smartschool.util.*;
import com.sun.deploy.net.HttpRequest;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
@RestController
@RequestMapping("/sms/system")
public class SystemController {
@Autowired
private AdminService adminService;
@Autowired
private TeacherService teacherService;
@Autowired
private StudentService studentService;
@ApiOperation("更新用户密码")
@PostMapping("/updatePwd/{oldPwd}/{newPwd}")
public Result updatePwd(@RequestHeader("token") String token,
@PathVariable("oldPwd") String oldPwd,
@PathVariable("newPwd") String newPwd){
boolean expiration = JwtHelper.isExpiration(token);
if (expiration){
return Result.fail().message("token失效,请重新登录在修改密码");
}
//获取用户id和类型
Long userId = JwtHelper.getUserId(token);
Integer userType = JwtHelper.getUserType(token);
//密码加密
oldPwd= MD5.encrypt(oldPwd);
newPwd= MD5.encrypt(newPwd);
switch (userType){
case 1:
QueryWrapper<Admin> queryWrapper1=new QueryWrapper<>();
queryWrapper1.eq("id",userId.intValue());
queryWrapper1.eq("password",oldPwd);
Admin admin =adminService.getOne(queryWrapper1);
if (admin != null){
// 修改
admin.setPassword(newPwd);
adminService.saveOrUpdate(admin);
}else{
return Result.fail().message("原密码有误!");
}
break;
case 2:
QueryWrapper<Teacher> queryWrapper2=new QueryWrapper<>();
queryWrapper2.eq("id",userId.intValue());
queryWrapper2.eq("password",oldPwd);
Teacher teacher = teacherService.getOne(queryWrapper2);
if (teacher!=null){
//修改密码
teacher.setPassword(newPwd);
teacherService.saveOrUpdate(teacher);
}else {
return Result.fail().message("原密码有误");
}
break;
case 3:
QueryWrapper<Student> queryWrapper3=new QueryWrapper<>();
queryWrapper3.eq("id",userId.intValue());
queryWrapper3.eq("password",oldPwd);
Student student =studentService.getOne(queryWrapper3);
if (student!=null){
student.setPassword(newPwd);
studentService.saveOrUpdate(student);
}else {
return Result.fail().message("原密码有错误");
}
break;
}
return Result.ok();
}
/*@ApiOperation("文件上传")
@PostMapping("/headerImgUpload")
public Result getHeaderImgUpload(@RequestPart("multipartFile") MultipartFile multipartFile,
HttpServletRequest request){
//修改文件名
String uuid = UUID.randomUUID().toString().replace("-","").toLowerCase();
String originalFilename = multipartFile.getOriginalFilename();
int i = originalFilename.lastIndexOf(".");
String newFielName=uuid.concat(originalFilename.substring(i));
//保存文件 将文件发送到第三方/独立的图片服务器
String portraitPath ="D:/springboot_project/smartschool/target/classes/public.upload".concat(newFielName);
try {
multipartFile.transferTo(new File(portraitPath));
} catch (IOException e) {
e.printStackTrace();
}
// request.getServletContext().getRealPath("public/upload");实际路径
//响应图片
String path="upload/".concat(newFielName);
return Result.ok(path);
}*/
@ApiOperation("文件上传统一入口")
@PostMapping("/headerImgUpload")
public Result headerImgUpload(
@ApiParam("头像文件") @RequestPart("multipartFile") MultipartFile multipartFile
,
HttpServletRequest request
){
String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
String originalFilename = multipartFile.getOriginalFilename();
int i = originalFilename.lastIndexOf(".");
String newFileName =uuid.concat(originalFilename.substring(i));
// 保存文件 将文件发送到第三方/独立的图片服务器上,
String portraitPath="D:/springboot_project/smartschool/target/classes/public/upload/".concat(newFileName);
try {
multipartFile.transferTo(new File(portraitPath));
} catch (IOException e) {
e.printStackTrace();
}
// 响应图片的路径
String path="upload/".concat(newFileName);
return Result.ok(path);
}
@GetMapping("/getInfo")
public Result getInfoByToken(@RequestHeader("token") String token){
boolean expiration = JwtHelper.isExpiration(token);
if (expiration){
return Result.build(null, ResultCodeEnum.CODE_ERROR);
}
//从token中解析出用户id和用户类型
Long userId = JwtHelper.getUserId(token);
Integer userType = JwtHelper.getUserType(token);
Map<String,Object> map = new LinkedHashMap<>();
switch (userType){
case 1:
Admin admin = adminService.getAdminById(userId);
map.put("userType",1);
map.put("user",admin);
break;
case 2:
Student student = studentService.getStudentById(userId);
map.put("userType",2);
map.put("user",student);
break;
case 3:
Teacher teacher = teacherService.getTeacherById(userId);
map.put("userType",3);
map.put("user",teacher);
break;
}
return Result.ok(map);
}
//登录接口
@PostMapping("/login")
public Result login (@RequestBody LoginForm loginForm,HttpServletRequest request){
//验证码校验
HttpSession session =request.getSession();
String sessionVerificode = (String)session.getAttribute("verifiCode");
String loginVerifiCode = loginForm.getVerifiCode();
if ("".equals(sessionVerificode)||null==sessionVerificode){
return Result.fail().message("验证码失败,请刷新后重试");
}
if (!sessionVerificode.equalsIgnoreCase(loginVerifiCode)){
return Result.fail().message("验证码有误,请小心输入");
}
//从session域中移除现有验证码
session.removeAttribute("verifiCode");
//分用户校验
//准备一个map存放响应数据
// Map<String,Object> map=new linkedHashMap<>();
Map<String, Object
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于vue+springboot的智慧校园管理系统源码+数据库.zip 该项目是个人大作业项目源码,评审分达到95分以上,都经过严格调试,确保可以运行!放心下载使用。 基于vue+springboot的智慧校园管理系统源码+数据库.zip 该项目是个人大作业项目源码,评审分达到95分以上,都经过严格调试,确保可以运行!放心下载使用。基于vue+springboot的智慧校园管理系统源码+数据库.zip 该项目是个人大作业项目源码,评审分达到95分以上,都经过严格调试,确保可以运行!放心下载使用。基于vue+springboot的智慧校园管理系统源码+数据库.zip 该项目是个人大作业项目源码,评审分达到95分以上,都经过严格调试,确保可以运行!放心下载使用。基于vue+springboot的智慧校园管理系统源码+数据库.zip 该项目是个人大作业项目源码,评审分达到95分以上,都经过严格调试,确保可以运行!放心下载使用。基于vue+springboot的智慧校园管理系统源码+数据库.zip 该项目是个人大作业项目源码,评审分达到95分以上,都经过严格调试,确保可以运行!
资源推荐
资源详情
资源评论
收起资源包目录
基于vue+springboot的智慧校园管理系统源码.zip (81个子文件)
基于vue+springboot的智慧校园管理系统源码
mvnw.cmd 7KB
sql
db_smartschool.sql 11KB
pom.xml 4KB
src
test
java
com
itcgg
smartschool
SmartschoolApplicationTests.java 227B
main
resources
public
upload
default.jpg 48KB
static
permission.json 166B
favicon.ico 66KB
index.html 5KB
images
logo.png 41KB
default.jpg 3KB
static
js
chunk-elementUI.edb7fc53.js 500KB
chunk-libs.9892d939.js 261KB
chunk-01081519.06d2caa6.js 12KB
chunk-96a4e134.ba975cc5.js 621B
chunk-24890d62.13705e10.js 10KB
chunk-417b88dd.20c43d0c.js 12KB
chunk-299dfd1b.644f9fcc.js 1KB
app.c9219e63.js 103KB
chunk-2c5071da.266f37e1.js 4KB
chunk-62446ae8.5a21e53b.js 8KB
chunk-35d45b48.4f5531a8.js 10KB
chunk-4ce4e6a0.aa96c8ff.js 9KB
default.jpg 17KB
img
404.a57b6f31.png 96KB
bg.7285dd88.jpg 178KB
404_cloud.0f4bc32b.png 5KB
css
chunk-2c5071da.97dec6d1.css 2KB
chunk-417b88dd.6d26ba5b.css 335B
chunk-01081519.6d26ba5b.css 335B
chunk-96a4e134.2654d086.css 369B
app.2a150c78.css 12KB
chunk-elementUI.751bfb5e.css 183KB
chunk-299dfd1b.0c55c6b3.css 5KB
chunk-35d45b48.6d26ba5b.css 335B
chunk-4ce4e6a0.71911e6b.css 3KB
chunk-libs.3dfb7769.css 3KB
fonts
element-icons.535877f5.woff 28KB
element-icons.732389de.ttf 55KB
menus.json 1KB
application.yml 957B
java
com
itcgg
smartschool
mapper
TeacherMapper.java 264B
ClazzMapper.java 258B
GradeMapper.java 258B
StudentMapper.java 264B
AdminMapper.java 306B
controller
GradeController.java 2KB
AdminController.java 2KB
ClazzController.java 2KB
TeacherController.java 2KB
SystemController.java 11KB
StudentController.java 2KB
pojo
Teacher.java 728B
Clazz.java 848B
Admin.java 663B
Grade.java 748B
Student.java 742B
LoginForm.java 283B
service
ClazzService.java 437B
AdminService.java 514B
StudentService.java 529B
GradeService.java 443B
TeacherService.java 533B
impl
GradeServiceImpl.java 1KB
TeacherServiceImpl.java 2KB
ClazzServiceImpl.java 1KB
AdminServiceImpl.java 2KB
StudentServiceImpl.java 2KB
SmartschoolApplication.java 336B
util
MD5.java 1KB
CreateVerifiCodeImage.java 3KB
Result.java 2KB
AuthContextHolder.java 715B
ResultCodeEnum.java 1KB
JwtHelper.java 3KB
UploadFile.java 4KB
config
Swagger2Config.java 3KB
MyConfig.java 717B
.mvn
wrapper
maven-wrapper.properties 1019B
maven-wrapper.jar 59KB
mvnw 10KB
.gitignore 395B
共 81 条
- 1
资源评论
- 飘了·2024-11-21发现一个宝藏资源,资源有很高的参考价值,赶紧学起来~
- Jayshenjy2024-04-10发现一个宝藏资源,资源有很高的参考价值,赶紧学起来~
- 90后晚年大叔2024-06-03这个资源内容超赞,对我来说很有价值,很实用,感谢大佬分享~
盈梓的博客
- 粉丝: 9275
- 资源: 2197
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功