Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(user): accept both email and id when login #97

Merged
merged 2 commits into from
Jul 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading