update/studentModel
This commit is contained in:
1 parent
0bf3910a20
commit
8b55d1df53
3 files changed
+32
-32
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.YOG = ((12 - student.SchoolData.GradeLevel) + time.Now().Year()) + 1
|
||||||
|
|
||||||
student.SchoolData.SchoolEmail = student.GenerateSchoolEmail()
|
student.AccountData.SchoolEmail = student.GenerateSchoolEmail()
|
||||||
|
|
||||||
// Disable login block
|
// Disable login block
|
||||||
student.AccountData.AccountDisabled = false
|
student.AccountData.AccountDisabled = false
|
||||||
@@ -103,7 +103,7 @@ func Enroll(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
// Generate temporary password
|
// Generate temporary password
|
||||||
tempPass := student.GeneratePassword(12, 1, 1, 1)
|
tempPass := student.GeneratePassword(12, 1, 1, 1)
|
||||||
student.SchoolData.Password = student.HashPassword(tempPass)
|
student.AccountData.Password = student.HashPassword(tempPass)
|
||||||
student.AccountData.TempPassword = true
|
student.AccountData.TempPassword = true
|
||||||
|
|
||||||
// Send student personal email temp password
|
// Send student personal email temp password
|
||||||
|
|||||||
@@ -51,10 +51,10 @@ func UpdateStudentName(c *fiber.Ctx) error {
|
|||||||
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
update := bson.M{
|
update := bson.M{
|
||||||
"$set": bson.M{
|
"$set": bson.M{
|
||||||
"firstname": data["firstname"],
|
"PersonalData.FirstName": data["firstname"],
|
||||||
"middlename": data["middlename"],
|
"PersonalData.middlename": data["middlename"],
|
||||||
"lastname": data["lastname"],
|
"PersonalData.lastname": data["lastname"],
|
||||||
"updated_at": update_time,
|
"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_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
update := bson.M{
|
update := bson.M{
|
||||||
"$set": bson.M{
|
"$set": bson.M{
|
||||||
"gradelevel": data["gradelevel"],
|
"SchoolData.gradelevel": data["gradelevel"],
|
||||||
"updated_at": update_time,
|
"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_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
update := bson.M{
|
update := bson.M{
|
||||||
"$set": bson.M{
|
"$set": bson.M{
|
||||||
"homeroom": data["homeroom"],
|
"SchoolData.homeroom": data["homeroom"],
|
||||||
"updated_at": update_time,
|
"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_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
update := bson.M{
|
update := bson.M{
|
||||||
"$set": bson.M{
|
"$set": bson.M{
|
||||||
"password": student.HashPassword(data["newPassword1"]),
|
"AccountData.password": student.HashPassword(data["newPassword1"]),
|
||||||
"temppassword": false, // If it were a temp password, its not now
|
"AccountData.temppassword": false, // If it were a temp password, its not now
|
||||||
"updated_at": update_time,
|
"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_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
update := bson.M{
|
update := bson.M{
|
||||||
"$set": bson.M{
|
"$set": bson.M{
|
||||||
"password": student.HashPassword(tempPass),
|
"AccountData.password": student.HashPassword(tempPass),
|
||||||
"temppassword": true,
|
"AccountData.temppassword": true,
|
||||||
"updated_at": update_time,
|
"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_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
update := bson.M{
|
update := bson.M{
|
||||||
"$set": bson.M{
|
"$set": bson.M{
|
||||||
"accountdisabled": false,
|
"AccountData.accountdisabled": false,
|
||||||
"attempts": 0,
|
"AccountData.attempts": 0,
|
||||||
"updated_at": update_time,
|
"updated_at": update_time,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-13
@@ -28,20 +28,20 @@ type Student struct {
|
|||||||
Contacts []string `json:"contacts"` // List of contact ID's rather than contact object
|
Contacts []string `json:"contacts"` // List of contact ID's rather than contact object
|
||||||
}
|
}
|
||||||
SchoolData struct {
|
SchoolData struct {
|
||||||
GradeLevel int `json:"gradelevel" validate:"required"`
|
GradeLevel int `json:"gradelevel" validate:"required"`
|
||||||
SchoolEmail string `json:"schoolemail"`
|
SID string `json:"sid"` // Student ID
|
||||||
Password string `json:"-" validate:"min=10,max=32"`
|
PEN string `json:"ped"` // Personal Education Number
|
||||||
SID string `json:"sid"` // Student ID
|
Homeroom string `json:"homeroom"`
|
||||||
PEN string `json:"ped"` // Personal Education Number
|
Locker Locker `json:"locker"`
|
||||||
Homeroom string `json:"homeroom"`
|
YOG int `json:"yog"` // Year of Graduation
|
||||||
Locker Locker `json:"locker"`
|
Photo string `json:"photo"`
|
||||||
YOG int `json:"yog"` // Year of Graduation
|
|
||||||
Photo string `json:"photo"`
|
|
||||||
}
|
}
|
||||||
AccountData struct {
|
AccountData struct {
|
||||||
AccountDisabled bool `bson:"accountdisabled"`
|
SchoolEmail string `json:"schoolemail"`
|
||||||
TempPassword bool `json:"temppassword"`
|
Password string `json:"-" validate:"min=10,max=32"`
|
||||||
Attempts int `json:"attempts"` // login attempts max 5
|
AccountDisabled bool `bson:"accountdisabled"`
|
||||||
|
TempPassword bool `json:"temppassword"`
|
||||||
|
Attempts int `json:"attempts"` // login attempts max 5
|
||||||
}
|
}
|
||||||
Created_at time.Time `json:"created_at"`
|
Created_at time.Time `json:"created_at"`
|
||||||
Updated_at time.Time `json:"updated_at"`
|
Updated_at time.Time `json:"updated_at"`
|
||||||
@@ -59,7 +59,7 @@ func (s *Student) GenerateSchoolEmail() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Student) ComparePasswords(password string) bool {
|
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 {
|
if valid != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user