Skip to content

Commit

Permalink
Merge pull request #75 from NJUPT-SAST/fix-login
Browse files Browse the repository at this point in the history
fix: Fix the problem that users cannot login using uid
  • Loading branch information
Xunop authored Mar 13, 2024
2 parents d64970b + 58460a9 commit 26ee7de
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,16 @@ func VerifyAccountRegister(ctx *gin.Context, username string) (string, error) {
// This username is email or uid
func VerifyAccountLogin(ctx *gin.Context, username string) (string, error) {
var user *model.User
user, err := model.GetUserByEmail(username)

// User use email to login, need to trasfer to uid
split := regexp.MustCompile(`@`)
username = split.Split(username, 2)[0]

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

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

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 26ee7de

Please sign in to comment.