|
|
@ -17,7 +17,9 @@ import java.util.Date; |
|
|
|
|
|
|
|
|
|
|
|
@RestController |
|
|
|
@RestController |
|
|
|
@RequestMapping("/api/manager") |
|
|
|
@RequestMapping("/api/manager") |
|
|
|
|
|
|
|
//客户端跨域测试
|
|
|
|
@CrossOrigin("http://localhost:4200") |
|
|
|
@CrossOrigin("http://localhost:4200") |
|
|
|
|
|
|
|
//管理员接口
|
|
|
|
public class ManagerController { |
|
|
|
public class ManagerController { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
@ -25,22 +27,25 @@ public class ManagerController { |
|
|
|
|
|
|
|
|
|
|
|
// 登陆
|
|
|
|
// 登陆
|
|
|
|
@PostMapping("login") |
|
|
|
@PostMapping("login") |
|
|
|
@ResponseBody |
|
|
|
|
|
|
|
public Res<Token> login(@RequestBody ManagerLogin managerLogin){ |
|
|
|
public Res<Token> login(@RequestBody ManagerLogin managerLogin){ |
|
|
|
if(StringUtils.isEmpty(managerLogin.getManagerName())){ |
|
|
|
if(StringUtils.isEmpty(managerLogin.getManagerName())){ |
|
|
|
return new Res<>(Result.FAIL,"管理员不能为空!",null); |
|
|
|
return new Res<>(Result.FAIL,"管理员不能为空!",null); |
|
|
|
}else if(StringUtils.isEmpty(managerLogin.getPassword())){ |
|
|
|
}else if(StringUtils.isEmpty(managerLogin.getPassword())){ |
|
|
|
return new Res<>(Result.FAIL,"密码不能为空!",null); |
|
|
|
return new Res<>(Result.FAIL,"密码不能为空!",null); |
|
|
|
|
|
|
|
//校验账号密码
|
|
|
|
}else if(!managerDao.login(managerLogin)){ |
|
|
|
}else if(!managerDao.login(managerLogin)){ |
|
|
|
return new Res<>(Result.FAIL,"账号或密码错误!",null); |
|
|
|
return new Res<>(Result.FAIL,"账号或密码错误!",null); |
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
else{ |
|
|
|
|
|
|
|
// 验证通过生成令牌响应给服务端
|
|
|
|
Token token=new Token(); |
|
|
|
Token token=new Token(); |
|
|
|
Calendar c=Calendar.getInstance(); |
|
|
|
Calendar c=Calendar.getInstance(); |
|
|
|
c.setTime(new Date()); |
|
|
|
c.setTime(new Date()); |
|
|
|
token.setCreateTime(c.getTimeInMillis()); |
|
|
|
token.setCreateTime(c.getTimeInMillis()); |
|
|
|
|
|
|
|
// 令牌有效时间1小时
|
|
|
|
c.add(Calendar.HOUR,1); |
|
|
|
c.add(Calendar.HOUR,1); |
|
|
|
token.setUseTime(c.getTimeInMillis()); |
|
|
|
token.setUseTime(c.getTimeInMillis()); |
|
|
|
|
|
|
|
// 生成token
|
|
|
|
token.setToken(DigestUtils.md5DigestAsHex((token.getCreateTime()+""+token.getUseTime()+"").getBytes())); |
|
|
|
token.setToken(DigestUtils.md5DigestAsHex((token.getCreateTime()+""+token.getUseTime()+"").getBytes())); |
|
|
|
return new Res<>(Result.OK,"登陆成功",token); |
|
|
|
return new Res<>(Result.OK,"登陆成功",token); |
|
|
|
} |
|
|
|
} |
|
|
@ -48,7 +53,6 @@ public class ManagerController { |
|
|
|
|
|
|
|
|
|
|
|
// 注册
|
|
|
|
// 注册
|
|
|
|
@PostMapping("register") |
|
|
|
@PostMapping("register") |
|
|
|
@ResponseBody |
|
|
|
|
|
|
|
public Res<String> register(@RequestBody ManagerRegister manager){ |
|
|
|
public Res<String> register(@RequestBody ManagerRegister manager){ |
|
|
|
if(StringUtils.isEmpty(manager.getManagerName())){ |
|
|
|
if(StringUtils.isEmpty(manager.getManagerName())){ |
|
|
|
return new Res<>(Result.FAIL,"管理员不能为空",null); |
|
|
|
return new Res<>(Result.FAIL,"管理员不能为空",null); |
|
|
@ -65,6 +69,7 @@ public class ManagerController { |
|
|
|
}else if(managerDao.hasUser(manager.getManagerName())){ |
|
|
|
}else if(managerDao.hasUser(manager.getManagerName())){ |
|
|
|
return new Res<>(Result.FAIL,"用户已存在",null); |
|
|
|
return new Res<>(Result.FAIL,"用户已存在",null); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
|
|
|
|
// 表单数据转换到管理员实体,调用dao层持久化到数据库
|
|
|
|
Manager m=new Manager(); |
|
|
|
Manager m=new Manager(); |
|
|
|
m.setManagerName(manager.getManagerName()); |
|
|
|
m.setManagerName(manager.getManagerName()); |
|
|
|
m.setPassword(DigestUtils.md5DigestAsHex(manager.getPassword().getBytes())); |
|
|
|
m.setPassword(DigestUtils.md5DigestAsHex(manager.getPassword().getBytes())); |
|
|
|