|
|
@@ -2,11 +2,13 @@ package com.uas.sso.uu.controller;
|
|
|
|
|
|
import com.uas.sso.controller.BaseController;
|
|
|
import com.uas.sso.core.PasswordStrength;
|
|
|
+import com.uas.sso.entity.Token;
|
|
|
import com.uas.sso.entity.User;
|
|
|
import com.uas.sso.service.UserService;
|
|
|
import com.uas.sso.util.PasswordLevelUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
@@ -24,7 +26,7 @@ public class ImResetPasswordController extends BaseController {
|
|
|
private UserService userService;
|
|
|
|
|
|
/**
|
|
|
- * 获取验证码
|
|
|
+ * 通过手机号找回密码,获取验证码
|
|
|
* @param mobile 用户手机号
|
|
|
* @return token
|
|
|
*/
|
|
|
@@ -35,7 +37,7 @@ public class ImResetPasswordController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 校验验证码
|
|
|
+ * 通过手机号找回密码,校验验证码
|
|
|
* @param token 获取验证码返回的token
|
|
|
* @param mobile 获取验证码的手机号
|
|
|
* @param code 用户输入的验证码
|
|
|
@@ -48,7 +50,7 @@ public class ImResetPasswordController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 重置密码
|
|
|
+ * 通过手机号找回密码,重置密码
|
|
|
* @param mobile 获取验证码的手机号
|
|
|
* @param token 获取验证码返回的token
|
|
|
* @param code 用户输入的验证码
|
|
|
@@ -80,4 +82,55 @@ public class ImResetPasswordController extends BaseController {
|
|
|
// 返回成功
|
|
|
return success();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过邮箱修改密码,获取图片验证码
|
|
|
+ * @mobile 手机号
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getEmail", method = RequestMethod.GET)
|
|
|
+ public ModelMap getEmail(String mobile) {
|
|
|
+ // 获取用户邮箱
|
|
|
+ User user = userService.findByMobile(mobile);
|
|
|
+ if (user == null) {
|
|
|
+ return error("该号码未注册");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(user.getEmail())) {
|
|
|
+ return error("该账号未设置邮箱");
|
|
|
+ }
|
|
|
+
|
|
|
+ Token token = new Token(user.getUserUU(), 60*60);
|
|
|
+ tokenService.save(token);
|
|
|
+ ModelMap data = new ModelMap();
|
|
|
+ data.put("email", user.getEmail());
|
|
|
+ data.put("token", token.getId());
|
|
|
+ return success(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送邮件
|
|
|
+ * @param token
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/sendEmail", method = RequestMethod.GET)
|
|
|
+ public ModelMap sendEmail(String token) {
|
|
|
+ Token existToken = tokenService.findOne(token);
|
|
|
+ if (existToken == null) {
|
|
|
+ return error("用户信息过期,请重新校验");
|
|
|
+ }
|
|
|
+ User user = userService.findOne((Long) existToken.getBind());
|
|
|
+
|
|
|
+ int expires = 7*24*60*60;
|
|
|
+ Token tk = new Token(existToken.getBind(), expires);
|
|
|
+ tokenService.save(tk);
|
|
|
+ ModelMap data = new ModelMap();
|
|
|
+ data.put("vipName", user.getVipName());
|
|
|
+ data.put("type", "密码重置");
|
|
|
+ // TODO 邮件认证地址
|
|
|
+ data.put("url", getFrontUrl() + "/reset/passwordResetValidQuestion?token="+tk.getId());
|
|
|
+
|
|
|
+ sendEmail("templateForSendMailWhenResetPassword", user.getEmail(), data);
|
|
|
+ tokenService.delete(token);
|
|
|
+ return success();
|
|
|
+ }
|
|
|
+
|
|
|
}
|