Search in sources :

Example 41 with UserDO

use of org.neusoft.neubbs.entity.UserDO in project neubbs by nuitcoder.

the class AccountController method updateUserInfo.

/**
 * 修改用户基本信息
 *      - sex 不能为空,且只能为 0 or 1
 *      - birthday, position, description 允许 "",但是不能为 null
 *
 * @param requestBodyParamsMap request-body 内 JSON 数据
 * @return ApiJsonDTO 接口 JSON 传输对象
 */
@LoginAuthorization
@AccountActivation
@RequestMapping(value = "/update-profile", method = RequestMethod.POST, consumes = "application/json")
public ApiJsonDTO updateUserInfo(@RequestBody Map<String, Object> requestBodyParamsMap) {
    Integer newSex = (Integer) requestBodyParamsMap.get(ParamConst.SEX);
    String newBirthday = (String) requestBodyParamsMap.get(ParamConst.BIRTHDAY);
    String newPosition = (String) requestBodyParamsMap.get(ParamConst.POSITION);
    String newDescription = (String) requestBodyParamsMap.get(ParamConst.DESCRIPTION);
    validationService.checkCommand(String.valueOf(newSex), "0", "1");
    validationService.checkParamsNotAllNull(newBirthday, newPosition, newDescription);
    validationService.check(ParamConst.BIRTHDAY, newBirthday).check(ParamConst.POSITION, newPosition).check(ParamConst.DESCRIPTION, newDescription);
    // get user information in client cookie
    UserDO user = secretService.getUserInfoByAuthentication(httpService.getAuthenticationCookieValue());
    return new ApiJsonDTO().success().model(userService.alterUserProfile(user.getName(), newSex, newBirthday, newPosition, newDescription));
}
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 42 with UserDO

use of org.neusoft.neubbs.entity.UserDO 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 43 with UserDO

use of org.neusoft.neubbs.entity.UserDO 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 44 with UserDO

use of org.neusoft.neubbs.entity.UserDO 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 45 with UserDO

use of org.neusoft.neubbs.entity.UserDO 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

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