Search in sources :

Example 26 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class BloggerGalleryController method delete.

/**
 * 从设备和数据库中删除图片
 */
@RequestMapping(value = "/{pictureId}", method = RequestMethod.DELETE)
@ResponseBody
public ResultBean delete(HttpServletRequest request, @PathVariable("bloggerId") Integer bloggerId, @PathVariable("pictureId") Integer pictureId) {
    handleBloggerSignInCheck(request, bloggerId);
    BloggerPicture picture = bloggerPictureService.getPicture(pictureId, bloggerId);
    if (picture == null) {
        throw exceptionManager.getUnknownPictureException(new RequestContext(request));
    }
    // 检查权限
    if (!validateManager.checkBloggerPictureLegal(bloggerId, picture.getCategory()))
        throw exceptionManager.getUnauthorizedException(new RequestContext(request));
    boolean succ = bloggerPictureService.deletePicture(bloggerId, picture.getId(), true);
    if (!succ)
        handlerOperateFail(request);
    return new ResultBean<>("");
}
Also used : BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture) RequestContext(org.springframework.web.servlet.support.RequestContext) ResultBean(com.duan.blogos.restful.ResultBean)

Example 27 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class BloggerLoginController method loginWithPhoneNumber.

@RequestMapping(value = "/way=phone", method = RequestMethod.POST)
public ResultBean loginWithPhoneNumber(HttpServletRequest request, @RequestParam("phone") String phone) {
    handlePhoneCheck(phone, request);
    BloggerAccount account = accountService.getAccountByPhone(phone);
    if (account == null)
        return new ResultBean<>("", ResultBean.FAIL);
    HttpSession session = request.getSession();
    session.setAttribute(bloggerProperties.getSessionNameOfBloggerId(), account.getId());
    session.setAttribute(bloggerProperties.getSessionNameOfBloggerName(), account.getUsername());
    session.setAttribute(bloggerProperties.getSessionBloggerLoginSignal(), "login");
    // 成功登录
    return new ResultBean<>(account.getUsername());
}
Also used : BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) HttpSession(javax.servlet.http.HttpSession) ResultBean(com.duan.blogos.restful.ResultBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 28 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class BloggerLoginController method loginWithUserName.

@RequestMapping(value = "/way=name", method = RequestMethod.POST)
public ResultBean loginWithUserName(HttpServletRequest request, @RequestParam("username") String userName, @RequestParam("password") String password) throws NoSuchAlgorithmException {
    // TODO 使用shiro
    BloggerAccount account = accountService.getAccount(userName);
    if (account != null && account.getUsername().equals(userName) && account.getPassword().equals(new BigInteger(StringUtils.toSha(password)).toString())) {
        HttpSession session = request.getSession();
        session.setAttribute(bloggerProperties.getSessionNameOfBloggerId(), account.getId());
        session.setAttribute(bloggerProperties.getSessionNameOfBloggerName(), account.getUsername());
        session.setAttribute(bloggerProperties.getSessionBloggerLoginSignal(), "login");
        // 成功登录
        return new ResultBean<>("");
    } else {
        // TODO 判断登录失败的原因
        String errorMsg = messageManager.getLoginFailMessage(new RequestContext(request), false);
        request.getServletContext().setAttribute(bloggerProperties.getSessionNameOfErrorMsg(), errorMsg);
        return new ResultBean(exceptionManager.getLoginFailException(new RequestContext(request), false));
    }
}
Also used : BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) HttpSession(javax.servlet.http.HttpSession) BigInteger(java.math.BigInteger) RequestContext(org.springframework.web.servlet.support.RequestContext) ResultBean(com.duan.blogos.restful.ResultBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ResultBean (com.duan.blogos.restful.ResultBean)28 RequestContext (org.springframework.web.servlet.support.RequestContext)12 Blog (com.duan.blogos.entity.blog.Blog)5 BloggerAccount (com.duan.blogos.entity.blogger.BloggerAccount)5 BloggerPicture (com.duan.blogos.entity.blogger.BloggerPicture)5 HttpSession (javax.servlet.http.HttpSession)5 BlogCategory (com.duan.blogos.entity.blog.BlogCategory)4 ArrayList (java.util.ArrayList)4 BlogListItemDTO (com.duan.blogos.dto.blog.BlogListItemDTO)3 BloggerDTO (com.duan.blogos.dto.blogger.BloggerDTO)3 BloggerProfile (com.duan.blogos.entity.blogger.BloggerProfile)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 BloggerCategoryDTO (com.duan.blogos.dto.blogger.BloggerCategoryDTO)2 FavouriteBlogListItemDTO (com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO)2 BlogLabel (com.duan.blogos.entity.blog.BlogLabel)2 BlogStatistics (com.duan.blogos.entity.blog.BlogStatistics)2 BlogListItemComparatorFactory (com.duan.blogos.manager.comparator.BlogListItemComparatorFactory)2 HashMap (java.util.HashMap)2 JSONObject (com.alibaba.fastjson.JSONObject)1 BlogMainContentDTO (com.duan.blogos.dto.blog.BlogMainContentDTO)1