Search in sources :

Example 11 with ApiJsonDTO

use of org.neusoft.neubbs.dto.ApiJsonDTO in project neubbs by nuitcoder.

the class AccountController method loginAccount.

/**
 * 登录
 *      - username(支持用户名 or 邮箱格式)
 *
 * @param requestBodyParamsMap  request-body 内 JSON 数据
 * @return ApiJsonDTO 接口 JSON 传输对象
 */
@RequestMapping(value = "/login", method = RequestMethod.POST)
public ApiJsonDTO loginAccount(@RequestBody Map<String, Object> requestBodyParamsMap) {
    String username = (String) requestBodyParamsMap.get(ParamConst.USERNAME);
    String password = (String) requestBodyParamsMap.get(ParamConst.PASSWORD);
    validationService.checkUsername(username).check(ParamConst.PASSWORD, password);
    // database login authenticate
    UserDO user = userService.loginVerification(username, password);
    // jwt secret user information, save authentication to cookie
    String authentication = secretService.generateUserInfoAuthentication(user);
    httpService.saveAuthenticationCookie(authentication);
    httpService.increaseOnlineLoginUserNumber();
    // response model -> include authentication and state
    Map<String, Object> modelMap = new LinkedHashMap<>(SetConst.LENGTH_TWO);
    modelMap.put(ParamConst.AUTHENTICATION, authentication);
    modelMap.put(ParamConst.STATE, userService.isUserActivatedByState(user.getState()));
    return new ApiJsonDTO().success().model(modelMap);
}
Also used : UserDO(org.neusoft.neubbs.entity.UserDO) ApiJsonDTO(org.neusoft.neubbs.dto.ApiJsonDTO) LinkedHashMap(java.util.LinkedHashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with ApiJsonDTO

use of org.neusoft.neubbs.dto.ApiJsonDTO in project neubbs by nuitcoder.

the class FileController method uploadUserAvatar.

/**
 * 上传用户头像
 *      - 上传文件类型需满足 MediaType.MULTIPART_FORM_DATA_VALUE(multipart/form-data)
 *      - 执行流程
 *          - 检查上传头像规范(空,类型,文件大小)
 *          - Cookie 内获取用户信息
 *          - ftp 服务上传用户头像
 *          - 修改数据库用户个人信息(头像名)
 *
 * @param avatarFile 用户上传的文件对象
 * @return ApiJsonDTO 接口 JSON 传输对象
 */
@LoginAuthorization
@AccountActivation
@RequestMapping(value = "/avatar", method = RequestMethod.POST, consumes = "multipart/form-data")
public ApiJsonDTO uploadUserAvatar(@RequestParam("avatarImageFile") MultipartFile avatarFile) {
    validationService.checkUserUploadAvatarNorm(avatarFile);
    UserDO cookieUser = secretService.getUserInfoByAuthentication(httpService.getAuthenticationCookieValue());
    ftpService.uploadUserAvatar(cookieUser, avatarFile);
    userService.alterUserAvatar(cookieUser.getName(), ftpService.generateServerAvatarFileName(avatarFile));
    return new ApiJsonDTO().success().message(ApiMessage.UPLOAD_SUCCESS);
}
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 ApiJsonDTO

use of org.neusoft.neubbs.dto.ApiJsonDTO in project neubbs by nuitcoder.

the class TopicController method updateTopicReply.

/**
 * 编辑回复
 *
 * @param requestBodyParamsMap request-body 内 JSON 数据
 * @return ApiJsonDTO 接口 JSON 传输对象
 */
@LoginAuthorization
@AccountActivation
@RequestMapping(value = "/topic/reply-update", method = RequestMethod.POST, consumes = "application/json")
public ApiJsonDTO updateTopicReply(@RequestBody Map<String, Object> requestBodyParamsMap) {
    Integer replyId = (Integer) requestBodyParamsMap.get(ParamConst.REPLY_ID);
    String newReplyContent = (String) requestBodyParamsMap.get(ParamConst.CONTENT);
    validationService.check(ParamConst.ID, String.valueOf(replyId)).check(ParamConst.REPLY_CONTENT, newReplyContent);
    topicService.alterReplyContent(replyId, newReplyContent);
    return new ApiJsonDTO().success();
}
Also used : 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 14 with ApiJsonDTO

use of org.neusoft.neubbs.dto.ApiJsonDTO in project neubbs by nuitcoder.

the class TopicController method releaseTopic.

/**
 * 发布话题
 *
 * @param requestBodyParamsMap request-body 内 JSON 数据
 * @return ApiJsonDTO 接口 JSON 传输数据
 */
@LoginAuthorization
@AccountActivation
@RequestMapping(value = "/topic", method = RequestMethod.POST, consumes = "application/json")
public ApiJsonDTO releaseTopic(@RequestBody Map<String, Object> requestBodyParamsMap) {
    String category = (String) requestBodyParamsMap.get(ParamConst.CATEGORY);
    String title = (String) requestBodyParamsMap.get(ParamConst.TITLE);
    String topicContent = (String) requestBodyParamsMap.get(ParamConst.CONTENT);
    validationService.check(ParamConst.TOPIC_CATEGORY_NICK, category).check(ParamConst.TOPIC_TITLE, title).check(ParamConst.TOPIC_CONTENT, topicContent);
    UserDO cookieUser = secretService.getUserInfoByAuthentication(httpService.getAuthenticationCookieValue());
    return new ApiJsonDTO().success().model(topicService.saveTopic(cookieUser.getId(), category, title, topicContent));
}
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 ApiJsonDTO

use of org.neusoft.neubbs.dto.ApiJsonDTO 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)

Aggregations

ApiJsonDTO (org.neusoft.neubbs.dto.ApiJsonDTO)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 LoginAuthorization (org.neusoft.neubbs.controller.annotation.LoginAuthorization)16 UserDO (org.neusoft.neubbs.entity.UserDO)15 AccountActivation (org.neusoft.neubbs.controller.annotation.AccountActivation)14 LinkedHashMap (java.util.LinkedHashMap)3 AdminRank (org.neusoft.neubbs.controller.annotation.AdminRank)2 HashMap (java.util.HashMap)1