use of com.hfut.entity.AjaxResult in project Workload by amoxu.
the class UserController method forget.
@RequestMapping(value = "/auth/find", produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8", method = { RequestMethod.POST })
@ResponseBody
public // 注册
String forget(HttpServletRequest request) throws Exception {
// System.out.println(account.getName() + " " + account.getPsw() + " " + account.getMail());
Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
String username = request.getParameter("user");
String captcha = request.getParameter("captcha");
if (session.getAttribute("rand") == null || !session.getAttribute("rand").toString().equalsIgnoreCase(captcha)) {
return "{\"status\":1,\"msg\":\"请重新输入验证码!\"}";
}
AjaxResult result = new AjaxResult();
User user = userService.findByName(username);
if (null != user) {
result.ok();
String md5 = Encryp.encryptionStr(new Random().nextInt(256) + new Date().getTime() + username, Encryp.MD5);
result.setMsg(md5);
session.setAttribute("md5", md5);
session.setAttribute("anser", user.getAnswer());
List list = new ArrayList();
list.add(user.getQuestion());
result.setData(list);
}
return JSON.toJSONString(result);
}
use of com.hfut.entity.AjaxResult in project Workload by amoxu.
the class UserController method update.
@RequestMapping(value = "/zone/update", produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8", method = { RequestMethod.POST })
@ResponseBody
public // 重置密码
String update(HttpServletRequest request) throws Exception {
Subject currentUser = SecurityUtils.getSubject();
String name = request.getParameter("name");
String mail = request.getParameter("mail");
String question = request.getParameter("question");
String answer = request.getParameter("answer");
AjaxResult result = new AjaxResult();
String username = currentUser.getPrincipal().toString();
User user = userService.findByName(username);
if (null == user) {
result.failed();
result.setMsg("请重新登录后重试。");
return JSON.toJSONString(result);
}
user.setQuestion(question);
user.setAnswer(answer);
user.setMail(mail);
user.setUser(name);
try {
userService.updateUser(user);
currentUser.logout();
UsernamePasswordToken token = new UsernamePasswordToken(user.getUser(), user.getPassword());
Subject subject = SecurityUtils.getSubject();
// 如果获取不到用户名就是登录失败,但登录失败的话,会直接抛出异常
subject.login(token);
result.ok();
result.setMsg("修改成功。");
return JSON.toJSONString(result);
} catch (Exception e) {
e.printStackTrace();
throw new CustomException("请重新登录后重试。");
}
}
use of com.hfut.entity.AjaxResult in project Workload by amoxu.
the class UserController method reset.
@RequestMapping(value = "/auth/anser", produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8", method = { RequestMethod.POST })
@ResponseBody
public // 重置密码
String reset(HttpServletRequest request) throws Exception {
Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
String username = request.getParameter("user");
String captcha = request.getParameter("captcha");
String md5 = request.getParameter("md5");
String question = request.getParameter("question");
String answer = request.getParameter("answer");
String password = request.getParameter("password");
if (session.getAttribute("rand") == null || !session.getAttribute("rand").toString().equalsIgnoreCase(captcha)) {
return "{\"status\":1,\"msg\":\"请重新输入验证码!\"}";
}
boolean ss = !session.getAttribute("md5").toString().equals(md5);
System.out.println(session.getAttribute("md5").toString());
System.out.println(request.getParameter("md5"));
if (session.getAttribute("MD5") != null && ss) {
return "{\"status\":1,\"msg\":\"请刷新重试!\"}";
}
String psw = Encryp.strDec(password, "amoxu", "amoxu", "amoxu");
System.out.println(psw);
// 加密MD5 32
psw = Encryp.encryptionStr(psw + "amoxu", Encryp.MD5);
AjaxResult result = new AjaxResult();
try {
User user = userService.findByName(username);
if (user.getAnswer() != null && user.getAnswer().equals(answer) && user.getQuestion().equals(question)) {
user.setPassword(psw);
userService.updateUser(user);
currentUser.logout();
System.out.println(psw);
result.ok();
result.setMsg("修改成功,重新登录。");
return JSON.toJSONString(result);
} else {
result.failed();
result.setMsg("答案错误。");
return JSON.toJSONString(result);
}
} catch (Exception e) {
throw new CustomException("请检查数据是否正确");
}
}
Aggregations