update/studentModel
This commit is contained in:
1 parent
0bf3910a20
commit
8b55d1df53
3 files changed
+16
-16
No files matched your search
@@ -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
|
||||
|
||||
@@ -51,9 +51,9 @@ 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"],
|
||||
"PersonalData.FirstName": data["firstname"],
|
||||
"PersonalData.middlename": data["middlename"],
|
||||
"PersonalData.lastname": data["lastname"],
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
@@ -114,7 +114,7 @@ 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"],
|
||||
"SchoolData.gradelevel": data["gradelevel"],
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
@@ -175,7 +175,7 @@ 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"],
|
||||
"SchoolData.homeroom": data["homeroom"],
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
@@ -268,8 +268,8 @@ 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
|
||||
"AccountData.password": student.HashPassword(data["newPassword1"]),
|
||||
"AccountData.temppassword": false, // If it were a temp password, its not now
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
@@ -340,8 +340,8 @@ 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,
|
||||
"AccountData.password": student.HashPassword(tempPass),
|
||||
"AccountData.temppassword": true,
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
@@ -462,8 +462,8 @@ 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,
|
||||
"AccountData.accountdisabled": false,
|
||||
"AccountData.attempts": 0,
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@ type Student struct {
|
||||
}
|
||||
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"`
|
||||
@@ -39,6 +37,8 @@ type Student struct {
|
||||
Photo string `json:"photo"`
|
||||
}
|
||||
AccountData struct {
|
||||
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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user