Search in sources :

Example 46 with UserDO

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);
}
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 47 with UserDO

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

Example 48 with UserDO

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);
        }
    }
}
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 49 with UserDO

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

Example 50 with UserDO

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));
}
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)

Aggregations

UserDO (org.neusoft.neubbs.entity.UserDO)60 Test (org.junit.Test)28 Transactional (javax.transaction.Transactional)21 ApiJsonDTO (org.neusoft.neubbs.dto.ApiJsonDTO)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 AccountActivation (org.neusoft.neubbs.controller.annotation.AccountActivation)11 LoginAuthorization (org.neusoft.neubbs.controller.annotation.LoginAuthorization)11 Cookie (javax.servlet.http.Cookie)6 JSONArray (com.alibaba.fastjson.JSONArray)4 Map (java.util.Map)4 LinkedHashMap (java.util.LinkedHashMap)3 UserActionDO (org.neusoft.neubbs.entity.UserActionDO)3 ServiceException (org.neusoft.neubbs.exception.ServiceException)3 TopicContentDO (org.neusoft.neubbs.entity.TopicContentDO)2 TopicReplyDO (org.neusoft.neubbs.entity.TopicReplyDO)2 UserDynamicDO (org.neusoft.neubbs.entity.UserDynamicDO)2 PermissionException (org.neusoft.neubbs.exception.PermissionException)2 HandlerMethod (org.springframework.web.method.HandlerMethod)2 JWTVerifier (com.auth0.jwt.JWTVerifier)1 TokenExpiredException (com.auth0.jwt.exceptions.TokenExpiredException)1