Optimize two-factor api. Add remove two-factor api.

This commit is contained in:
2024-03-01 15:35:32 +08:00
parent b52ce7f5e8
commit 570f5a8ac6
20 changed files with 109 additions and 21 deletions

View File

@@ -3,6 +3,7 @@ package top.fatweb.oxygen.api.controller.permission
import io.swagger.v3.oas.annotations.Operation
import jakarta.servlet.http.HttpServletRequest
import jakarta.validation.Valid
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
@@ -163,7 +164,7 @@ class AuthenticationController(
* @see ResponseResult
* @see TwoFactorVo
*/
@Operation(summary = "创建二步验证")
@Operation(summary = "创建双因素验证")
@GetMapping("/two-factor")
fun createTwoFactor(): ResponseResult<TwoFactorVo> =
ResponseResult.success(data = authenticationService.createTwoFactor())
@@ -174,12 +175,24 @@ class AuthenticationController(
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@Operation(summary = "验证二步验证")
@Operation(summary = "验证双因素")
@PostMapping("/two-factor")
fun validateTwoFactor(@RequestBody @Valid twoFactorValidateParam: TwoFactorValidateParam): ResponseResult<Nothing> =
if (authenticationService.validateTwoFactor(twoFactorValidateParam)) ResponseResult.success()
else ResponseResult.fail()
/**
* Remove two-factor
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@Operation(summary = "移除双因素")
@DeleteMapping("/two-factor")
fun removeTwoFactor(@RequestBody @Valid twoFactorRemoveParam: TwoFactorRemoveParam): ResponseResult<Nothing> =
if (authenticationService.removeTwoFactor(twoFactorRemoveParam)) ResponseResult.success()
else ResponseResult.fail()
/**
* Logout

View File

@@ -194,7 +194,7 @@ class SettingsController(
* @see ResponseResult
* @see TwoFactorSettingsVo
*/
@Operation(summary = "获取二步验证设置")
@Operation(summary = "获取双因素设置")
@GetMapping("/two-factor")
@PreAuthorize("hasAnyAuthority('system:settings:query:two-factor')")
fun getTwoFactor(): ResponseResult<TwoFactorSettingsVo> =
@@ -211,7 +211,7 @@ class SettingsController(
* @see ResponseResult
*/
@Trim
@Operation(summary = "更新二步验证设置")
@Operation(summary = "更新双因素设置")
@PutMapping("/two-factor")
@PreAuthorize("hasAnyAuthority('system:settings:modify:two-factor')")
fun updateTwoFactor(@RequestBody twoFactorSettingsParam: TwoFactorSettingsParam): ResponseResult<Nothing> {