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<>("");
}
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());
}
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));
}
}
Aggregations