public static String randomPasswd(User usr) { String passwd = R.sg(10).next(); String slat = R.sg(48).next(); usr.setSalt(slat); usr.setPassword(passwordEncode(passwd, slat)); return passwd; }
@At("/passwd/reset/callback") public Object resetPasswdCallback(String token) { PasswordReset reset = dao.fetch(PasswordReset.class, Cnd.where("token", "=", token)); if (reset != null) { dao.clear(PasswordReset.class, Cnd.where("token", "=", token)); if (System.currentTimeMillis() - reset.getCreateTime().getTime() > 30 * 60 * 1000) return Ajax.fail().setMsg("token is expise"); String passwd = R.sg(12).next(); dao.update( User.class, Chain.make("passwd", xMD5(passwd)), Cnd.where("id", "=", reset.getUid())); String email = dao.fetch(User.class, Cnd.where("id", "=", reset.getUid())).getEmail(); mailService.add2Queue(email, "推爸密码重置邮件", "Your password : "******"Reset success!! Check you email!"); } return Ajax.fail().setMsg("Token not found!!"); }
@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!!"); } } } }