use of org.neusoft.neubbs.controller.annotation.AccountActivation in project neubbs by nuitcoder.
the class TopicController method collectTopic.
/**
* 收藏话题
* - 自动处理用户喜欢话题状态,取反(已收藏 -> 未收藏, 未收藏 -> 已收藏)
*
* @param requestBodyParamsMap request-body 内 JSON 数据
* @return ApiJsonDTO 接口 JSON 传输对象
*/
@LoginAuthorization
@AccountActivation
@RequestMapping(value = "/topic/collect", method = RequestMethod.POST, consumes = "application/json")
public ApiJsonDTO collectTopic(@RequestBody Map<String, Object> requestBodyParamsMap) {
Integer topicId = (Integer) requestBodyParamsMap.get(ParamConst.TOPIC_ID);
validationService.check(ParamConst.TOPIC_ID, String.valueOf(topicId));
UserDO cookieUser = secretService.getUserInfoByAuthentication(httpService.getAuthenticationCookieValue());
return new ApiJsonDTO().success().model(topicService.operateCollectTopic(cookieUser.getId(), topicId));
}
use of org.neusoft.neubbs.controller.annotation.AccountActivation 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.controller.annotation.AccountActivation 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.controller.annotation.AccountActivation 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));
}
use of org.neusoft.neubbs.controller.annotation.AccountActivation in project neubbs by nuitcoder.
the class TopicController method newLikeTopic.
/**
* 点赞话题(新接口)
* - 自动处理用户喜欢话题状态,取反(已喜欢 -> 未喜欢, 未喜欢 -> 已喜欢)
*
* @param requestBodyParamsMap request-body 内 JSON 数据
* @return ApiJsonDTO 接口 JSON 传输对象
*/
@LoginAuthorization
@AccountActivation
@RequestMapping(value = "/topic/newlike", method = RequestMethod.POST, consumes = "application/json")
public ApiJsonDTO newLikeTopic(@RequestBody Map<String, Object> requestBodyParamsMap) {
Integer topicId = (Integer) requestBodyParamsMap.get(ParamConst.TOPIC_ID);
validationService.check(ParamConst.TOPIC_ID, String.valueOf(topicId));
UserDO cookieUser = secretService.getUserInfoByAuthentication(httpService.getAuthenticationCookieValue());
Map<String, Object> resultMap = new LinkedHashMap<>(SetConst.SIZE_TWO);
resultMap.put(ParamConst.USER_LIKE_TOPIC_ID, topicService.operateLikeTopic(cookieUser.getId(), topicId));
resultMap.put(ParamConst.LIKE, topicService.countTopicContentLike(topicId));
return new ApiJsonDTO().success().model(resultMap);
}
Aggregations