Search in sources :

Example 11 with AccountActivation

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));
}
Also used : UserDO(org.neusoft.neubbs.entity.UserDO) ApiJsonDTO(org.neusoft.neubbs.dto.ApiJsonDTO) AccountActivation(org.neusoft.neubbs.controller.annotation.AccountActivation) LoginAuthorization(org.neusoft.neubbs.controller.annotation.LoginAuthorization) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with AccountActivation

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);
}
Also used : UserDO(org.neusoft.neubbs.entity.UserDO) ApiJsonDTO(org.neusoft.neubbs.dto.ApiJsonDTO) AccountActivation(org.neusoft.neubbs.controller.annotation.AccountActivation) LoginAuthorization(org.neusoft.neubbs.controller.annotation.LoginAuthorization) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with AccountActivation

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);
        }
    }
}
Also used : AccountActivation(org.neusoft.neubbs.controller.annotation.AccountActivation) PermissionException(org.neusoft.neubbs.exception.PermissionException) UserDO(org.neusoft.neubbs.entity.UserDO) HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 14 with AccountActivation

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));
}
Also used : UserDO(org.neusoft.neubbs.entity.UserDO) ApiJsonDTO(org.neusoft.neubbs.dto.ApiJsonDTO) AccountActivation(org.neusoft.neubbs.controller.annotation.AccountActivation) LoginAuthorization(org.neusoft.neubbs.controller.annotation.LoginAuthorization) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with AccountActivation

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);
}
Also used : UserDO(org.neusoft.neubbs.entity.UserDO) ApiJsonDTO(org.neusoft.neubbs.dto.ApiJsonDTO) LinkedHashMap(java.util.LinkedHashMap) AccountActivation(org.neusoft.neubbs.controller.annotation.AccountActivation) LoginAuthorization(org.neusoft.neubbs.controller.annotation.LoginAuthorization) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AccountActivation (org.neusoft.neubbs.controller.annotation.AccountActivation)15 LoginAuthorization (org.neusoft.neubbs.controller.annotation.LoginAuthorization)14 ApiJsonDTO (org.neusoft.neubbs.dto.ApiJsonDTO)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 UserDO (org.neusoft.neubbs.entity.UserDO)11 AdminRank (org.neusoft.neubbs.controller.annotation.AdminRank)2 LinkedHashMap (java.util.LinkedHashMap)1 PermissionException (org.neusoft.neubbs.exception.PermissionException)1 HandlerMethod (org.springframework.web.method.HandlerMethod)1