diff --git a/controllers/authController.go b/controllers/authController.go index 6e57c56..9ce7745 100644 --- a/controllers/authController.go +++ b/controllers/authController.go @@ -95,7 +95,7 @@ func Enroll(c *fiber.Ctx) error { student.SchoolData.YOG = ((12 - student.SchoolData.GradeLevel) + time.Now().Year()) + 1 - student.SchoolData.SchoolEmail = student.GenerateSchoolEmail() + student.AccountData.SchoolEmail = student.GenerateSchoolEmail() // Disable login block student.AccountData.AccountDisabled = false @@ -103,7 +103,7 @@ func Enroll(c *fiber.Ctx) error { // Generate temporary password tempPass := student.GeneratePassword(12, 1, 1, 1) - student.SchoolData.Password = student.HashPassword(tempPass) + student.AccountData.Password = student.HashPassword(tempPass) student.AccountData.TempPassword = true // Send student personal email temp password diff --git a/controllers/updateController.go b/controllers/updateController.go index 96ecefb..8c85f32 100644 --- a/controllers/updateController.go +++ b/controllers/updateController.go @@ -51,10 +51,10 @@ func UpdateStudentName(c *fiber.Ctx) error { update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) update := bson.M{ "$set": bson.M{ - "firstname": data["firstname"], - "middlename": data["middlename"], - "lastname": data["lastname"], - "updated_at": update_time, + "PersonalData.FirstName": data["firstname"], + "PersonalData.middlename": data["middlename"], + "PersonalData.lastname": data["lastname"], + "updated_at": update_time, }, } @@ -114,8 +114,8 @@ func UpdateStudentGradeLevel(c *fiber.Ctx) error { update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) update := bson.M{ "$set": bson.M{ - "gradelevel": data["gradelevel"], - "updated_at": update_time, + "SchoolData.gradelevel": data["gradelevel"], + "updated_at": update_time, }, } @@ -175,8 +175,8 @@ func UpdateStudentHomeroom(c *fiber.Ctx) error { update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) update := bson.M{ "$set": bson.M{ - "homeroom": data["homeroom"], - "updated_at": update_time, + "SchoolData.homeroom": data["homeroom"], + "updated_at": update_time, }, } @@ -268,9 +268,9 @@ func UpdateStudentPassword(c *fiber.Ctx) error { update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) update := bson.M{ "$set": bson.M{ - "password": student.HashPassword(data["newPassword1"]), - "temppassword": false, // If it were a temp password, its not now - "updated_at": update_time, + "AccountData.password": student.HashPassword(data["newPassword1"]), + "AccountData.temppassword": false, // If it were a temp password, its not now + "updated_at": update_time, }, } @@ -340,9 +340,9 @@ func ResetStudentPassword(c *fiber.Ctx) error { update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) update := bson.M{ "$set": bson.M{ - "password": student.HashPassword(tempPass), - "temppassword": true, - "updated_at": update_time, + "AccountData.password": student.HashPassword(tempPass), + "AccountData.temppassword": true, + "updated_at": update_time, }, } @@ -462,9 +462,9 @@ func RemoveStudentsDisabled(c *fiber.Ctx) error { update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) update := bson.M{ "$set": bson.M{ - "accountdisabled": false, - "attempts": 0, - "updated_at": update_time, + "AccountData.accountdisabled": false, + "AccountData.attempts": 0, + "updated_at": update_time, }, } diff --git a/models/studentModel.go b/models/studentModel.go index c95e0f9..974594d 100644 --- a/models/studentModel.go +++ b/models/studentModel.go @@ -28,20 +28,20 @@ type Student struct { Contacts []string `json:"contacts"` // List of contact ID's rather than contact object } SchoolData struct { - GradeLevel int `json:"gradelevel" validate:"required"` - SchoolEmail string `json:"schoolemail"` - Password string `json:"-" validate:"min=10,max=32"` - SID string `json:"sid"` // Student ID - PEN string `json:"ped"` // Personal Education Number - Homeroom string `json:"homeroom"` - Locker Locker `json:"locker"` - YOG int `json:"yog"` // Year of Graduation - Photo string `json:"photo"` + GradeLevel int `json:"gradelevel" validate:"required"` + SID string `json:"sid"` // Student ID + PEN string `json:"ped"` // Personal Education Number + Homeroom string `json:"homeroom"` + Locker Locker `json:"locker"` + YOG int `json:"yog"` // Year of Graduation + Photo string `json:"photo"` } AccountData struct { - AccountDisabled bool `bson:"accountdisabled"` - TempPassword bool `json:"temppassword"` - Attempts int `json:"attempts"` // login attempts max 5 + SchoolEmail string `json:"schoolemail"` + Password string `json:"-" validate:"min=10,max=32"` + AccountDisabled bool `bson:"accountdisabled"` + TempPassword bool `json:"temppassword"` + Attempts int `json:"attempts"` // login attempts max 5 } Created_at time.Time `json:"created_at"` Updated_at time.Time `json:"updated_at"` @@ -59,7 +59,7 @@ func (s *Student) GenerateSchoolEmail() string { } func (s *Student) ComparePasswords(password string) bool { - valid := bcrypt.CompareHashAndPassword([]byte(s.SchoolData.Password), []byte(password)) + valid := bcrypt.CompareHashAndPassword([]byte(s.AccountData.Password), []byte(password)) if valid != nil { return false }