Skip to content

Commit

Permalink
feat: add no-need-invite-code feature for specific email suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
JingYiJun committed Feb 29, 2024
1 parent 12720d8 commit 8569faa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion apis/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package account

import (
"errors"
"strings"
"time"

"MOSS_backend/config"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 8569faa

Please sign in to comment.