update/studentModel

This commit is contained in:
SowinskiBraeden committed 2022-01-15 12:18:45 -08:00
1 parent 0bf3910a20
commit 8b55d1df53
3 files changed
+32 -32

No files matched your search

+2 -2
View File
@@ -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
+17 -17
View File
@@ -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,
},
}
+13 -13
View File
@@ -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
}