Optimize register api. Add verify Turnstile captcha to login api.

This commit is contained in:
2023-12-29 17:55:44 +08:00
parent 94512ccd2b
commit 22055faca4
15 changed files with 189 additions and 8 deletions

View File

@@ -0,0 +1,33 @@
package top.fatweb.oxygen.api.http
import com.github.lianjiatech.retrofit.spring.boot.core.RetrofitClient
import org.springframework.stereotype.Service
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.POST
import top.fatweb.oxygen.api.http.entity.turnstile.SiteverifyResponse
import top.fatweb.oxygen.api.properties.ServerProperties
/**
* Turnstile http request api
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@Service
@RetrofitClient(baseUrl = "https://challenges.cloudflare.com/turnstile/v0/")
interface TurnstileApi {
/**
* Turnstile post verify captcha code
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see SiteverifyResponse
*/
@FormUrlEncoded
@POST("siteverify")
fun siteverify(
@Field("response") captchaCode: String,
@Field("secret") secret: String = ServerProperties.turnstileSecretKey
): SiteverifyResponse
}

View File

@@ -0,0 +1,48 @@
package top.fatweb.oxygen.api.http.entity.turnstile
import com.fasterxml.jackson.annotation.JsonProperty
import java.time.LocalDateTime
/**
* Turnstile verify captcha code response
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
data class SiteverifyResponse(
/**
* Is success
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@JsonProperty("success")
val success: Boolean,
/**
* Challenge time
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@JsonProperty("challenge_ts")
val challengeTs: LocalDateTime?,
/**
* Hostname
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@JsonProperty("hostname")
val hostname: String?,
/**
* Error codes list
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
@JsonProperty("error-codes")
val errorCodes: List<String>?
)