@Resource
private EmployeeService employeeService;
//登录功能
@PostMapping("/login")
public R<Employee> login(HttpServletRequest request, @RequestBody Employee employee){
String password=employee.getPassword();
//MD5加密
password=DigestUtils.md5DigestAsHex(password.getBytes());
//2查数据库
LambdaQueryWrapper<Employee> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Employee::getUsername,employee.getUsername());
Employee one = employeeService.getOne(queryWrapper);
//3判断
if (one==null){
return R.error("登录失败");
}
//4比对密码
if (!one.getPassword().equals(password)){
return R.error("登录失败");
}
//5查状态
if (one.getStatus()==0){
return R.error("账号已禁用");
}
//6登录成功
request.getSession().setAttribute("employee",one.getId());
return R.success(one);
}
//退出系统
@PostMapping("/logout")
public R<String> logout(HttpServletRequest request){
//清理session中保存的登录员工的id
request.getSession().removeAttribute("employee");
return R.success("退出成功");
}