use of org.nutz.mvc.annotation.POST in project nutzboot by nutzam.
the class UserJsonModule method add.
@POST
public User add(@Param("name") String name, @Param("age") int age) {
User user = new User();
user.setName(name);
user.setAge(age);
return dao.insert(user);
}
use of org.nutz.mvc.annotation.POST in project nutz by nutzam.
the class UserModule method add.
@POST
@At
public NutMap add(@Param("..") User user) {
NutMap re = new NutMap("ok", false);
if (Strings.isBlank(user.getName()))
return re.setv("msg", "名字不能是空");
if (Strings.isBlank(user.getPassword()))
return re.setv("msg", "密码不能是空");
dao.insert(user);
return re.setv("ok", true);
}
use of org.nutz.mvc.annotation.POST in project nutzboot by nutzam.
the class UserWsModule method add.
@POST
public User add(@Param("name") String name, @Param("age") int age) {
User user = new User();
user.setName(name);
user.setAge(age);
return dao.insert(user);
}
use of org.nutz.mvc.annotation.POST in project nutzboot by nutzam.
the class UserModule method login.
@Ok("json")
@Fail("http:500")
@POST
@At("/login")
public boolean login(@Param("username") String username, @Param("password") String password, HttpSession session) {
User user = dao.fetch(User.class, username);
if (user == null)
return false;
Sha256Hash hash = new Sha256Hash(password, user.getSalt());
if (!hash.toHex().equals(user.getPassword())) {
return false;
}
Subject subject = SecurityUtils.getSubject();
subject.login(new SimpleShiroToken(user.getId()));
return true;
}
use of org.nutz.mvc.annotation.POST 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);
}
Aggregations