package com.wu.project20.Controller;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.wu.project20.Mapper.ManagerMapper;
import com.wu.project20.Mapper.ScoreDao;
import com.wu.project20.Mapper.StudentMapper;
import com.wu.project20.Mapper.TeacherMapper;
import com.wu.project20.Result.*;
import com.wu.project20.Token.TokenTools;
import com.wu.project20.bean.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@RestController
public class CommonController {
@Autowired
StudentMapper studentMapper;
@Autowired
ScoreDao scoreDao ;
@Autowired
TeacherMapper teacherMapper ;
@Autowired
ManagerMapper managerMapper ;
TokenTools tokenTools = new TokenTools() ;
/*
* 学生登录,username为学号,password为密码,生成token,
* 用学号+密码+时间生成token。存进数据库里面,成为验证的一项重大工具
* */
@RequestMapping(method = RequestMethod.POST , value = "user/login")
@CrossOrigin(methods = { RequestMethod.GET, RequestMethod.POST }, origins = "*")
@ResponseBody
public ResultToken studentLogin(HttpServletRequest request, @RequestBody StudentHtml studentHtml){
String username = studentHtml.getUsername();
String password = studentHtml.getPassword();/*
String username = request.getParameter("username");
String password = request.getParameter("password");*/
Meta meta = new Meta();
int role = 0;
if(studentMapper.studentExist(username)==1){
role = 1;
if(password.trim().equals(studentMapper.getPassword(username).trim())){
String token = tokenTools.createToken(username,password,String.valueOf(role));
studentMapper.CreateToken(token,username);//将token传到数据库,进行保存。
meta.setMessage("登录成功");
meta.setStatus(200);
return new ResultToken(token,meta);
}
}
if (teacherMapper.teacherExist(username)==1) {
role = 2;
if (password.trim().equals(teacherMapper.getPassword(username).trim())) {
String token = tokenTools.createToken(username, password, String.valueOf(role));
teacherMapper.CreateToken(token, username);//将token传到数据库,进行保存。
meta.setMessage("登录成功");
meta.setStatus(200);
return new ResultToken(token, meta);
}
}
if (managerMapper.managerExist(username)==1) {
role = 3;
if (password.trim().equals(managerMapper.getPassword(username).trim())) {
String token = tokenTools.createToken(username, password, String.valueOf(role));
managerMapper.CreateToken(token, username);//将token传到数据库,进行保存。
meta.setMessage("登录成功");
meta.setStatus(200);
return new ResultToken(token, meta);
}
}
meta.setMessage("登录失败");
meta.setStatus(400);
return new ResultToken(null,meta) ;
}
@RequestMapping(method = RequestMethod.GET ,value = "user/menulist")
@CrossOrigin(methods = { RequestMethod.GET, RequestMethod.POST }, origins = "*")
@ResponseBody
public ResultMenu getMenu(HttpServletRequest request){
String token = request.getHeader("Authorization");
DecodedJWT jwt = tokenTools.decodeToken(token);
String id = jwt.getClaim("id").asString();
String role = jwt.getClaim("role").asString();
Meta meta = new Meta();
if(role.equals("1")){
if(token.trim().equals(studentMapper.SelectToken(id))) {
meta.setMessage("获取成功");
meta.setStatus(200);
return new ResultMenu(getMenuList(role),meta);
}
}
else if(token.trim().equals(teacherMapper.SelectTeacherToken(id))) {
meta.setMessage("获取成功");
meta.setStatus(200);
return new ResultMenu(getMenuList(role),meta);
}
return null;
}
/*
* 通过点击个人信息一栏,通过传入的token,进行解码,解出id,
* 查询出id所对应的token,看是否相等,等,则将个人信息进行返回。*/
@RequestMapping(method = RequestMethod.GET ,value = "user/getpersonalinfo")
@CrossOrigin(methods = { RequestMethod.GET, RequestMethod.POST }, origins = "*")
@ResponseBody
public ResultInformation studentInformation(HttpServletRequest request){
String token = request.getHeader("Authorization");
DecodedJWT jwt = tokenTools.decodeToken(token);
String id = jwt.getClaim("id").asString();
String role = jwt.getClaim("role").asString();
Meta meta = new Meta();
if(role.equals("1")){
if(token.trim().equals(studentMapper.SelectToken(id))){
meta.setMessage("获取成功");
meta.setStatus(200);
return new ResultInformation(studentMapper.SelectID(id),null,null,meta);
}
}else if(role.equals("2")){
if(token.trim().equals(teacherMapper.SelectTeacherToken(id))){
meta.setMessage("获取成功");
meta.setStatus(200);
return new ResultInformation(null,teacherMapper.SelectTeacher(id),null,meta);
}
}
meta.setMessage("获取失败");
meta.setStatus(400);
return new ResultInformation(null,null,null,meta);
}
/*
* 修改密码
* 通过进行对token的验证,利用反解出的id,进行对密码的修改*/
@RequestMapping(method = RequestMethod.POST , value = "user/updatepassword")
@CrossOrigin(methods = { RequestMethod.GET, RequestMethod.POST }, origins = "*")
@ResponseBody
public ResultStudent updateStudent(HttpServletRequest request, @RequestBody StudentHtml studentHtml ){
String token = request.getHeader("Authorization");
DecodedJWT jwt = tokenTools.decodeToken(token);
String id = jwt.getClaim("id").asString();
String password = jwt.getClaim("password").asString();
String role = jwt.getClaim("role").asString() ;
String oldPassword = studentHtml.getOldPassword();
Meta meta = new Meta();
if(role.equals("1")){
if(token.trim().equals(studentMapper.SelectToken(id))){
if(password.equals(oldPassword)){
String newPassword = studentHtml.getNewPassword();
/*String password = studentHtml.getPassword*/
studentMapper.updatestudent(newPassword,id);
meta.setMessage("修改成功");
meta.setStatus(200);
return new ResultStudent(null,meta);
}
meta.setMessage("修改失败");
meta.setStatus(403);
return new ResultStudent(null,meta);
}
}
if(role.equals("2")){
if(token.trim().equals(teacherMapper.SelectTeacherToken(id))){
if(password.equals(oldPassword)){
String newPassword = studentHtml.getNewPassword();
/*String password = studentHtml.getPassword*/
teacherMapper.updateTeacher(id,newPassword);
meta.setMessage("修改成功");
meta.setStatus(200);
return new ResultStudent(null,meta);
没有合适的资源?快使用搜索试试~ 我知道了~
基于微信小程序的课程学习小程序后端程序
共411个文件
xml:105个
java:51个
class:50个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 9 下载量 133 浏览量
2022-03-19
21:08:26
上传
评论 3
收藏 30.38MB ZIP 举报
温馨提示
基于微信小程序的课程学习小程序后端程序
资源推荐
资源详情
资源评论
收起资源包目录
基于微信小程序的课程学习小程序后端程序 (411个子文件)
0164ee2be615c4ba00d64653ec00be3f1a02c6 160B
01bcbb9624a350f6a1a55c3908b62e98d24f9c 44B
02c553ff701ec0837ea4b0d521a90315d39e19 7KB
02d4b2b70a676a93460824c0130c5b7e324c1e 182B
039e017b82665112a01e3b864cd050c1937966 51B
0453cb7901213b9b7d7db3a4affbee3691772c 517B
04ba62c9de2aa905444f5071d683d43fd70f8a 158B
0594f5a01378c472cf0d0f0430ad6bb4813b58 223B
085c568e536b2ee99222ab652a92d7ed618c2a 204B
0ce7bcd648a626b74ff920ff30e3856803ac02 46B
168c71bbcc874e817b7b8a6032f5bf896c8a41 173KB
1e1b4f8149403f979ca6f68fae28bd29cc049e 7KB
206e3862ad3cb6c46b431095107853adb624a5 452B
224307a12c0659941d1a59854b478e1b5c01c3 636B
22614ee5069087bdf4d4f81e60505d114509d1 1KB
23b7a495d9840a0e91c7a7708f56ed6d8c5c08 79B
273459f4d60caa166f62e68b39c7d038b90f6c 54B
27af36f6ddbc9835b4d7ecebccead10a1fd126 197B
29068051294804d85c5cc0cde792dfbc310860 2KB
2977cb510383fc03153c4e774deb73176a5c52 207B
29b177c2b3a185d6020061424189adb7ab8a75 177B
2b9ebd7c54a4360091b8969fc615e0056f288f 252B
2d572ce90e5085986bdd9c9204b9404f028084 130B
2ede2efb7040f9ce8328d8cd0f2eebc3ecf654 22KB
2f71bf7f262c2469fbf245ab4d6f228b7bf8de 4KB
31853c72c2596eafc43b12681e5bd67eb4fd31 291B
3769135cdd7f9224772575acd9651df6d6ba75 3KB
37f7a653661d1d7738a96e7806cbada1e65d8e 762B
392022f008bb15782b80a29f07173a472cc62d 839B
3ad9d717c3cf7bfe625df481ddcb2b2125eeac 457KB
3bebac5c69c4065bb240b7074b52766c3a3b11 88B
3cd8cbb9ed389c7964f9e2a66a9b90b1605638 422B
40496161ad88922dba2c1887e5ce0da5bd030a 62B
4475e5c56750888ba6186346d65e8b41a6294a 46KB
48e9b5b3cd9ce9115b5c599e5e31fb5eb1c579 333B
4c3e9e4a477016b89d7d12077c8728c0798b7c 187B
4d7a62ac4ff755f9dbd1b22992e27f9c3439cc 234B
4f7341a20e4de7d252f8aaeb2b689720dd3c35 46B
52b0cda6e67a718fa335d8baee092491fe4a90 344B
54136aca3d6d3617baa0040035e44b5007b19b 159B
553eeb126a982e7d9637a309a20056d4b0a143 4KB
57ae2a43b05b212d496566bb14cb507b9527e1 177B
58c125505ad31ce4b95923401df5da570ecdfe 58B
5a0daa4973590bf79da30289cb2fa6b2063707 200B
5a287234ee86c44af76282a8aa7e5ff3eaf4af 1KB
5eb6ba269cd38f8965cef786729790945d9537 2KB
6237b4aa0bf89a0d8524e1bf3fcf84503f3413 74B
625645fa4a8a8e922464f104e84fc5d6faf7d4 3KB
6b5431b4c3cab50323a3f558003fd0abd87dad 3KB
6d33271e57e0d0bda5743845275bc8c114e566 189B
6f366d637955b61744c550f956ca2035fc15b0 187B
7456f135d5840feae5dbc9837b7dbc4e88a9ad 641B
7a9db1c79fe6a06c8e55dbc6e4d3a875e8c0a1 74B
7e53ea14fad4ef36fdedab2680e2aadc6bd1d7 243B
7e64dfbaa0c9a28c026cc3b007a3155985ba0f 374B
7ee42cd1021d9f0315fd0f8779eceb3ba1f96b 38KB
84f124fde4d1aa497e9099e55c2062449ae18b 547B
8790bac18e9ce229343a87a3f2424cdf8b4b8a 192B
8889c18fd000f0afe4e974298f8d28bf5d7912 197B
916c40ceb9e22a2fe7e5d0ad6c24befa6214e7 70KB
9c5d5401d4ffd39d22000f46de9b5133892d37 93B
9f09d4ec191302d04b04dbe4b795c100210b83 108B
a3040aa86debfd8826d9c2b5c816314c17d9fe 235B
a7e3bf6e2e809c05e2ef16bcf02a0a3c42bfa4 32KB
a8d31e4596cbb6ce4de3e41013b21201326ecb 216B
b043159fc5fcf2e42c4cdedf5aaa7fce25055e 117B
b51ccc9dfe08b8cc7197c158e76ec4244fa862 2KB
b6ee02a394410bb8a0816960f77ab3193a53dd 217B
b7393d3e5e3938da512064d5cd86600c7bc281 181B
b9a2539e425a7a8c244faba92527602be76212 28KB
bcf815749541445ee5bea7ef56a2a59ef3fe4e 42KB
bf4cf610648943581817557053739d932c2ca6 50B
c057458550ef5f0e061e0bf10c05bae94aa6e2 894B
c07fd803b5fc9c54f44e31123ae4fa11e134b0 35KB
c4d790c1400daa3a4ac1d5913ac53e399e5689 2KB
c5b5a33ab856629748dba686540870da73e89f 3KB
c7d4a55c0cd0092912bf49ae38b3a9e3fd0054 43KB
c8dff3876c0e5e03c72b81f748c5ee3fe7e0d9 1006B
cc2dcea6e10ef4b64a6f8930d5c2f4cd3c9da7 774B
CommonController.class 13KB
TeacherController.class 12KB
StudentController.class 11KB
StudentMapper.class 7KB
TeacherMapper.class 5KB
Student.class 4KB
Teacher.class 4KB
ScoreController.class 3KB
Exam.class 3KB
ResultChoiceRecord.class 3KB
choiceRecord.class 3KB
ResultQuestion.class 3KB
Score.class 3KB
TokenTools.class 2KB
DruidConfig.class 2KB
Time.class 2KB
UnZip.class 2KB
MyConfig.class 2KB
StudentHtml.class 2KB
ResultChoiceQuestionList.class 2KB
ResultStudentAnalysis.class 2KB
共 411 条
- 1
- 2
- 3
- 4
- 5
曾许人间第一流.
- 粉丝: 18
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (源码)基于Spring Boot框架的博客系统.zip
- (源码)基于Spring Boot框架的博客管理系统.zip
- (源码)基于ESP8266和Blynk的IR设备控制系统.zip
- (源码)基于Java和JSP的校园论坛系统.zip
- (源码)基于ROS Kinetic框架的AGV激光雷达导航与SLAM系统.zip
- (源码)基于PythonDjango框架的资产管理系统.zip
- (源码)基于计算机系统原理与Arduino技术的学习平台.zip
- (源码)基于SSM框架的大学消息通知系统服务端.zip
- (源码)基于Java Servlet的学生信息管理系统.zip
- (源码)基于Qt和AVR的FestosMechatronics系统终端.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页