加入不允许注册模块

This commit is contained in:
筱锋xiao_lfeng 2023-11-29 23:41:27 +08:00
parent b6db17290b
commit 0106db1e3b
No known key found for this signature in database
GPG Key ID: 3D44FF873E0CD0E3
4 changed files with 32 additions and 1 deletions

8
info_upload.sql Normal file
View File

@ -0,0 +1,8 @@
USE dormstar;
TRUNCATE ds_info;
INSERT INTO ds_info (value, data, commit) VALUES
('title', '201京海市保护伞', '网站标题'),
('sub_title', '我们的宿舍', '网站副标题'),
('register', true, '是否允许注册');

View File

@ -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<BaseResponse> {
// 检查是否允许注册
if (!infoMapper.getRegister()) {
return ResultUtil.error(ErrorCode.REGISTRATION_NOT_ALLOWED, httpServletRequest)
}
// 判断请求体是否为空
if (signUpVO == null) {
return ResultUtil.error(ErrorCode.MISSING_REQUEST_BODY, httpServletRequest)

View File

@ -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
}

View File

@ -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,