simplify naming
This commit is contained in:
7 files changed
+49
-49
No files matched your search
@@ -267,16 +267,16 @@ func Enroll(c *fiber.Ctx) error {
|
||||
}
|
||||
offset++
|
||||
}
|
||||
student.AccountData.SchoolEmail = schoolEmail
|
||||
student.AccountData.HashHistory = []string{}
|
||||
student.Account.SchoolEmail = schoolEmail
|
||||
student.Account.HashHistory = []string{}
|
||||
|
||||
// Disable login block
|
||||
student.AccountData.AccountDisabled = false
|
||||
student.AccountData.Alerted = false
|
||||
student.AccountData.Attempts = 0
|
||||
student.Account.AccountDisabled = false
|
||||
student.Account.Alerted = false
|
||||
student.Account.Attempts = 0
|
||||
|
||||
student.AccountData.Password = student.HashPassword(data["password1"].(string))
|
||||
student.AccountData.TempPassword = false
|
||||
student.Account.Password = student.HashPassword(data["password1"].(string))
|
||||
student.Account.TempPassword = false
|
||||
|
||||
var sid string
|
||||
for {
|
||||
@@ -437,15 +437,15 @@ func RegisterTeacher(c *fiber.Ctx) error {
|
||||
}
|
||||
offset++
|
||||
}
|
||||
teacher.AccountData.SchoolEmail = schoolEmail
|
||||
teacher.AccountData.HashHistory = []string{}
|
||||
teacher.Account.SchoolEmail = schoolEmail
|
||||
teacher.Account.HashHistory = []string{}
|
||||
|
||||
// Disable login block
|
||||
teacher.AccountData.AccountDisabled = false
|
||||
teacher.AccountData.Attempts = 0
|
||||
teacher.Account.AccountDisabled = false
|
||||
teacher.Account.Attempts = 0
|
||||
|
||||
teacher.AccountData.Password = teacher.HashPassword(data["password1"].(string))
|
||||
teacher.AccountData.TempPassword = false
|
||||
teacher.Account.Password = teacher.HashPassword(data["password1"].(string))
|
||||
teacher.Account.TempPassword = false
|
||||
|
||||
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
|
||||
@@ -646,20 +646,20 @@ func StudentLogin(c *fiber.Ctx) error {
|
||||
|
||||
var verified bool = student.ComparePasswords(data["password"])
|
||||
var localAccountDisabled bool = false
|
||||
var localAttempts int = student.AccountData.Attempts
|
||||
var localAttempts int = student.Account.Attempts
|
||||
|
||||
if !verified {
|
||||
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
|
||||
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||
update := bson.M{
|
||||
"$set": bson.M{
|
||||
"accountdata.accountdisabled": true,
|
||||
"accountdata.alerted": true,
|
||||
"accountdata.attempts": 0,
|
||||
"Account.accountdisabled": true,
|
||||
"Account.alerted": true,
|
||||
"Account.attempts": 0,
|
||||
"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
|
||||
subject := "Account Disabled"
|
||||
receiver := student.Personal.Email
|
||||
@@ -708,7 +708,7 @@ func StudentLogin(c *fiber.Ctx) error {
|
||||
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||
update := bson.M{
|
||||
"$set": bson.M{
|
||||
"accountdata.attempts": (student.AccountData.Attempts + 1),
|
||||
"Account.attempts": (student.Account.Attempts + 1),
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
@@ -735,7 +735,7 @@ func StudentLogin(c *fiber.Ctx) error {
|
||||
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||
update := bson.M{
|
||||
"$set": bson.M{
|
||||
"accountdata.attempts": 0,
|
||||
"Account.attempts": 0,
|
||||
"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{
|
||||
"success": false,
|
||||
"message": "Student Accound Disabled, Contact and Admin",
|
||||
|
||||
@@ -369,9 +369,9 @@ func RemoveStudentsDisabled(c *fiber.Ctx) error {
|
||||
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||
update := bson.M{
|
||||
"$set": bson.M{
|
||||
"accountdata.accountdisabled": false,
|
||||
"accountdata.alerted": false,
|
||||
"accountdata.attempts": 0,
|
||||
"Account.accountdisabled": false,
|
||||
"Account.alerted": false,
|
||||
"Account.attempts": 0,
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
@@ -432,8 +432,8 @@ func RemoveTeachersDisabled(c *fiber.Ctx) error {
|
||||
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||
update := bson.M{
|
||||
"$set": bson.M{
|
||||
"accountdata.accountdisabled": false,
|
||||
"accountdata.attempts": 0,
|
||||
"Account.accountdisabled": false,
|
||||
"Account.attempts": 0,
|
||||
"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 := bson.M{
|
||||
"$set": bson.M{
|
||||
"accountdata.password": student.HashPassword(data["newpassword1"]),
|
||||
"accountdata.temppassword": false, // If it were a temp password, its not now
|
||||
"Account.password": student.HashPassword(data["newpassword1"]),
|
||||
"Account.temppassword": false, // If it were a temp password, its not now
|
||||
"updated_at": update_time,
|
||||
},
|
||||
"$push": bson.M{
|
||||
"accountdata.hashhistory": student.HashPassword(data["newpassword1"]),
|
||||
"Account.hashhistory": student.HashPassword(data["newpassword1"]),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -393,8 +393,8 @@ func ResetStudentPassword(c *fiber.Ctx) error {
|
||||
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||
update := bson.M{
|
||||
"$set": bson.M{
|
||||
"accountdata.password": student.HashPassword(tempPass),
|
||||
"accountdata.temppassword": true,
|
||||
"Account.password": student.HashPassword(tempPass),
|
||||
"Account.temppassword": true,
|
||||
"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 := bson.M{
|
||||
"$set": bson.M{
|
||||
"accountdata.password": teacher.HashPassword(data["newpassword1"]),
|
||||
"accountdata.temppassword": false, // If it were a temp password, its not now
|
||||
"Account.password": teacher.HashPassword(data["newpassword1"]),
|
||||
"Account.temppassword": false, // If it were a temp password, its not now
|
||||
"updated_at": update_time,
|
||||
},
|
||||
"$push": bson.M{
|
||||
"accountdata.hashhistory": teacher.HashPassword(data["newpassword1"]),
|
||||
"Account.hashhistory": teacher.HashPassword(data["newpassword1"]),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -246,8 +246,8 @@ func ResetTeacherPassword(c *fiber.Ctx) error {
|
||||
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||
update := bson.M{
|
||||
"$set": bson.M{
|
||||
"accountdata.password": teacher.HashPassword(tempPass),
|
||||
"accountdata.temppassword": true,
|
||||
"Account.password": teacher.HashPassword(tempPass),
|
||||
"Account.temppassword": true,
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ type Admin struct {
|
||||
|
||||
func (a *Admin) EmailExists(email string) bool {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ type Student struct {
|
||||
YOG int `json:"yog"` // Year of Graduation
|
||||
PhotoName string `json:"photoname"` // name of photo in db
|
||||
} `json:"schooldata"`
|
||||
AccountData struct {
|
||||
Account struct {
|
||||
VerifiedEmail bool `json:"verifiedemail"`
|
||||
SchoolEmail string `json:"schoolemail"`
|
||||
Password string `json:"-" validate:"min=10,max=32"`
|
||||
@@ -54,13 +54,13 @@ type Student struct {
|
||||
TempPassword bool `json:"temppassword"`
|
||||
Attempts int `json:"attempts"` // login attempts max 5
|
||||
HashHistory []string `json:"-"` // List of old hashed passwords (not including auto generated passwords)
|
||||
} `json:"accountdata"`
|
||||
} `json:"Account"`
|
||||
Created_at time.Time `json:"created_at"`
|
||||
Updated_at time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (s *Student) UsedPassword(password string) bool {
|
||||
for _, oldHash := range s.AccountData.HashHistory {
|
||||
for _, oldHash := range s.Account.HashHistory {
|
||||
if oldHash == s.HashPassword(password) {
|
||||
return true
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func (s *Student) HashPassword(password string) string {
|
||||
|
||||
func (s *Student) EmailExists(email string) bool {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
valid := bcrypt.CompareHashAndPassword([]byte(s.AccountData.Password), []byte(password))
|
||||
valid := bcrypt.CompareHashAndPassword([]byte(s.Account.Password), []byte(password))
|
||||
return valid == nil
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ type Teacher struct {
|
||||
Homeroom string `json:"homeroom"`
|
||||
PhotoName string `json:"photoname"` // name of photo in db
|
||||
} `json:"schooldata"`
|
||||
AccountData struct {
|
||||
Account struct {
|
||||
VerifiedEmail bool `json:"verifiedemail"`
|
||||
SchoolEmail string `json:"schoolemail"`
|
||||
Password string `json:"-" validate:"min=10,max=32"`
|
||||
@@ -52,13 +52,13 @@ type Teacher struct {
|
||||
TempPassword bool `json:"temppassword"`
|
||||
Attempts int `json:"attempts"` // login attempts max 5
|
||||
HashHistory []string `json:"-"` // List of old hashed passwords (not including auto generated passwords)
|
||||
} `json:"accountdata"`
|
||||
} `json:"Account"`
|
||||
Created_at time.Time `json:"created_at"`
|
||||
Updated_at time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (t *Teacher) UsedPassword(password string) bool {
|
||||
for _, oldHash := range t.AccountData.HashHistory {
|
||||
for _, oldHash := range t.Account.HashHistory {
|
||||
if oldHash == t.HashPassword(password) {
|
||||
return true
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func (t *Teacher) HashPassword(password string) string {
|
||||
|
||||
func (t *Teacher) EmailExists(email string) bool {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func (t *Teacher) GenerateSchoolEmail(offset int, lastEmail string) string {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user