Search in sources :

Example 1 with Ok

use of org.nutz.mvc.annotation.Ok in project nutzboot by nutzam.

the class MainLauncher method make.

@AdaptBy(type = JsonAdaptor.class)
@At("/maker/make")
@Ok("json:full")
public NutMap make(@Param("..") NutMap params) throws IOException {
    NutMap re = new NutMap();
    String key = R.UU32();
    File tmpRoot = Files.createDirIfNoExists(tmpDir + "/" + key);
    build(tmpRoot, params);
    re.put("key", key);
    re.put("ok", true);
    return re;
}
Also used : File(java.io.File) NutMap(org.nutz.lang.util.NutMap) At(org.nutz.mvc.annotation.At) AdaptBy(org.nutz.mvc.annotation.AdaptBy) Ok(org.nutz.mvc.annotation.Ok)

Example 2 with Ok

use of org.nutz.mvc.annotation.Ok in project nutzboot by nutzam.

the class MainLauncher method index.

@At({ "/", "/index" })
@Ok("vm:/index.vm")
public NutMap index() {
    NutMap obj = new NutMap();
    obj.setv("name", "牛牪犇").setv("age", 18);
    return obj;
}
Also used : NutMap(org.nutz.lang.util.NutMap) At(org.nutz.mvc.annotation.At) Ok(org.nutz.mvc.annotation.Ok)

Example 3 with Ok

use of org.nutz.mvc.annotation.Ok 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 4 with Ok

use of org.nutz.mvc.annotation.Ok in project nutzboot by nutzam.

the class UserModule method apitest.

/**
 * 这是演示api调用的入口,会顺序调用一堆请求,请关注日志
 */
@Ok("raw")
@At
public String apitest() {
    List<User> users = userService.list();
    log.info("users=" + Json.toJson(users));
    User haoqoo = userService.add("haoqoo", 19);
    User wendal = userService.add("wendal", 28);
    users = userService.list();
    log.info("users=" + Json.toJson(users));
    userService.delete(haoqoo.getId());
    userService.delete(wendal.getId());
    users = userService.list();
    log.info("users=" + Json.toJson(users));
    return "done";
}
Also used : User(io.nutz.demo.feign.bean.User) At(org.nutz.mvc.annotation.At) Ok(org.nutz.mvc.annotation.Ok)

Example 5 with Ok

use of org.nutz.mvc.annotation.Ok in project nutzcloud by nutzam.

the class UserModule method apitest.

/**
 * 这是演示api调用的入口,会顺序调用一堆请求,请关注日志
 */
@Ok("raw")
@At
public String apitest() {
    List<User> users = userService.list();
    log.info("users=" + Json.toJson(users));
    User haoqoo = userService.add("haoqoo", 19);
    User wendal = userService.add("wendal", 28);
    users = userService.list();
    log.info("users=" + Json.toJson(users));
    userService.delete(haoqoo.getId());
    userService.delete(wendal.getId());
    users = userService.list();
    log.info("users=" + Json.toJson(users));
    return "done";
}
Also used : User(io.nutz.cloud.demo.bean.User) At(org.nutz.mvc.annotation.At) Ok(org.nutz.mvc.annotation.Ok)

Aggregations

At (org.nutz.mvc.annotation.At)6 Ok (org.nutz.mvc.annotation.Ok)6 NutMap (org.nutz.lang.util.NutMap)2 User (io.nutz.cloud.demo.bean.User)1 User (io.nutz.demo.feign.bean.User)1 User (io.nutz.demo.simple.bean.User)1 File (java.io.File)1 Sha256Hash (org.apache.shiro.crypto.hash.Sha256Hash)1 Subject (org.apache.shiro.subject.Subject)1 SimpleShiroToken (org.nutz.integration.shiro.SimpleShiroToken)1 Stopwatch (org.nutz.lang.Stopwatch)1 AdaptBy (org.nutz.mvc.annotation.AdaptBy)1 Fail (org.nutz.mvc.annotation.Fail)1 POST (org.nutz.mvc.annotation.POST)1