Skip to content

Commit

Permalink
fix(service/verify login): verify by email or uid depending on suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
aimixsaka authored Jul 28, 2024
1 parent 22a0792 commit b3b5f51
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,18 @@ 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) {
// check if input username contain '@', add '@' if not contained
if !strings.Contains(username, "@njupt.edu.cn") {
username = username + "@njupt.edu.cn"
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)
}
var user *model.User
user, err := model.UserByField("email", username)
if err != nil || user == nil {
return "", result.UserNotExist

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

if user == nil {
user, err := model.UserByField("uid", 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 == "" {
Expand Down

0 comments on commit b3b5f51

Please sign in to comment.