From a888fa62effa7c24d33681872e24bf2c02878f38 Mon Sep 17 00:00:00 2001 From: Deng Junhai Date: Thu, 4 Apr 2024 12:12:18 +0800 Subject: [PATCH] feat: support email suffix checkout feat: support email suffix checkout Co-Authored-By: Minghan Zhang <112773885+zmh-program@users.noreply.github.com> --- app/src/api/auth.ts | 9 +++++---- app/src/components/home/assemblies/ChatAction.tsx | 2 +- app/src/routes/Register.tsx | 2 +- auth/auth.go | 13 ++++++++++--- auth/controller.go | 8 +++++--- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/app/src/api/auth.ts b/app/src/api/auth.ts index 9253b2b..1d34045 100644 --- a/app/src/api/auth.ts +++ b/app/src/api/auth.ts @@ -85,10 +85,10 @@ export async function doRegister( } } -export async function doVerify(email: string): Promise { +export async function doVerify(email: string, checkout?: boolean): Promise { try { const response = await axios.post("/verify", { - email, + email, checkout, } as VerifyForm); return response.data as VerifyResponse; } catch (e) { @@ -115,10 +115,11 @@ export async function sendCode( t: any, toast: any, email: string, + checkout?: boolean, ): Promise { if (email.trim().length === 0 || !isEmailValid(email)) return false; - const res = await doVerify(email); + const res = await doVerify(email, checkout); if (!res.status) toast({ title: t("auth.send-code-failed"), @@ -131,4 +132,4 @@ export async function sendCode( }); return res.status; -} +} \ No newline at end of file diff --git a/app/src/components/home/assemblies/ChatAction.tsx b/app/src/components/home/assemblies/ChatAction.tsx index 0f0d1d5..4d80037 100644 --- a/app/src/components/home/assemblies/ChatAction.tsx +++ b/app/src/components/home/assemblies/ChatAction.tsx @@ -140,7 +140,7 @@ export function MarketAction() { return ( - + diff --git a/app/src/routes/Register.tsx b/app/src/routes/Register.tsx index 58a7029..7eb1ad9 100644 --- a/app/src/routes/Register.tsx +++ b/app/src/routes/Register.tsx @@ -155,7 +155,7 @@ function Verify({ form, dispatch, setNext }: CompProps) { await router.navigate("/"); }; - const onVerify = async () => await sendCode(t, toast, form.email); + const onVerify = async () => await sendCode(t, toast, form.email, true); return (
diff --git a/auth/auth.go b/auth/auth.go index 79e8a95..ac85bd2 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -8,12 +8,13 @@ import ( "database/sql" "errors" "fmt" + "strings" + "time" + "github.com/dgrijalva/jwt-go" "github.com/gin-gonic/gin" "github.com/go-redis/redis/v8" "github.com/spf13/viper" - "strings" - "time" ) func ParseToken(c *gin.Context, token string) *User { @@ -90,10 +91,16 @@ func generateCode(c *gin.Context, cache *redis.Client, email string) string { return code } -func Verify(c *gin.Context, email string) error { +func Verify(c *gin.Context, email string, checkout bool) error { cache := utils.GetCacheFromContext(c) code := generateCode(c, cache, email) + if checkout { + if err := channel.SystemInstance.IsValidMail(email); err != nil { + return err + } + } + return channel.SystemInstance.SendVerifyMail(email, code) } diff --git a/auth/controller.go b/auth/controller.go index de14af6..a0a4452 100644 --- a/auth/controller.go +++ b/auth/controller.go @@ -4,9 +4,10 @@ import ( "chat/channel" "chat/globals" "chat/utils" - "github.com/gin-gonic/gin" "net/http" "strings" + + "github.com/gin-gonic/gin" ) type RegisterForm struct { @@ -17,7 +18,8 @@ type RegisterForm struct { } type VerifyForm struct { - Email string `form:"email" binding:"required"` + Email string `form:"email" binding:"required"` + Checkout bool `form:"checkout"` } type LoginForm struct { @@ -228,7 +230,7 @@ func VerifyAPI(c *gin.Context) { return } - if err := Verify(c, form.Email); err != nil { + if err := Verify(c, form.Email, form.Checkout); err != nil { c.JSON(http.StatusOK, gin.H{ "status": false, "error": err.Error(),