Skip to content

Commit

Permalink
fix(user): accept both email and id when login (#97)
Browse files Browse the repository at this point in the history
* fix(user): accept both email and id when login

* fix(service/verify login): verify by email or uid depending on suffix

---------

Co-authored-by: A.S.K <[email protected]>
  • Loading branch information
MaxtuneLee and aimixsaka authored Jul 28, 2024
1 parent e0f0eee commit 58a0012
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,19 @@ func VerifyAccountRegister(ctx *gin.Context, username string) (string, error) {
// This function is used to verify the user's email is exist or not when login
// This username is email or uid
func VerifyAccountLogin(ctx *gin.Context, username string) (string, error) {
var user *model.User
user, err := model.UserByField("email", username)
if err != nil || user == nil {
return "", result.UserNotExist
var user *model.User
var err error
if strings.Contains(username, "@njupt.edu.cn") {
user, err = model.UserByField("email", username)
} else {
user, err = model.UserByField("uid", username)
}

if user == nil {
user, err := model.UserByField("uid", username)
if err != nil || user == nil {
return "", result.UserNotExist
}

if err != nil {
return "", err
}


ticket, err := util.GenerateTokenWithExp(ctx, model.LoginTicketJWTSubKey(*user.Uid), model.LOGIN_TICKET_EXP)
if err != nil || ticket == "" {
return "", err
Expand Down

0 comments on commit 58a0012

Please sign in to comment.