From 8569faa8fd93d5e9cf648918cfb50ec6b322f4b1 Mon Sep 17 00:00:00 2001 From: Ke Chen Date: Thu, 29 Feb 2024 19:57:04 +0800 Subject: [PATCH] feat: add no-need-invite-code feature for specific email suffix --- apis/account/account.go | 13 ++++++++++++- config/config.go | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apis/account/account.go b/apis/account/account.go index 612087d..856c830 100644 --- a/apis/account/account.go +++ b/apis/account/account.go @@ -2,6 +2,7 @@ package account import ( "errors" + "strings" "time" "MOSS_backend/config" @@ -68,7 +69,17 @@ func Register(c *fiber.Ctx) error { } // check Invite code - if configObject.InviteRequired { + var inviteRequired = configObject.InviteRequired + if body.EmailModel != nil { + // check email suffix in no need invite code + for _, emailSuffix := range config.Config.NoNeedInviteCodeEmailSuffix { + if strings.HasSuffix(body.Email, emailSuffix) { + inviteRequired = false + break + } + } + } + if inviteRequired { if body.InviteCode == nil { return errCollection.ErrNeedInviteCode } diff --git a/config/config.go b/config/config.go index 77f1cff..6fd0d43 100644 --- a/config/config.go +++ b/config/config.go @@ -63,7 +63,8 @@ var Config struct { // InnerThoughtsPostprocess bool `env:"INNER_THOUGHTS_POSTPROCESS" envDefault:"false"` - DefaultModelID int `env:"DEFAULT_MODEL_ID" envDefault:"1"` + DefaultModelID int `env:"DEFAULT_MODEL_ID" envDefault:"1"` + NoNeedInviteCodeEmailSuffix []string `env:"NO_NEED_INVITE_CODE_EMAIL_SUFFIX" envSeparator:"," envDefault:"fudan.edu.cn"` } func InitConfig() {