feat: support email suffix checkout

feat: support email suffix checkout
Co-Authored-By: Minghan Zhang <112773885+zmh-program@users.noreply.github.com>
This commit is contained in:
Deng Junhai 2024-04-04 12:12:18 +08:00
parent e60b16fc9a
commit a888fa62ef
5 changed files with 22 additions and 12 deletions

View File

@ -85,10 +85,10 @@ export async function doRegister(
}
}
export async function doVerify(email: string): Promise<VerifyResponse> {
export async function doVerify(email: string, checkout?: boolean): Promise<VerifyResponse> {
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<boolean> {
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;
}
}

View File

@ -140,7 +140,7 @@ export function MarketAction() {
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger>
<DialogTrigger asChild>
<ChatAction text={t("market.title")}>
<Blocks className={`h-4 w-4`} />
</ChatAction>

View File

@ -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 (
<div className={`auth-wrapper`}>

View File

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

View File

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