|
@@ -16,6 +16,7 @@ import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
@@ -24,6 +25,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
|
import java.util.Enumeration;
|
|
import java.util.Enumeration;
|
|
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
@Controller
|
|
@Controller
|
|
@@ -63,18 +65,21 @@ public class UserController {
|
|
|
*/
|
|
*/
|
|
|
@RequestMapping(value = "/api/code", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
|
|
@RequestMapping(value = "/api/code", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
- public String getAuthCode(String email) {
|
|
|
|
|
- ResponseResult<String> responseResult = new ResponseResult<String>();
|
|
|
|
|
|
|
+ public String getAuthCode(@RequestBody Map<String, Object> emailMap) {
|
|
|
|
|
+ String email = String.valueOf(emailMap.get("email"));
|
|
|
|
|
+ ResponseResult<Boolean> responseResult = new ResponseResult<Boolean>();
|
|
|
|
|
+ responseResult.setContent(false);
|
|
|
responseResult.setMessage("获取验证码失败");
|
|
responseResult.setMessage("获取验证码失败");
|
|
|
String code = CodeGenerator.getInstance().getRandomCode();
|
|
String code = CodeGenerator.getInstance().getRandomCode();
|
|
|
- int result = new EmailTool().sendEmail("吾记温馨提醒您,您的6位验证码(5分钟内有效)是:" + code, email);
|
|
|
|
|
|
|
+ int result = new EmailTool().sendEmail("拾贝温馨提醒您,您的6位验证码(5分钟内有效)是:" + code, email);
|
|
|
if (result == EmailTool.SUCCESS) {
|
|
if (result == EmailTool.SUCCESS) {
|
|
|
mCodeMap.put(email, System.currentTimeMillis()+"-"+code);
|
|
mCodeMap.put(email, System.currentTimeMillis()+"-"+code);
|
|
|
- responseResult.setResultCode(ResultCode.SUCCESS);
|
|
|
|
|
|
|
+ responseResult.setCode(ResultCode.SUCCESS);
|
|
|
responseResult.setMessage("获取验证码成功");
|
|
responseResult.setMessage("获取验证码成功");
|
|
|
|
|
+ responseResult.setContent(true);
|
|
|
responseResult.setExtra(SecureManager.KEY_FOR_CLIENT + "=" + SecureManager.IV_FOR_CLIENT);
|
|
responseResult.setExtra(SecureManager.KEY_FOR_CLIENT + "=" + SecureManager.IV_FOR_CLIENT);
|
|
|
} else {
|
|
} else {
|
|
|
- responseResult.setResultCode(ResultCode.FAILED_COMMON);
|
|
|
|
|
|
|
+ responseResult.setCode(ResultCode.FAILED_COMMON);
|
|
|
responseResult.setMessage("获取验证码失败");
|
|
responseResult.setMessage("获取验证码失败");
|
|
|
}
|
|
}
|
|
|
return JSON.toJSONString(responseResult);
|
|
return JSON.toJSONString(responseResult);
|
|
@@ -87,13 +92,13 @@ public class UserController {
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
public String register(String email, String password, String code, String nickName) {
|
|
public String register(String email, String password, String code, String nickName) {
|
|
|
ResponseResult<User> responseResult = new ResponseResult<User>();
|
|
ResponseResult<User> responseResult = new ResponseResult<User>();
|
|
|
- responseResult.setResultCode(ResultCode.FAILED_COMMON);
|
|
|
|
|
|
|
+ responseResult.setCode(ResultCode.FAILED_COMMON);
|
|
|
responseResult.setMessage("注册失败");
|
|
responseResult.setMessage("注册失败");
|
|
|
|
|
|
|
|
// 从数据库查询,如果没有这个email并且不在黑名单里,才可以继续注册
|
|
// 从数据库查询,如果没有这个email并且不在黑名单里,才可以继续注册
|
|
|
User dbUser = userRepository.findUserByEmail(email);
|
|
User dbUser = userRepository.findUserByEmail(email);
|
|
|
if (dbUser != null) {
|
|
if (dbUser != null) {
|
|
|
- responseResult.setResultCode(ResultCode.FAILED_USER_ALREADY_EXIST);
|
|
|
|
|
|
|
+ responseResult.setCode(ResultCode.FAILED_USER_ALREADY_EXIST);
|
|
|
responseResult.setMessage("该邮箱已被使用");
|
|
responseResult.setMessage("该邮箱已被使用");
|
|
|
return JSON.toJSONString(responseResult);
|
|
return JSON.toJSONString(responseResult);
|
|
|
}
|
|
}
|
|
@@ -131,9 +136,9 @@ public class UserController {
|
|
|
userRepository.save(user);
|
|
userRepository.save(user);
|
|
|
|
|
|
|
|
user.setPassword("");
|
|
user.setPassword("");
|
|
|
- responseResult.setResultCode(ResultCode.SUCCESS);
|
|
|
|
|
|
|
+ responseResult.setCode(ResultCode.SUCCESS);
|
|
|
responseResult.setMessage("注册成功");
|
|
responseResult.setMessage("注册成功");
|
|
|
- responseResult.setResultObj(user);
|
|
|
|
|
|
|
+ responseResult.setContent(user);
|
|
|
|
|
|
|
|
// 注册成功,从内存中移除相应的验证码,节省资源
|
|
// 注册成功,从内存中移除相应的验证码,节省资源
|
|
|
mCodeMap.remove(email);
|
|
mCodeMap.remove(email);
|
|
@@ -154,7 +159,7 @@ public class UserController {
|
|
|
public String getAES() {
|
|
public String getAES() {
|
|
|
ResponseResult responseResult = new ResponseResult();
|
|
ResponseResult responseResult = new ResponseResult();
|
|
|
responseResult.setExtra(SecureManager.KEY_FOR_CLIENT + "=" + SecureManager.IV_FOR_CLIENT);
|
|
responseResult.setExtra(SecureManager.KEY_FOR_CLIENT + "=" + SecureManager.IV_FOR_CLIENT);
|
|
|
- responseResult.setResultCode(ResultCode.SUCCESS);
|
|
|
|
|
|
|
+ responseResult.setCode(ResultCode.SUCCESS);
|
|
|
return JSON.toJSONString(responseResult);
|
|
return JSON.toJSONString(responseResult);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -189,9 +194,9 @@ public class UserController {
|
|
|
userRepository.save(user);
|
|
userRepository.save(user);
|
|
|
|
|
|
|
|
user.setPassword("");
|
|
user.setPassword("");
|
|
|
- responseResult.setResultCode(ResultCode.SUCCESS);
|
|
|
|
|
|
|
+ responseResult.setCode(ResultCode.SUCCESS);
|
|
|
responseResult.setMessage("登录成功");
|
|
responseResult.setMessage("登录成功");
|
|
|
- responseResult.setResultObj(user);
|
|
|
|
|
|
|
+ responseResult.setContent(user);
|
|
|
|
|
|
|
|
return JSON.toJSONString(responseResult);
|
|
return JSON.toJSONString(responseResult);
|
|
|
}
|
|
}
|
|
@@ -208,11 +213,11 @@ public class UserController {
|
|
|
if (user == null || !TextUtils.equals(token, user.getToken())) {
|
|
if (user == null || !TextUtils.equals(token, user.getToken())) {
|
|
|
// 拿到token就可以拿到token的有效时间,以后可以做过期校验
|
|
// 拿到token就可以拿到token的有效时间,以后可以做过期校验
|
|
|
responseResult.setMessage("请重新登录");
|
|
responseResult.setMessage("请重新登录");
|
|
|
- responseResult.setResultCode(ResultCode.FAILED_NEED_RE_LOGIN);
|
|
|
|
|
|
|
+ responseResult.setCode(ResultCode.FAILED_NEED_RE_LOGIN);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
responseResult.setMessage("token登录成功");
|
|
responseResult.setMessage("token登录成功");
|
|
|
- responseResult.setResultCode(ResultCode.SUCCESS);
|
|
|
|
|
|
|
+ responseResult.setCode(ResultCode.SUCCESS);
|
|
|
return JSON.toJSONString(responseResult);
|
|
return JSON.toJSONString(responseResult);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -223,13 +228,13 @@ public class UserController {
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
public String resetPassword(String email, String code, String password) {
|
|
public String resetPassword(String email, String code, String password) {
|
|
|
ResponseResult<User> responseResult = new ResponseResult<User>();
|
|
ResponseResult<User> responseResult = new ResponseResult<User>();
|
|
|
- responseResult.setResultCode(ResultCode.FAILED_COMMON);
|
|
|
|
|
|
|
+ responseResult.setCode(ResultCode.FAILED_COMMON);
|
|
|
responseResult.setMessage("密码重置失败");
|
|
responseResult.setMessage("密码重置失败");
|
|
|
|
|
|
|
|
// 从数据库查询,如果有这个email并且不在黑名单里,才可以继续
|
|
// 从数据库查询,如果有这个email并且不在黑名单里,才可以继续
|
|
|
User dbUser = userRepository.findUserByEmail(email);
|
|
User dbUser = userRepository.findUserByEmail(email);
|
|
|
if (dbUser == null) {
|
|
if (dbUser == null) {
|
|
|
- responseResult.setResultCode(ResultCode.FAILED_USER_NOT_EXIST);
|
|
|
|
|
|
|
+ responseResult.setCode(ResultCode.FAILED_USER_NOT_EXIST);
|
|
|
responseResult.setMessage("用户不存在");
|
|
responseResult.setMessage("用户不存在");
|
|
|
return JSON.toJSONString(responseResult);
|
|
return JSON.toJSONString(responseResult);
|
|
|
}
|
|
}
|
|
@@ -264,9 +269,9 @@ public class UserController {
|
|
|
|
|
|
|
|
// 这种是不是会导致密码被修改为空。答案:不会
|
|
// 这种是不是会导致密码被修改为空。答案:不会
|
|
|
dbUser.setPassword("");
|
|
dbUser.setPassword("");
|
|
|
- responseResult.setResultCode(ResultCode.SUCCESS);
|
|
|
|
|
|
|
+ responseResult.setCode(ResultCode.SUCCESS);
|
|
|
responseResult.setMessage("密码重置成功");
|
|
responseResult.setMessage("密码重置成功");
|
|
|
- responseResult.setResultObj(dbUser);
|
|
|
|
|
|
|
+ responseResult.setContent(dbUser);
|
|
|
|
|
|
|
|
// 注册成功,从内存中移除相应的验证码,节省资源
|
|
// 注册成功,从内存中移除相应的验证码,节省资源
|
|
|
mCodeMap.remove(email);
|
|
mCodeMap.remove(email);
|
|
@@ -283,7 +288,7 @@ public class UserController {
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
public String saveBgInfo(String email, String token, int mode, MultipartFile file) {
|
|
public String saveBgInfo(String email, String token, int mode, MultipartFile file) {
|
|
|
ResponseResult<String> responseResult = new ResponseResult<String>();
|
|
ResponseResult<String> responseResult = new ResponseResult<String>();
|
|
|
- responseResult.setResultCode(ResultCode.FAILED_COMMON);
|
|
|
|
|
|
|
+ responseResult.setCode(ResultCode.FAILED_COMMON);
|
|
|
responseResult.setMessage("上传背景失败");
|
|
responseResult.setMessage("上传背景失败");
|
|
|
|
|
|
|
|
//String bgDir = request.getSession().getServletContext().getRealPath("bg") + File.separator;
|
|
//String bgDir = request.getSession().getServletContext().getRealPath("bg") + File.separator;
|
|
@@ -305,7 +310,7 @@ public class UserController {
|
|
|
out.flush();
|
|
out.flush();
|
|
|
out.close();
|
|
out.close();
|
|
|
|
|
|
|
|
- responseResult.setResultCode(ResultCode.SUCCESS);
|
|
|
|
|
|
|
+ responseResult.setCode(ResultCode.SUCCESS);
|
|
|
responseResult.setMessage("上传背景成功");
|
|
responseResult.setMessage("上传背景成功");
|
|
|
|
|
|
|
|
// 更新用户的theme mode(4为自定义)
|
|
// 更新用户的theme mode(4为自定义)
|
|
@@ -354,7 +359,7 @@ public class UserController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
responseResult.setMessage("用户模式更新成功");
|
|
responseResult.setMessage("用户模式更新成功");
|
|
|
- responseResult.setResultCode(ResultCode.SUCCESS);
|
|
|
|
|
|
|
+ responseResult.setCode(ResultCode.SUCCESS);
|
|
|
return JSON.toJSONString(responseResult);
|
|
return JSON.toJSONString(responseResult);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|