use of org.neusoft.neubbs.entity.UserDO in project neubbs by nuitcoder.
the class TopicController method likeTopic.
/**
* 点赞话题
* - 需要 command 命令(inc - 点赞 | dec - 取消)
*
* @param requestBodyParamsMap request-body 内 JSON 数据
* @return ApiJsonDTO 接口 JSON 传输对象
*/
@LoginAuthorization
@AccountActivation
@RequestMapping(value = "/topic/like", method = RequestMethod.POST, consumes = "application/json")
public ApiJsonDTO likeTopic(@RequestBody Map<String, Object> requestBodyParamsMap) {
Integer topicId = (Integer) requestBodyParamsMap.get(ParamConst.TOPIC_ID);
String command = (String) requestBodyParamsMap.get(ParamConst.COMMAND);
validationService.check(ParamConst.TOPIC_ID, String.valueOf(topicId));
validationService.checkCommand(command, SetConst.COMMAND_INC, SetConst.COMMAND_DEC);
UserDO cookieUser = secretService.getUserInfoByAuthentication(httpService.getAuthenticationCookieValue());
// judge current user like topic, according the command('inc', 'dec'), alter like of topic
boolean isCurrentUserLikeTopic = userService.isUserLikeTopic(cookieUser.getId(), topicId);
// record user like topic id array of user action
userService.operateLikeTopic(cookieUser.getId(), topicId, command);
int latestTopicLike = topicService.alterTopicLikeByCommand(isCurrentUserLikeTopic, topicId, cookieUser.getId(), command);
return new ApiJsonDTO().success().buildMap(ParamConst.LIKE, latestTopicLike);
}
use of org.neusoft.neubbs.entity.UserDO in project neubbs by nuitcoder.
the class ApiInterceptor method doAdminRank.
/**
* 执行管理员权限验证
* - 判断 api 函数是否标识 @AdminRank
* - 判断是否存在 authentication Cookie(不存在表明未登陆, 未登录无权操作)
* - 判断 authentication Cookie 是否解密成功(解密失败,表示认认证信息已经过期)
* - 从认证信息内获取用户信息,判断用户权限
*
* @param request http 请求
* @param handler 方法对象
*/
private void doAdminRank(HttpServletRequest request, Object handler) throws ServiceException {
HandlerMethod handlerMethod = (HandlerMethod) handler;
if (handlerMethod.getMethodAnnotation(AdminRank.class) != null) {
String authentication = CookieUtil.getCookieValue(request, ParamConst.AUTHENTICATION);
UserDO currentUser = this.judgeAuthentication(authentication);
// judge user rank
if (!SetConst.RANK_ADMIN.equals(currentUser.getRank())) {
throw new PermissionException(ApiMessage.NO_PERMISSION).log(LogWarnEnum.AT3);
}
}
}
use of org.neusoft.neubbs.entity.UserDO in project neubbs by nuitcoder.
the class ApiInterceptor method doAccountActivation.
/**
* 执行账户激活验证
* - 判断 api 函数是否标识 @AccountActivation
* - 判断是否存在 authentication Cookie(不存在表明未登陆, 未登录无权操作)
* - 判断 authentication Cookie 是否解密成功(解密失败,表示认认证信息已经过期)
* - 从认证信息内获取用户信息,判断用户激活状态
*
* @param request http 请求
* @param handler 方法对象
*/
private void doAccountActivation(HttpServletRequest request, Object handler) throws ServiceException {
HandlerMethod handlerMethod = (HandlerMethod) handler;
if (handlerMethod.getMethodAnnotation(AccountActivation.class) != null) {
String authentication = CookieUtil.getCookieValue(request, ParamConst.AUTHENTICATION);
UserDO currentUser = this.judgeAuthentication(authentication);
// judge user state
if (currentUser.getState() == SetConst.ACCOUNT_NO_ACTIVATED_STATE) {
throw new PermissionException(ApiMessage.NO_ACTIVATE).log(LogWarnEnum.US17);
}
}
}
use of org.neusoft.neubbs.entity.UserDO in project neubbs by nuitcoder.
the class TopicController method getTopicInfo.
/**
* 获取话题信息
* - 能够获取当前用户是否点赞该文章信息(访客用户默认为 false)
* - hadread 参数决定是否增加阅读数(0 - 不增加, 1 - 增加)
*
* @param topicId 话题 id
* @param hadRead 阅读数是否增加(0 - 不增加,1 - 增加)
* @return ApiJsonDTO 接口 JSON 传输对象
*/
@RequestMapping(value = "/topic", method = RequestMethod.GET)
public ApiJsonDTO getTopicInfo(@RequestParam(value = "topicid", required = false) String topicId, @RequestParam(value = "hadread", required = false) String hadRead) {
validationService.check(ParamConst.ID, topicId);
// judge whether to increase read count
boolean isAddTopicRead = false;
if (hadRead != null) {
validationService.checkCommand(hadRead, "0", "1");
isAddTopicRead = SetConst.COMMAND_ONE.equals(hadRead);
}
int topicIdInt = Integer.parseInt(topicId);
Map<String, Object> topicContentPageModelMap = topicService.getTopicContentModelMap(topicIdInt);
// judge current user is like this topic (visit user default value of 'false')
boolean isLikeTopicForCurrentUser = false;
if (httpService.isUserLoginState()) {
UserDO currentUser = secretService.getUserInfoByAuthentication(httpService.getAuthenticationCookieValue());
isLikeTopicForCurrentUser = userService.isUserLikeTopic(currentUser.getId(), topicIdInt);
}
topicContentPageModelMap.put(ParamConst.IS_LIKE_TOPIC, isLikeTopicForCurrentUser);
// read + 1 (default no add)
if (isAddTopicRead) {
topicService.increaseTopicRead(topicIdInt);
topicContentPageModelMap.put(ParamConst.READ, (int) topicContentPageModelMap.get(ParamConst.READ) + 1);
}
return new ApiJsonDTO().success().model(topicContentPageModelMap);
}
use of org.neusoft.neubbs.entity.UserDO in project neubbs by nuitcoder.
the class TopicController method releaseTopicReply.
/**
* 发布回复
*
* @param requestBodyParamsMap request-body 内 JSON 数据
* @return ApiJsonDTO 接口 JSON 传输对象
*/
@LoginAuthorization
@AccountActivation
@RequestMapping(value = "/topic/reply", method = RequestMethod.POST, consumes = "application/json")
public ApiJsonDTO releaseTopicReply(@RequestBody Map<String, Object> requestBodyParamsMap) {
Integer topicId = (Integer) requestBodyParamsMap.get(ParamConst.TOPIC_ID);
String replyContent = (String) requestBodyParamsMap.get(ParamConst.CONTENT);
validationService.check(ParamConst.ID, String.valueOf(topicId)).check(ParamConst.REPLY_CONTENT, replyContent);
UserDO cookieUser = secretService.getUserInfoByAuthentication(httpService.getAuthenticationCookieValue());
return new ApiJsonDTO().success().model(topicService.saveReply(cookieUser.getId(), topicId, replyContent));
}
Aggregations