Skip to content

Commit

Permalink
Refactor CheckIfUserIsLoggingInFromKnownLocation function for improve…
Browse files Browse the repository at this point in the history
…d readability and logging
  • Loading branch information
waveyboym committed Jul 21, 2024
1 parent c498ce8 commit 402bda1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
6 changes: 1 addition & 5 deletions occupi-backend/pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,14 +877,10 @@ func CheckIfUserIsLoggingInFromKnownLocation(ctx *gin.Context, appsession *model
return false, nil, err
}

logrus.Info("User: ", user)
logrus.Info("Info: ", info)

// Add the user to the cache if cache is not nil
cache.SetUser(appsession, user)

for i, location := range user.KnownLocations {
logrus.Info("Location: ", i, location)
for _, location := range user.KnownLocations {
if location.Country == info.Country && location.City == info.City && location.Region == info.Region {
return true, nil, nil
}
Expand Down
34 changes: 17 additions & 17 deletions occupi-backend/pkg/models/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ import (

// structure of user
type User struct {
ID string `json:"_id" bson:"_id,omitempty"`
OccupiID string `json:"occupiId" bson:"occupiId"`
Password string `json:"password" bson:"password"`
Email string `json:"email" bson:"email"`
Role string `json:"role" bson:"role"`
OnSite bool `json:"onSite" bson:"onSite"`
IsVerified bool `json:"isVerified" bson:"isVerified"`
NextVerificationDate time.Time `json:"nextVerificationDate" bson:"nextVerificationDate"`
TwoFAEnabled bool `json:"twoFAEnabled" bson:"twoFAEnabled"`
KnownLocations []Location `json:"locations" bson:"locations"`
Details *Details `json:"details" bson:"details, omitempty"`
Notifications *Notifications `json:"notifications" bson:"notifications, omitempty"`
Security *Security `json:"security" bson:"security, omitempty"`
Status string `json:"status" bson:"status, omitempty"`
Position string `json:"position" bson:"position, omitempty"`
DepartmentNo string `json:"departmentNo" bson:"departmentNo, omitempty"`
ExpoPushToken string `json:"expoPushToken" bson:"expoPushToken"`
ID string `json:"_id" bson:"_id,omitempty"`
OccupiID string `json:"occupiId" bson:"occupiId"`
Password string `json:"password" bson:"password"`
Email string `json:"email" bson:"email"`
Role string `json:"role" bson:"role"`
OnSite bool `json:"onSite" bson:"onSite"`
IsVerified bool `json:"isVerified" bson:"isVerified"`
NextVerificationDate time.Time `json:"nextVerificationDate" bson:"nextVerificationDate"`
TwoFAEnabled bool `json:"twoFAEnabled" bson:"twoFAEnabled"`
KnownLocations []Location `json:"knownLocations" bson:"knownLocations"`
Details Details `json:"details" bson:"details, omitempty"`
Notifications Notifications `json:"notifications" bson:"notifications, omitempty"`
Security Security `json:"security" bson:"security, omitempty"`
Status string `json:"status" bson:"status, omitempty"`
Position string `json:"position" bson:"position, omitempty"`
DepartmentNo string `json:"departmentNo" bson:"departmentNo, omitempty"`
ExpoPushToken string `json:"expoPushToken" bson:"expoPushToken"`
}

type UserDetails struct {
Expand Down

0 comments on commit 402bda1

Please sign in to comment.