|
@@ -57,6 +57,11 @@ public class AdminController {
|
|
|
// System.out.println(pwdMD5);
|
|
|
// System.out.println(admin.getPwd());
|
|
|
if(pwdMD5.equalsIgnoreCase(admin.getPwd())){
|
|
|
+ if(admin.getStatus()<0){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.ACCESS_DENIED);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
String token = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
admin.setToken(token);
|
|
|
adminService.Update(admin);
|
|
@@ -112,33 +117,42 @@ public class AdminController {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ @RequestMapping(value = "/register", method = RequestMethod.POST)
|
|
|
+ public void Register(HttpServletRequest request, HttpServletResponse response, @RequestBody Admin admin){
|
|
|
+ InsertUpdate(request, response, admin);
|
|
|
+ }
|
|
|
+
|
|
|
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
|
|
public void Update(HttpServletRequest request, HttpServletResponse response, @RequestBody Admin admin){
|
|
|
-
|
|
|
+ InsertUpdate(request, response, admin);
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/register", method = RequestMethod.POST)
|
|
|
- public void Insert(HttpServletRequest request, HttpServletResponse response, Admin admin){
|
|
|
- String name = admin.getName();
|
|
|
- String pwd = admin.getPwd();
|
|
|
-
|
|
|
- if(name==null || name.length()<4 || pwd==null || pwd.length()<4){
|
|
|
- HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
|
|
|
- return;
|
|
|
+ public void InsertUpdate(HttpServletRequest request, HttpServletResponse response, Admin admin){
|
|
|
+ if(admin.getId()==null){
|
|
|
+ String name = admin.getName();
|
|
|
+ String pwd = admin.getPwd();
|
|
|
+
|
|
|
+ if(name==null || name.length()<4 || pwd==null || pwd.length()<4){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Admin> list = adminService.SearchByName(name);
|
|
|
+ if(list!=null && list.size()>0){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.RECORD_EXIST);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ admin.setCreated(new Date());
|
|
|
}
|
|
|
- String salt = UUID.randomUUID().toString().replaceAll("-","");
|
|
|
- String token = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
- String pwdMD5 = Common.getMD5(Common.getMD5(pwd) + salt);
|
|
|
-
|
|
|
- List<Admin> list = adminService.SearchByName(name);
|
|
|
- if(list!=null && list.size()>0){
|
|
|
- HttpUtil.responseApiCode(request, response, ApiCode.RECORD_EXIST);
|
|
|
- return;
|
|
|
+ if(admin.getPwd()!=null){
|
|
|
+ String pwd = admin.getPwd();
|
|
|
+ String salt = UUID.randomUUID().toString().replaceAll("-","");
|
|
|
+ String token = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ String pwdMD5 = Common.getMD5(Common.getMD5(pwd) + salt);
|
|
|
+ admin.setPwd(pwdMD5);
|
|
|
+ admin.setSalt(salt);
|
|
|
+ admin.setToken(token);
|
|
|
}
|
|
|
- admin.setPwd(pwdMD5);
|
|
|
- admin.setSalt(salt);
|
|
|
- admin.setToken(token);
|
|
|
- admin.setCreated(new Date());
|
|
|
+
|
|
|
admin = adminService.Insert(admin);
|
|
|
SaveRedis(admin);
|
|
|
|