Search in sources :

Example 1 with JSON

use of com.blade.mvc.annotation.JSON in project tale by otale.

the class LinksController method saveLink.

@Route(value = "save", method = HttpMethod.POST)
@JSON
public RestResponse saveLink(@QueryParam String title, @QueryParam String url, @QueryParam String logo, @QueryParam Integer mid, @QueryParam(value = "sort", defaultValue = "0") int sort) {
    try {
        Metas metas = new Metas();
        metas.setName(title);
        metas.setSlug(url);
        metas.setDescription(logo);
        metas.setSort(sort);
        metas.setType(Types.LINK);
        if (null != mid) {
            metas.setMid(mid);
            metasService.update(metas);
        } else {
            metasService.saveMeta(metas);
        }
        siteService.cleanCache(Types.C_STATISTICS);
    } catch (Exception e) {
        String msg = "友链保存失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
    return RestResponse.ok();
}
Also used : Metas(com.tale.model.Metas) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Example 2 with JSON

use of com.blade.mvc.annotation.JSON in project tale by otale.

the class AuthController method doLogin.

@Route(value = "login", method = HttpMethod.POST)
@JSON
public RestResponse doLogin(@QueryParam String username, @QueryParam String password, @QueryParam String remeber_me, Request request, Session session, Response response) {
    Integer error_count = cache.get("login_error_count");
    try {
        error_count = null == error_count ? 0 : error_count;
        if (null != error_count && error_count > 3) {
            return RestResponse.fail("您输入密码已经错误超过3次,请10分钟后尝试");
        }
        Users user = usersService.login(username, password);
        session.attribute(TaleConst.LOGIN_SESSION_KEY, user);
        if (StringKit.isNotBlank(remeber_me)) {
            TaleUtils.setCookie(response, user.getUid());
        }
        Users temp = new Users();
        temp.setUid(user.getUid());
        temp.setLogged(DateKit.getCurrentUnixTime());
        usersService.update(temp);
        LOGGER.info("登录成功:{}", JSONKit.toJSONString(request.querys()));
        cache.set("login_error_count", 0);
        logService.save(LogActions.LOGIN, JSONKit.toJSONString(request.querys()), request.address(), user.getUid());
    } catch (Exception e) {
        error_count += 1;
        cache.set("login_error_count", error_count, 10 * 60);
        String msg = "登录失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
    return RestResponse.ok();
}
Also used : Users(com.tale.model.Users) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Example 3 with JSON

use of com.blade.mvc.annotation.JSON in project tale by otale.

the class CommentController method delete.

/**
     * 删除一条评论
     * @param coid
     * @return
     */
@Route(value = "delete", method = HttpMethod.POST)
@JSON
public RestResponse delete(@QueryParam Integer coid) {
    try {
        Comments comments = commentsService.byId(coid);
        if (null == comments) {
            return RestResponse.fail("不存在该评论");
        }
        commentsService.delete(coid, comments.getCid());
        siteService.cleanCache(Types.C_STATISTICS);
    } catch (Exception e) {
        String msg = "评论删除失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
    return RestResponse.ok();
}
Also used : Comments(com.tale.model.Comments) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Example 4 with JSON

use of com.blade.mvc.annotation.JSON in project tale by otale.

the class CommentController method delete.

@Route(value = "status", method = HttpMethod.POST)
@JSON
public RestResponse delete(@QueryParam Integer coid, @QueryParam String status) {
    try {
        Comments comments = new Comments();
        comments.setCoid(coid);
        comments.setStatus(status);
        commentsService.update(comments);
        siteService.cleanCache(Types.C_STATISTICS);
    } catch (Exception e) {
        String msg = "操作失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
    return RestResponse.ok();
}
Also used : Comments(com.tale.model.Comments) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Example 5 with JSON

use of com.blade.mvc.annotation.JSON in project tale by otale.

the class IndexController method upPwd.

/**
     * 修改密码
     */
@Route(value = "password", method = HttpMethod.POST)
@JSON
public RestResponse upPwd(@QueryParam String old_password, @QueryParam String password, Request request) {
    Users users = this.user();
    if (StringKit.isBlank(old_password) || StringKit.isBlank(password)) {
        return RestResponse.fail("请确认信息输入完整");
    }
    if (!users.getPassword().equals(Tools.md5(users.getUsername() + old_password))) {
        return RestResponse.fail("旧密码错误");
    }
    if (password.length() < 6 || password.length() > 14) {
        return RestResponse.fail("请输入6-14位密码");
    }
    try {
        Users temp = new Users();
        temp.setUid(users.getUid());
        String pwd = Tools.md5(users.getUsername() + password);
        temp.setPassword(pwd);
        usersService.update(temp);
        logService.save(LogActions.UP_PWD, null, request.address(), this.getUid());
        return RestResponse.ok();
    } catch (Exception e) {
        String msg = "密码修改失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
}
Also used : Users(com.tale.model.Users) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Aggregations

JSON (com.blade.mvc.annotation.JSON)14 Route (com.blade.mvc.annotation.Route)13 TipException (com.tale.exception.TipException)12 Users (com.tale.model.Users)6 Config (com.blade.kit.base.Config)3 Comments (com.tale.model.Comments)3 Attach (com.tale.model.Attach)2 IOException (java.io.IOException)2 BladeException (com.blade.exception.BladeException)1 RestController (com.blade.mvc.annotation.RestController)1 FileItem (com.blade.mvc.multipart.FileItem)1 ModelAndView (com.blade.mvc.view.ModelAndView)1 RestResponse (com.blade.mvc.view.RestResponse)1 BackResponse (com.tale.dto.BackResponse)1 Metas (com.tale.model.Metas)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1