@Filters(@By(type = AjaxCheckSession.class, args = "me")) @At("/update") public Object updateInfo( String nickName, String passwd, @Attr("me") User me, HttpSession session) { if (!Strings.isBlank(nickName) && !nickName.startsWith("_") // 系统默认生成的nickName以_开头 && me.getNickName().startsWith("_") // 只允许修改一次nickName && nickName.trim().length() > 1 && nickName.trim().length() < 10 && nickName.indexOf("<") < 0 && nickName.indexOf(">") < 0 && nickName.indexOf("@") < 0 && nickName.indexOf("#") < 0 && nickName.indexOf(" ") < 0 && nickName.indexOf("&") < 0) { try { dao.update( User.class, Chain.make("nickName", nickName.trim()), Cnd.where("id", "=", me.getId())); } catch (Throwable e) { return Ajax.fail().setMsg("Nickname is dup or it is BAD!"); } } if (!Strings.isBlank(passwd) && passwd.trim().length() > 5 && passwd.trim().length() < 40) { dao.update( User.class, Chain.make("passwd", xMD5(passwd.trim())), Cnd.where("id", "=", me.getId())); } session.setAttribute("me", dao.fetch(User.class, Cnd.where("id", "=", me.getId()))); return Ajax.ok(); }
@At("/passwd/reset") public void resetPassword(String email, HttpServletRequest req) { if (Strings.isBlank(email)) return; User user = dao.fetch(User.class, Cnd.where("email", "=", email)); if (user == null) return; dao.clear(PasswordReset.class, Cnd.where("uid", "=", user.getId())); String token = R.UU64() + R.UU64(); PasswordReset reset = new PasswordReset(); reset.setUid(dao.fetch(User.class, Cnd.where("email", "=", email)).getId()); reset.setToken(token); dao.insert(reset); String url = req.getRequestURL() + "/callback?token=" + token; mailService.add2Queue(email, "推爸 密码重置请求", "Reset URL --> " + url); }
@At public Object reg(@Param("email") String email) { if (Strings.isBlank(email) || !Strings.isEmail(email)) { return Ajax.fail().setMsg("email is blank or invaild!"); } else { if (0 != dao.count(User.class, Cnd.where("email", "=", email))) { return Ajax.fail().setMsg("email is exist!"); } else { final User me = new User(); me.setEmail(email); String passwd = R.sg(12).next(); me.setPasswd(xMD5(passwd)); me.setNickName("_" + me.getNickName()); dao.insert(me); if (mailService.add2Queue(email, "推爸注册确认邮件", "Your password : "******"Fail to send comfig email!!"); } } } }