simplify naming
This commit is contained in:
7 files changed
+58
-58
No files matched your search
@@ -267,16 +267,16 @@ func Enroll(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
offset++
|
offset++
|
||||||
}
|
}
|
||||||
student.AccountData.SchoolEmail = schoolEmail
|
student.Account.SchoolEmail = schoolEmail
|
||||||
student.AccountData.HashHistory = []string{}
|
student.Account.HashHistory = []string{}
|
||||||
|
|
||||||
// Disable login block
|
// Disable login block
|
||||||
student.AccountData.AccountDisabled = false
|
student.Account.AccountDisabled = false
|
||||||
student.AccountData.Alerted = false
|
student.Account.Alerted = false
|
||||||
student.AccountData.Attempts = 0
|
student.Account.Attempts = 0
|
||||||
|
|
||||||
student.AccountData.Password = student.HashPassword(data["password1"].(string))
|
student.Account.Password = student.HashPassword(data["password1"].(string))
|
||||||
student.AccountData.TempPassword = false
|
student.Account.TempPassword = false
|
||||||
|
|
||||||
var sid string
|
var sid string
|
||||||
for {
|
for {
|
||||||
@@ -437,15 +437,15 @@ func RegisterTeacher(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
offset++
|
offset++
|
||||||
}
|
}
|
||||||
teacher.AccountData.SchoolEmail = schoolEmail
|
teacher.Account.SchoolEmail = schoolEmail
|
||||||
teacher.AccountData.HashHistory = []string{}
|
teacher.Account.HashHistory = []string{}
|
||||||
|
|
||||||
// Disable login block
|
// Disable login block
|
||||||
teacher.AccountData.AccountDisabled = false
|
teacher.Account.AccountDisabled = false
|
||||||
teacher.AccountData.Attempts = 0
|
teacher.Account.Attempts = 0
|
||||||
|
|
||||||
teacher.AccountData.Password = teacher.HashPassword(data["password1"].(string))
|
teacher.Account.Password = teacher.HashPassword(data["password1"].(string))
|
||||||
teacher.AccountData.TempPassword = false
|
teacher.Account.TempPassword = false
|
||||||
|
|
||||||
var tid string
|
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
|
// 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 verified bool = student.ComparePasswords(data["password"])
|
||||||
var localAccountDisabled bool = false
|
var localAccountDisabled bool = false
|
||||||
var localAttempts int = student.AccountData.Attempts
|
var localAttempts int = student.Account.Attempts
|
||||||
|
|
||||||
if !verified {
|
if !verified {
|
||||||
localAttempts += 1
|
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
|
localAccountDisabled = true // Catches newly disbaled account before student obj is updated
|
||||||
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{
|
||||||
"accountdata.accountdisabled": true,
|
"Account.accountdisabled": true,
|
||||||
"accountdata.alerted": true,
|
"Account.alerted": true,
|
||||||
"accountdata.attempts": 0,
|
"Account.attempts": 0,
|
||||||
"updated_at": update_time,
|
"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
|
// Send student email warning of disabled account
|
||||||
subject := "Account Disabled"
|
subject := "Account Disabled"
|
||||||
receiver := student.Personal.Email
|
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_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
update := bson.M{
|
update := bson.M{
|
||||||
"$set": bson.M{
|
"$set": bson.M{
|
||||||
"accountdata.attempts": (student.AccountData.Attempts + 1),
|
"Account.attempts": (student.Account.Attempts + 1),
|
||||||
"updated_at": update_time,
|
"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_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
update := bson.M{
|
update := bson.M{
|
||||||
"$set": bson.M{
|
"$set": bson.M{
|
||||||
"accountdata.attempts": 0,
|
"Account.attempts": 0,
|
||||||
"updated_at": update_time,
|
"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{
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": "Student Accound Disabled, Contact and Admin",
|
"message": "Student Accound Disabled, Contact and Admin",
|
||||||
|
|||||||
@@ -369,10 +369,10 @@ 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{
|
||||||
"accountdata.accountdisabled": false,
|
"Account.accountdisabled": false,
|
||||||
"accountdata.alerted": false,
|
"Account.alerted": false,
|
||||||
"accountdata.attempts": 0,
|
"Account.attempts": 0,
|
||||||
"updated_at": update_time,
|
"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_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
update := bson.M{
|
update := bson.M{
|
||||||
"$set": bson.M{
|
"$set": bson.M{
|
||||||
"accountdata.accountdisabled": false,
|
"Account.accountdisabled": false,
|
||||||
"accountdata.attempts": 0,
|
"Account.attempts": 0,
|
||||||
"updated_at": update_time,
|
"updated_at": update_time,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -306,12 +306,12 @@ 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{
|
||||||
"accountdata.password": student.HashPassword(data["newpassword1"]),
|
"Account.password": student.HashPassword(data["newpassword1"]),
|
||||||
"accountdata.temppassword": false, // If it were a temp password, its not now
|
"Account.temppassword": false, // If it were a temp password, its not now
|
||||||
"updated_at": update_time,
|
"updated_at": update_time,
|
||||||
},
|
},
|
||||||
"$push": bson.M{
|
"$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_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
update := bson.M{
|
update := bson.M{
|
||||||
"$set": bson.M{
|
"$set": bson.M{
|
||||||
"accountdata.password": student.HashPassword(tempPass),
|
"Account.password": student.HashPassword(tempPass),
|
||||||
"accountdata.temppassword": true,
|
"Account.temppassword": true,
|
||||||
"updated_at": update_time,
|
"updated_at": update_time,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -161,12 +161,12 @@ func UpdateTeacherPassword(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{
|
||||||
"accountdata.password": teacher.HashPassword(data["newpassword1"]),
|
"Account.password": teacher.HashPassword(data["newpassword1"]),
|
||||||
"accountdata.temppassword": false, // If it were a temp password, its not now
|
"Account.temppassword": false, // If it were a temp password, its not now
|
||||||
"updated_at": update_time,
|
"updated_at": update_time,
|
||||||
},
|
},
|
||||||
"$push": bson.M{
|
"$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_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
update := bson.M{
|
update := bson.M{
|
||||||
"$set": bson.M{
|
"$set": bson.M{
|
||||||
"accountdata.password": teacher.HashPassword(tempPass),
|
"Account.password": teacher.HashPassword(tempPass),
|
||||||
"accountdata.temppassword": true,
|
"Account.temppassword": true,
|
||||||
"updated_at": update_time,
|
"updated_at": update_time,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ type Admin struct {
|
|||||||
|
|
||||||
func (a *Admin) EmailExists(email string) bool {
|
func (a *Admin) EmailExists(email string) bool {
|
||||||
var admin Admin
|
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
|
return findErr == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ type Student struct {
|
|||||||
YOG int `json:"yog"` // Year of Graduation
|
YOG int `json:"yog"` // Year of Graduation
|
||||||
PhotoName string `json:"photoname"` // name of photo in db
|
PhotoName string `json:"photoname"` // name of photo in db
|
||||||
} `json:"schooldata"`
|
} `json:"schooldata"`
|
||||||
AccountData struct {
|
Account struct {
|
||||||
VerifiedEmail bool `json:"verifiedemail"`
|
VerifiedEmail bool `json:"verifiedemail"`
|
||||||
SchoolEmail string `json:"schoolemail"`
|
SchoolEmail string `json:"schoolemail"`
|
||||||
Password string `json:"-" validate:"min=10,max=32"`
|
Password string `json:"-" validate:"min=10,max=32"`
|
||||||
@@ -54,13 +54,13 @@ type Student struct {
|
|||||||
TempPassword bool `json:"temppassword"`
|
TempPassword bool `json:"temppassword"`
|
||||||
Attempts int `json:"attempts"` // login attempts max 5
|
Attempts int `json:"attempts"` // login attempts max 5
|
||||||
HashHistory []string `json:"-"` // List of old hashed passwords (not including auto generated passwords)
|
HashHistory []string `json:"-"` // List of old hashed passwords (not including auto generated passwords)
|
||||||
} `json:"accountdata"`
|
} `json:"Account"`
|
||||||
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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Student) UsedPassword(password string) bool {
|
func (s *Student) UsedPassword(password string) bool {
|
||||||
for _, oldHash := range s.AccountData.HashHistory {
|
for _, oldHash := range s.Account.HashHistory {
|
||||||
if oldHash == s.HashPassword(password) {
|
if oldHash == s.HashPassword(password) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ func (s *Student) HashPassword(password string) string {
|
|||||||
|
|
||||||
func (s *Student) EmailExists(email string) bool {
|
func (s *Student) EmailExists(email string) bool {
|
||||||
var student Student
|
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
|
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
|
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
|
return valid == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ type Teacher struct {
|
|||||||
Homeroom string `json:"homeroom"`
|
Homeroom string `json:"homeroom"`
|
||||||
PhotoName string `json:"photoname"` // name of photo in db
|
PhotoName string `json:"photoname"` // name of photo in db
|
||||||
} `json:"schooldata"`
|
} `json:"schooldata"`
|
||||||
AccountData struct {
|
Account struct {
|
||||||
VerifiedEmail bool `json:"verifiedemail"`
|
VerifiedEmail bool `json:"verifiedemail"`
|
||||||
SchoolEmail string `json:"schoolemail"`
|
SchoolEmail string `json:"schoolemail"`
|
||||||
Password string `json:"-" validate:"min=10,max=32"`
|
Password string `json:"-" validate:"min=10,max=32"`
|
||||||
@@ -52,13 +52,13 @@ type Teacher struct {
|
|||||||
TempPassword bool `json:"temppassword"`
|
TempPassword bool `json:"temppassword"`
|
||||||
Attempts int `json:"attempts"` // login attempts max 5
|
Attempts int `json:"attempts"` // login attempts max 5
|
||||||
HashHistory []string `json:"-"` // List of old hashed passwords (not including auto generated passwords)
|
HashHistory []string `json:"-"` // List of old hashed passwords (not including auto generated passwords)
|
||||||
} `json:"accountdata"`
|
} `json:"Account"`
|
||||||
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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Teacher) UsedPassword(password string) bool {
|
func (t *Teacher) UsedPassword(password string) bool {
|
||||||
for _, oldHash := range t.AccountData.HashHistory {
|
for _, oldHash := range t.Account.HashHistory {
|
||||||
if oldHash == t.HashPassword(password) {
|
if oldHash == t.HashPassword(password) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ func (t *Teacher) HashPassword(password string) string {
|
|||||||
|
|
||||||
func (t *Teacher) EmailExists(email string) bool {
|
func (t *Teacher) EmailExists(email string) bool {
|
||||||
var teacher Teacher
|
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
|
return findErr == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ func (t *Teacher) GenerateSchoolEmail(offset int, lastEmail string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Teacher) ComparePasswords(password string) bool {
|
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
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user