Skip to content

Commit a888fa6

Browse files
Sh1n3zZzmh-program
andcommitted
feat: support email suffix checkout
feat: support email suffix checkout Co-Authored-By: Minghan Zhang <[email protected]>
1 parent e60b16f commit a888fa6

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

app/src/api/auth.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ export async function doRegister(
8585
}
8686
}
8787

88-
export async function doVerify(email: string): Promise<VerifyResponse> {
88+
export async function doVerify(email: string, checkout?: boolean): Promise<VerifyResponse> {
8989
try {
9090
const response = await axios.post("/verify", {
91-
email,
91+
email, checkout,
9292
} as VerifyForm);
9393
return response.data as VerifyResponse;
9494
} catch (e) {
@@ -115,10 +115,11 @@ export async function sendCode(
115115
t: any,
116116
toast: any,
117117
email: string,
118+
checkout?: boolean,
118119
): Promise<boolean> {
119120
if (email.trim().length === 0 || !isEmailValid(email)) return false;
120121

121-
const res = await doVerify(email);
122+
const res = await doVerify(email, checkout);
122123
if (!res.status)
123124
toast({
124125
title: t("auth.send-code-failed"),
@@ -131,4 +132,4 @@ export async function sendCode(
131132
});
132133

133134
return res.status;
134-
}
135+
}

app/src/components/home/assemblies/ChatAction.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export function MarketAction() {
140140

141141
return (
142142
<Dialog open={open} onOpenChange={setOpen}>
143-
<DialogTrigger>
143+
<DialogTrigger asChild>
144144
<ChatAction text={t("market.title")}>
145145
<Blocks className={`h-4 w-4`} />
146146
</ChatAction>

app/src/routes/Register.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function Verify({ form, dispatch, setNext }: CompProps) {
155155
await router.navigate("/");
156156
};
157157

158-
const onVerify = async () => await sendCode(t, toast, form.email);
158+
const onVerify = async () => await sendCode(t, toast, form.email, true);
159159

160160
return (
161161
<div className={`auth-wrapper`}>

auth/auth.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import (
88
"database/sql"
99
"errors"
1010
"fmt"
11+
"strings"
12+
"time"
13+
1114
"github.com/dgrijalva/jwt-go"
1215
"github.com/gin-gonic/gin"
1316
"github.com/go-redis/redis/v8"
1417
"github.com/spf13/viper"
15-
"strings"
16-
"time"
1718
)
1819

1920
func ParseToken(c *gin.Context, token string) *User {
@@ -90,10 +91,16 @@ func generateCode(c *gin.Context, cache *redis.Client, email string) string {
9091
return code
9192
}
9293

93-
func Verify(c *gin.Context, email string) error {
94+
func Verify(c *gin.Context, email string, checkout bool) error {
9495
cache := utils.GetCacheFromContext(c)
9596
code := generateCode(c, cache, email)
9697

98+
if checkout {
99+
if err := channel.SystemInstance.IsValidMail(email); err != nil {
100+
return err
101+
}
102+
}
103+
97104
return channel.SystemInstance.SendVerifyMail(email, code)
98105
}
99106

auth/controller.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import (
44
"chat/channel"
55
"chat/globals"
66
"chat/utils"
7-
"github.com/gin-gonic/gin"
87
"net/http"
98
"strings"
9+
10+
"github.com/gin-gonic/gin"
1011
)
1112

1213
type RegisterForm struct {
@@ -17,7 +18,8 @@ type RegisterForm struct {
1718
}
1819

1920
type VerifyForm struct {
20-
Email string `form:"email" binding:"required"`
21+
Email string `form:"email" binding:"required"`
22+
Checkout bool `form:"checkout"`
2123
}
2224

2325
type LoginForm struct {
@@ -228,7 +230,7 @@ func VerifyAPI(c *gin.Context) {
228230
return
229231
}
230232

231-
if err := Verify(c, form.Email); err != nil {
233+
if err := Verify(c, form.Email, form.Checkout); err != nil {
232234
c.JSON(http.StatusOK, gin.H{
233235
"status": false,
234236
"error": err.Error(),

0 commit comments

Comments
 (0)