Search in sources :

Example 21 with ApiJsonDTO

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

the class AccountController method logoutAccount.

/**
 * 注销
 *
 * @return ApiJsonDTO 接口 JSON 传输对象
 */
@LoginAuthorization
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public ApiJsonDTO logoutAccount() {
    httpService.removeCookie(ParamConst.AUTHENTICATION);
    httpService.decreaseOnlineLoginUserNumber();
    return new ApiJsonDTO().success();
}
Also used : ApiJsonDTO(org.neusoft.neubbs.dto.ApiJsonDTO) LoginAuthorization(org.neusoft.neubbs.controller.annotation.LoginAuthorization) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with ApiJsonDTO

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

the class AccountController method activateAccount.

/**
 * 激活账户
 *      - 发送激活 mail
 *
 * @param requestBodyParamsMap request-body 内 JSON 数据
 * @return ApiJsonDTO 接口 JSON 传输对象
 */
@RequestMapping(value = "/activate", method = RequestMethod.POST, consumes = "application/json")
public ApiJsonDTO activateAccount(@RequestBody Map<String, Object> requestBodyParamsMap) {
    String email = (String) requestBodyParamsMap.get(ParamConst.EMAIL);
    validationService.check(ParamConst.EMAIL, email);
    userService.confirmUserActivatedByEmail(email);
    // 60s send email interval
    long remainAllowSendEmailInterval = cacheService.getEmailKeyExpireTime(email);
    if (remainAllowSendEmailInterval != SetConst.EXPIRE_TIME_REDIS_NO_EXIST_KEY) {
        Map<String, Object> timerMap = new HashMap<>(SetConst.SIZE_ONE);
        timerMap.put(ParamConst.TIMER, remainAllowSendEmailInterval / SetConst.TIME_THOUSAND_MS);
        return new ApiJsonDTO().fail().message(ApiMessage.WAIT_TIMER).model(timerMap);
    }
    // start another thread to send mail
    emailService.sendAccountActivateMail(email, secretService.generateValidateEmailToken(email));
    // set user send email 60s interval
    cacheService.saveUserEmailKey(email);
    return new ApiJsonDTO().success();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ApiJsonDTO(org.neusoft.neubbs.dto.ApiJsonDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with ApiJsonDTO

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

the class AccountController method registerAccount.

/**
 * 注册
 *
 * @param requestBodyParamsMap request-body 内 JSON 数据
 * @return ApiJsonDTO 接口 JSON 传输对象
 */
@RequestMapping(value = "/register", method = RequestMethod.POST, consumes = "application/json")
public ApiJsonDTO registerAccount(@RequestBody Map<String, Object> requestBodyParamsMap) {
    String username = (String) requestBodyParamsMap.get(ParamConst.USERNAME);
    String password = (String) requestBodyParamsMap.get(ParamConst.PASSWORD);
    String email = (String) requestBodyParamsMap.get(ParamConst.EMAIL);
    validationService.check(ParamConst.USERNAME, username).check(ParamConst.PASSWORD, password).check(ParamConst.EMAIL, email);
    // database register user
    UserDO newRegisterUser = userService.registerUser(username, password, email);
    // create user person directory on cloud ftp server
    ftpService.createUserPersonalDirectory(newRegisterUser);
    return new ApiJsonDTO().success().model(userService.getUserInfoModelMap(newRegisterUser));
}
Also used : UserDO(org.neusoft.neubbs.entity.UserDO) ApiJsonDTO(org.neusoft.neubbs.dto.ApiJsonDTO) 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