From b14086928166975fad52c475eeb0a9e68ea78c70 Mon Sep 17 00:00:00 2001 From: SowinskiBraeden Date: Sat, 7 Jan 2023 17:14:00 -0800 Subject: [PATCH] simplify naming --- controllers/authController.go | 52 ++++++++++++------------- controllers/update/adminController.go | 14 +++---- controllers/update/studentController.go | 14 +++---- controllers/update/teacherController.go | 14 +++---- models/adminModel.go | 2 +- models/studentModel.go | 10 ++--- models/teacherModel.go | 10 ++--- 7 files changed, 58 insertions(+), 58 deletions(-) diff --git a/controllers/authController.go b/controllers/authController.go index 4897766..9624d1a 100644 --- a/controllers/authController.go +++ b/controllers/authController.go @@ -267,16 +267,16 @@ func Enroll(c *fiber.Ctx) error { } offset++ } - student.AccountData.SchoolEmail = schoolEmail - student.AccountData.HashHistory = []string{} + student.Account.SchoolEmail = schoolEmail + student.Account.HashHistory = []string{} // Disable login block - student.AccountData.AccountDisabled = false - student.AccountData.Alerted = false - student.AccountData.Attempts = 0 + student.Account.AccountDisabled = false + student.Account.Alerted = false + student.Account.Attempts = 0 - student.AccountData.Password = student.HashPassword(data["password1"].(string)) - student.AccountData.TempPassword = false + student.Account.Password = student.HashPassword(data["password1"].(string)) + student.Account.TempPassword = false var sid string for { @@ -437,15 +437,15 @@ func RegisterTeacher(c *fiber.Ctx) error { } offset++ } - teacher.AccountData.SchoolEmail = schoolEmail - teacher.AccountData.HashHistory = []string{} + teacher.Account.SchoolEmail = schoolEmail + teacher.Account.HashHistory = []string{} // Disable login block - teacher.AccountData.AccountDisabled = false - teacher.AccountData.Attempts = 0 + teacher.Account.AccountDisabled = false + teacher.Account.Attempts = 0 - teacher.AccountData.Password = teacher.HashPassword(data["password1"].(string)) - teacher.AccountData.TempPassword = false + teacher.Account.Password = teacher.HashPassword(data["password1"].(string)) + teacher.Account.TempPassword = false var tid string // For the unlikely event that an ID is already in use this will simply try again till it gets a id not in use @@ -646,21 +646,21 @@ func StudentLogin(c *fiber.Ctx) error { var verified bool = student.ComparePasswords(data["password"]) var localAccountDisabled bool = false - var localAttempts int = student.AccountData.Attempts + var localAttempts int = student.Account.Attempts if !verified { localAttempts += 1 } - if student.AccountData.Attempts >= 5 || localAttempts >= 5 { + if student.Account.Attempts >= 5 || localAttempts >= 5 { localAccountDisabled = true // Catches newly disbaled account before student obj is updated update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) update := bson.M{ "$set": bson.M{ - "accountdata.accountdisabled": true, - "accountdata.alerted": true, - "accountdata.attempts": 0, - "updated_at": update_time, + "Account.accountdisabled": true, + "Account.alerted": true, + "Account.attempts": 0, + "updated_at": update_time, }, } @@ -679,9 +679,9 @@ func StudentLogin(c *fiber.Ctx) error { } } - if localAccountDisabled || student.AccountData.AccountDisabled { + if localAccountDisabled || student.Account.AccountDisabled { - if !student.AccountData.Alerted { + if !student.Account.Alerted { // Send student email warning of disabled account subject := "Account Disabled" receiver := student.Personal.Email @@ -708,8 +708,8 @@ func StudentLogin(c *fiber.Ctx) error { update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) update := bson.M{ "$set": bson.M{ - "accountdata.attempts": (student.AccountData.Attempts + 1), - "updated_at": update_time, + "Account.attempts": (student.Account.Attempts + 1), + "updated_at": update_time, }, } @@ -735,8 +735,8 @@ func StudentLogin(c *fiber.Ctx) error { update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) update := bson.M{ "$set": bson.M{ - "accountdata.attempts": 0, - "updated_at": update_time, + "Account.attempts": 0, + "updated_at": update_time, }, } @@ -976,7 +976,7 @@ func Student(c *fiber.Ctx) error { }) } - if student.AccountData.AccountDisabled { + if student.Account.AccountDisabled { return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{ "success": false, "message": "Student Accound Disabled, Contact and Admin", diff --git a/controllers/update/adminController.go b/controllers/update/adminController.go index dfe4446..ccf5251 100644 --- a/controllers/update/adminController.go +++ b/controllers/update/adminController.go @@ -369,10 +369,10 @@ func RemoveStudentsDisabled(c *fiber.Ctx) error { update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) update := bson.M{ "$set": bson.M{ - "accountdata.accountdisabled": false, - "accountdata.alerted": false, - "accountdata.attempts": 0, - "updated_at": update_time, + "Account.accountdisabled": false, + "Account.alerted": false, + "Account.attempts": 0, + "updated_at": update_time, }, } @@ -432,9 +432,9 @@ func RemoveTeachersDisabled(c *fiber.Ctx) error { update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) update := bson.M{ "$set": bson.M{ - "accountdata.accountdisabled": false, - "accountdata.attempts": 0, - "updated_at": update_time, + "Account.accountdisabled": false, + "Account.attempts": 0, + "updated_at": update_time, }, } diff --git a/controllers/update/studentController.go b/controllers/update/studentController.go index 2607c92..31bdc3a 100644 --- a/controllers/update/studentController.go +++ b/controllers/update/studentController.go @@ -306,12 +306,12 @@ func UpdateStudentPassword(c *fiber.Ctx) error { update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) update := bson.M{ "$set": bson.M{ - "accountdata.password": student.HashPassword(data["newpassword1"]), - "accountdata.temppassword": false, // If it were a temp password, its not now - "updated_at": update_time, + "Account.password": student.HashPassword(data["newpassword1"]), + "Account.temppassword": false, // If it were a temp password, its not now + "updated_at": update_time, }, "$push": bson.M{ - "accountdata.hashhistory": student.HashPassword(data["newpassword1"]), + "Account.hashhistory": student.HashPassword(data["newpassword1"]), }, } @@ -393,9 +393,9 @@ func ResetStudentPassword(c *fiber.Ctx) error { update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) update := bson.M{ "$set": bson.M{ - "accountdata.password": student.HashPassword(tempPass), - "accountdata.temppassword": true, - "updated_at": update_time, + "Account.password": student.HashPassword(tempPass), + "Account.temppassword": true, + "updated_at": update_time, }, } diff --git a/controllers/update/teacherController.go b/controllers/update/teacherController.go index 1fd18a7..8aea35c 100644 --- a/controllers/update/teacherController.go +++ b/controllers/update/teacherController.go @@ -161,12 +161,12 @@ func UpdateTeacherPassword(c *fiber.Ctx) error { update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) update := bson.M{ "$set": bson.M{ - "accountdata.password": teacher.HashPassword(data["newpassword1"]), - "accountdata.temppassword": false, // If it were a temp password, its not now - "updated_at": update_time, + "Account.password": teacher.HashPassword(data["newpassword1"]), + "Account.temppassword": false, // If it were a temp password, its not now + "updated_at": update_time, }, "$push": bson.M{ - "accountdata.hashhistory": teacher.HashPassword(data["newpassword1"]), + "Account.hashhistory": teacher.HashPassword(data["newpassword1"]), }, } @@ -246,9 +246,9 @@ func ResetTeacherPassword(c *fiber.Ctx) error { update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) update := bson.M{ "$set": bson.M{ - "accountdata.password": teacher.HashPassword(tempPass), - "accountdata.temppassword": true, - "updated_at": update_time, + "Account.password": teacher.HashPassword(tempPass), + "Account.temppassword": true, + "updated_at": update_time, }, } diff --git a/models/adminModel.go b/models/adminModel.go index 4ab7425..5ffc434 100644 --- a/models/adminModel.go +++ b/models/adminModel.go @@ -34,7 +34,7 @@ type Admin struct { func (a *Admin) EmailExists(email string) bool { var admin Admin - findErr := AdminCollection.FindOne(context.TODO(), bson.M{"accountdata.schoolemail": email}).Decode(&admin) + findErr := AdminCollection.FindOne(context.TODO(), bson.M{"Account.schoolemail": email}).Decode(&admin) return findErr == nil } diff --git a/models/studentModel.go b/models/studentModel.go index 2459213..fc76dc8 100644 --- a/models/studentModel.go +++ b/models/studentModel.go @@ -45,7 +45,7 @@ type Student struct { YOG int `json:"yog"` // Year of Graduation PhotoName string `json:"photoname"` // name of photo in db } `json:"schooldata"` - AccountData struct { + Account struct { VerifiedEmail bool `json:"verifiedemail"` SchoolEmail string `json:"schoolemail"` Password string `json:"-" validate:"min=10,max=32"` @@ -54,13 +54,13 @@ type Student struct { TempPassword bool `json:"temppassword"` Attempts int `json:"attempts"` // login attempts max 5 HashHistory []string `json:"-"` // List of old hashed passwords (not including auto generated passwords) - } `json:"accountdata"` + } `json:"Account"` Created_at time.Time `json:"created_at"` Updated_at time.Time `json:"updated_at"` } func (s *Student) UsedPassword(password string) bool { - for _, oldHash := range s.AccountData.HashHistory { + for _, oldHash := range s.Account.HashHistory { if oldHash == s.HashPassword(password) { return true } @@ -75,7 +75,7 @@ func (s *Student) HashPassword(password string) string { func (s *Student) EmailExists(email string) bool { var student Student - findErr := StudentCollection.FindOne(context.TODO(), bson.M{"accountdata.schoolemail": email}).Decode(&student) + findErr := StudentCollection.FindOne(context.TODO(), bson.M{"Account.schoolemail": email}).Decode(&student) return findErr == nil } @@ -95,7 +95,7 @@ func (s *Student) GenerateSchoolEmail(offset int, lastEmail string) string { } func (s *Student) ComparePasswords(password string) bool { //True: passwords match, False: no match - valid := bcrypt.CompareHashAndPassword([]byte(s.AccountData.Password), []byte(password)) + valid := bcrypt.CompareHashAndPassword([]byte(s.Account.Password), []byte(password)) return valid == nil } diff --git a/models/teacherModel.go b/models/teacherModel.go index 044f395..782c6b8 100644 --- a/models/teacherModel.go +++ b/models/teacherModel.go @@ -44,7 +44,7 @@ type Teacher struct { Homeroom string `json:"homeroom"` PhotoName string `json:"photoname"` // name of photo in db } `json:"schooldata"` - AccountData struct { + Account struct { VerifiedEmail bool `json:"verifiedemail"` SchoolEmail string `json:"schoolemail"` Password string `json:"-" validate:"min=10,max=32"` @@ -52,13 +52,13 @@ type Teacher struct { TempPassword bool `json:"temppassword"` Attempts int `json:"attempts"` // login attempts max 5 HashHistory []string `json:"-"` // List of old hashed passwords (not including auto generated passwords) - } `json:"accountdata"` + } `json:"Account"` Created_at time.Time `json:"created_at"` Updated_at time.Time `json:"updated_at"` } func (t *Teacher) UsedPassword(password string) bool { - for _, oldHash := range t.AccountData.HashHistory { + for _, oldHash := range t.Account.HashHistory { if oldHash == t.HashPassword(password) { return true } @@ -73,7 +73,7 @@ func (t *Teacher) HashPassword(password string) string { func (t *Teacher) EmailExists(email string) bool { var teacher Teacher - findErr := TeacherCollection.FindOne(context.TODO(), bson.M{"accountdata.schoolemail": email}).Decode(&teacher) + findErr := TeacherCollection.FindOne(context.TODO(), bson.M{"Account.schoolemail": email}).Decode(&teacher) return findErr == nil } @@ -93,7 +93,7 @@ func (t *Teacher) GenerateSchoolEmail(offset int, lastEmail string) string { } func (t *Teacher) ComparePasswords(password string) bool { - err := bcrypt.CompareHashAndPassword([]byte(t.AccountData.Password), []byte(password)) + err := bcrypt.CompareHashAndPassword([]byte(t.Account.Password), []byte(password)) return err == nil }