diff --git a/info_upload.sql b/info_upload.sql new file mode 100644 index 0000000..05f221f --- /dev/null +++ b/info_upload.sql @@ -0,0 +1,8 @@ +USE dormstar; + +TRUNCATE ds_info; + +INSERT INTO ds_info (value, data, commit) VALUES + ('title', '201京海市保护伞', '网站标题'), + ('sub_title', '我们的宿舍', '网站副标题'), + ('register', true, '是否允许注册'); \ No newline at end of file diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/controllers/UserController.kt b/src/main/kotlin/com/xlf/dromstarkotlin/controllers/UserController.kt index 3816ef5..c71d50b 100644 --- a/src/main/kotlin/com/xlf/dromstarkotlin/controllers/UserController.kt +++ b/src/main/kotlin/com/xlf/dromstarkotlin/controllers/UserController.kt @@ -6,6 +6,7 @@ import com.frontleaves.general.utils.ResultUtil import com.xlf.dromstarkotlin.entity.voData.SignInVO import com.xlf.dromstarkotlin.entity.voData.SignUpVO import com.xlf.dromstarkotlin.exception.BusinessException +import com.xlf.dromstarkotlin.mapper.InfoMapper import com.xlf.dromstarkotlin.services.TokenService import com.xlf.dromstarkotlin.services.UserService import jakarta.servlet.http.HttpServletRequest @@ -30,7 +31,8 @@ import java.util.Date @RequestMapping("/api/user") class UserController( private val tokenService: TokenService, - private val userService: UserService + private val userService: UserService, + private val infoMapper: InfoMapper, ) { /** * 用户登录组件 @@ -73,6 +75,10 @@ class UserController( @RequestBody signUpVO: SignUpVO?, @CookieValue("session") token: String?, httpServletResponse: HttpServletResponse, httpServletRequest: HttpServletRequest ): ResponseEntity { + // 检查是否允许注册 + if (!infoMapper.getRegister()) { + return ResultUtil.error(ErrorCode.REGISTRATION_NOT_ALLOWED, httpServletRequest) + } // 判断请求体是否为空 if (signUpVO == null) { return ResultUtil.error(ErrorCode.MISSING_REQUEST_BODY, httpServletRequest) diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/mapper/InfoMapper.kt b/src/main/kotlin/com/xlf/dromstarkotlin/mapper/InfoMapper.kt new file mode 100644 index 0000000..4e49d9e --- /dev/null +++ b/src/main/kotlin/com/xlf/dromstarkotlin/mapper/InfoMapper.kt @@ -0,0 +1,11 @@ +package com.xlf.dromstarkotlin.mapper + +import org.apache.ibatis.annotations.Mapper +import org.apache.ibatis.annotations.Select + +@Mapper +interface InfoMapper { + + @Select("SELECT * FROM dormstar.ds_info WHERE value = 'register'") + fun getRegister(): Boolean +} \ No newline at end of file diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/utils/ErrorCode.kt b/src/main/kotlin/com/xlf/dromstarkotlin/utils/ErrorCode.kt index ec1f9fb..7223fc2 100644 --- a/src/main/kotlin/com/xlf/dromstarkotlin/utils/ErrorCode.kt +++ b/src/main/kotlin/com/xlf/dromstarkotlin/utils/ErrorCode.kt @@ -72,6 +72,12 @@ enum class ErrorCode(val output: String, val code: Int, val message: String, val "您已经登录", HttpStatus.BAD_REQUEST ), + REGISTRATION_NOT_ALLOWED( + "RegistrationNotAllowed", + 40027, + "不允许注册", + HttpStatus.BAD_REQUEST + ), YOU_ARE_NOT_LOGIN( "YouAreNotLogin", 40110,