Search in sources :

Example 1 with POST

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);
}
Also used : User(io.nutz.demo.feign.bean.User) POST(org.nutz.mvc.annotation.POST)

Example 2 with POST

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);
}
Also used : NutMap(org.nutz.lang.util.NutMap) At(org.nutz.mvc.annotation.At) POST(org.nutz.mvc.annotation.POST)

Example 3 with POST

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);
}
Also used : User(io.nutz.demo.feign.bean.User) POST(org.nutz.mvc.annotation.POST)

Example 4 with POST

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;
}
Also used : User(io.nutz.demo.simple.bean.User) Sha256Hash(org.apache.shiro.crypto.hash.Sha256Hash) SimpleShiroToken(org.nutz.integration.shiro.SimpleShiroToken) Subject(org.apache.shiro.subject.Subject) At(org.nutz.mvc.annotation.At) POST(org.nutz.mvc.annotation.POST) Ok(org.nutz.mvc.annotation.Ok) Fail(org.nutz.mvc.annotation.Fail)

Example 5 with POST

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);
}
Also used : User(net.wendal.nutzdemo.bean.User) NutMap(org.nutz.lang.util.NutMap) Filters(org.nutz.mvc.annotation.Filters) At(org.nutz.mvc.annotation.At) POST(org.nutz.mvc.annotation.POST)

Aggregations

POST (org.nutz.mvc.annotation.POST)5 At (org.nutz.mvc.annotation.At)3 User (io.nutz.demo.feign.bean.User)2 NutMap (org.nutz.lang.util.NutMap)2 User (io.nutz.demo.simple.bean.User)1 User (net.wendal.nutzdemo.bean.User)1 Sha256Hash (org.apache.shiro.crypto.hash.Sha256Hash)1 Subject (org.apache.shiro.subject.Subject)1 SimpleShiroToken (org.nutz.integration.shiro.SimpleShiroToken)1 Fail (org.nutz.mvc.annotation.Fail)1 Filters (org.nutz.mvc.annotation.Filters)1 Ok (org.nutz.mvc.annotation.Ok)1