package leslie.information_system.controller;
import leslie.information_system.entity.Department;
import leslie.information_system.entity.Student;
import leslie.information_system.exception.StudentException;
import leslie.information_system.service.DepartmentService;
import leslie.information_system.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Controller
public class StudentController {
@Autowired
private StudentService studentService;
@Autowired
private JavaMailSender javaMailSender;
@Autowired
private DepartmentService departmentService;
@PostMapping("/student/regist")
public String regist(Student student, HttpServletRequest request){
try {
studentService.regist(student);
//因为一些后期bug,所以这里先设置部门号为0,即为空。
Department departmentByDepartment_id = departmentService.getDepartmentByDepartment_id(0);
System.out.println(departmentByDepartment_id);
student.setDepartment(departmentByDepartment_id);
System.out.println(student);
studentService.update(student);
//发送激活邮件
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("804738464@qq.com");
message.setTo(student.getStudent_email());
message.setSubject("学生信息系统激活邮件");
message.setText("<html><body><h1>您好,"+student.getStudent_username()+"</h1><a href='http://222.178.203.72:19005/whst/63/_knbZkgnrs97.7.//student/active/"+student.getStudent_id()+"'>请点击进行激活</a></body></html>");
request.setAttribute("msg","激活邮件已经发送,请注意查看");
javaMailSender.send(message);
} catch (StudentException e) {
request.setAttribute("msg",e.getMessage());
return "studentPages/regist";
}
return "studentPages/login";
}
@ResponseBody
@GetMapping("/student/active/{student_id}")
public String acitve(@PathVariable Integer student_id){
studentService.active(student_id);
return "激活成功,请回到登录页面进行登录";
}
@PostMapping("/student/login")
public String login(Student student,HttpServletRequest request){
try {
Student login = studentService.login(student);
request.getSession().setAttribute("student",login);
} catch (StudentException e) {
request.setAttribute("msg",e.getMessage());
return "studentPages/login";
}
return "index";
}
@GetMapping("/student/quit")
public String quit(Integer student_id,HttpServletRequest request){
request.getSession().removeAttribute("student");
return "studentPages/login";
}
@PutMapping("/student/update")
public String update(Student student,Integer department_id,HttpServletRequest request){
Department departmentByDepartment_id = departmentService.getDepartmentByDepartment_id(department_id);
student.setDepartment(departmentByDepartment_id);
studentService.update(student);
request.getSession().setAttribute("student",student);
return "studentPages/changeInformation";
}
//根据系id查询所以学生
@GetMapping("/student/{department_id}")
public String getStudentByDepartment_id(@PathVariable Integer department_id,HttpServletRequest request){
List<Student> studentByDepartment_id = studentService.getStudentByDepartment_id(department_id);
request.setAttribute("studentList",studentByDepartment_id);
return "departmentAdminPages/studentList";
}
@DeleteMapping("/student")
public String deleteStudent(@RequestParam("student_id") Integer student_id){
System.out.println(student_id);
Student student = studentService.getStudentByStudent_id(student_id);
//发送删除告知邮件
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("804738464@qq.com");
message.setTo(student.getStudent_email());
message.setSubject("学生信息系统告知邮件");
message.setText("<html><body><h1>您好,"+student.getStudent_name()+"</h1><br/>系管理员当前已将你的账户信息与成绩信息清空,如有疑问,请联系相关的系管理员");
javaMailSender.send(message);
studentService.deleteStudent(student_id);
return "/departmentAdminPages/index";
}
//忘记密码
@PostMapping("/student/forgetPassword")
public String forgetPassword(@RequestParam("student_username") String student_username,HttpServletRequest request){
Student studentByStudent_name = studentService.getStudentByStudent_name(student_username);
if (studentByStudent_name == null){
request.setAttribute("msg","该用户名不存在,或者已经被系管理员删除");
return "studentPages/login";
}
//发送密码告知邮件
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("804738464@qq.com");
message.setTo(studentByStudent_name.getStudent_email());
message.setSubject("学生信息系统告知邮件");
message.setText("<html><body><h1>您好,"+studentByStudent_name.getStudent_name()+"</h1><br/>你的密码为:"+studentByStudent_name.getStudent_password());
javaMailSender.send(message);
request.setAttribute("msg","邮件已发送");
return "studentPages/login";
}
}
c++服务器开发
- 粉丝: 3182
- 资源: 4461
最新资源
- 多功能数字时钟设计资料.zip
- 基于FX3U源码V8.8的全新PLC程序架构:丰富指令、详细注释,含以太网Modbus功能及多版本源码等,FX3U源码V8.8版 PLC源码 以太网 三灵PLC 全新程序架构,指令丰富,注释详细,赠送
- 肺活量测量仪设计论文资料.zip
- 高灵敏无线探听器电路资料.zip
- 高频电路实训装置毕业设计论文资料.zip
- 给初学单片机的个实验汇编语言对应C语言加说明.zip
- 光纤通信复用技术的研究毕业设计论文资料.zip
- Labview OOP Plug-in框架模板资料:深度解析命令模式与工厂模式的设计实践及操作指南,Labview OOP Plug-in框架模板资料,适合研究学习(涉及到设计模式的命令模式和工厂模
- FX5U PLC以太网通讯实战案例:SOCKET通讯、SLMP协议、伺服电机控制与MODBUS协议应用,FX5UPLC的各种以太网通讯,SOCKET 2台PLC简单通讯 走网线,SLMP协议通讯,J
- 基于ATS单片机和DS的电子万年历设计资料.zip
- 红外遥控电路设计论文资料.zip
- 基于AVR单片机的汽车空调控制系统资料.zip
- 康耐视cognexVisionpro C#二次开发多相机视觉对位框架:实现多相机逻辑运算、运动控制、自动标定及TCP IP通讯,基于康耐视cognexVisionpro用C#二次开发的多相机视觉对位框
- 基于CPLD的三相多波形函数发生器设计论文资料.zip
- 基于CPLD的三相多波形函数发生器论文资料.zip
- 基于AVR及无线收发模块的脉搏监测系统设计论文资料.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈