Skip to content

Commit

Permalink
fix: many more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
harshkhandeparkar committed Dec 16, 2023
1 parent a85baa6 commit 7f29015
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions controllers/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ func OAuth(w http.ResponseWriter, r *http.Request) {
}

// Check if the user has already registered
var isNewUser bool = false
var isNewUser bool = true
var userType string = reqFields.Type

college := ""
student := models.Student{}
Expand All @@ -90,20 +91,26 @@ func OAuth(w http.ResponseWriter, r *http.Request) {
Where("username = ?", userInfo.Username).
First(&student)

isNewUser = isNewUser || (student.Username != userInfo.Username)

userInfo.Email = student.Email
college = student.College
if student.Username == userInfo.Username {
isNewUser = false
userType = "student"
userInfo.Email = student.Email
userInfo.Name = student.Name
college = student.College
}

mentor := models.Mentor{}
db.
Table("mentors").
Where("username = ?", userInfo.Username).
First(&mentor)

isNewUser = isNewUser || (mentor.Username != userInfo.Username)

userInfo.Email = mentor.Email
if mentor.Username == userInfo.Username {
isNewUser = false
userInfo.Email = mentor.Email
userInfo.Name = mentor.Name
userType = "mentor"
}

// Generate a JWT string for the user
jwtString, err := utils.GenerateLoginJwtString(utils.LoginJwtFields{
Expand All @@ -119,7 +126,7 @@ func OAuth(w http.ResponseWriter, r *http.Request) {
Name: userInfo.Name,
Email: userInfo.Email,
College: college,
Type: reqFields.Type,
Type: userType,
IsNewUser: isNewUser,
Jwt: jwtString,
}
Expand Down

0 comments on commit 7f29015

Please sign in to comment.