diff --git a/src/service/user.go b/src/service/user.go index 13bb531..85bf43b 100644 --- a/src/service/user.go +++ b/src/service/user.go @@ -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