use of org.nutz.mvc.annotation.Filters in project nutz by nutzam.
the class UserModule method login.
@Filters
@POST
@At
public NutMap login(String username, String password, HttpSession session) {
NutMap re = new NutMap("ok", false);
if (Strings.isBlank(username) || Strings.isBlank(password)) {
log.debug("username or password is null");
return re.setv("msg", "用户名或密码不能为空");
}
User user = dao.fetch(User.class, username);
if (user == null) {
log.debug("no such user = " + username);
return re.setv("msg", "没有该用户");
}
String tmp = Lang.digest("SHA-256", user.getSalt() + password);
if (!tmp.equals(user.getPassword())) {
log.debug("password is wrong");
return re.setv("msg", "密码错误");
}
session.setAttribute("me", user);
return re.setv("ok", true);
}