@At("/active/mail")
@POST
public Object activeMail(@Attr(scope=Scope.SESSION, value="me")int userId,
HttpServletRequest req) {
NutMap re = new NutMap();
UserProfile profile = get(userId);
if (Strings.isBlank(profile.getEmail())) {
return re.setv("ok", false).setv("msg", "你还没有填邮箱啊!");
}
String token = String.format("%s,%s,%s", userId, profile.getEmail(), System.currentTimeMillis());
token = Toolkit._3DES_encode(emailKEY, token.getBytes());
String url = req.getRequestURL() + "?token=" + token;
String html = "如果无法点击,请拷贝一下链接到浏览器中打开验证链接 %s";
html = String.format(html, url, url);
try {
boolean ok = emailService.send(profile.getEmail(), "XXX 验证邮件 by Nutzbook", html);
if (!ok) {
return re.setv("ok", false).setv("msg", "发送失败");
}
} catch (Throwable e) {
log.debug("发送邮件失败", e);
return re.setv("ok", false).setv("msg", "发送失败");
}
return re.setv("ok", true);
}
8 回复
@At("/active/mail")
@POST
public Object activeMail(@Attr(scope=Scope.SESSION, value="me")int userId,
HttpServletRequest req) {
NutMap re = new NutMap();
UserProfile profile = get(userId);
if (Strings.isBlank(profile.getEmail())) {
return re.setv("ok", false).setv("msg", "你还没有填邮箱啊!");
}
String token = String.format("%s,%s,%s", userId, profile.getEmail(), System.currentTimeMillis());
token = Toolkit._3DES_encode(emailKEY, token.getBytes());
String url = req.getRequestURL() + "?token=" + token;
String html = "<div>如果无法点击,请拷贝一下链接到浏览器中打开<p/>验证链接 %s</div>";
html = String.format(html, url, url);
try {
boolean ok = emailService.send(profile.getEmail(), "XXX 验证邮件 by Nutzbook", html);
if (!ok) {
return re.setv("ok", false).setv("msg", "发送失败");
}
} catch (Throwable e) {
log.debug("发送邮件失败", e);
return re.setv("ok", false).setv("msg", "发送失败");
}
return re.setv("ok", true);
}
这样吗?
添加回复
请先登陆