update/account-disabled

This commit is contained in:
SowinskiBraeden committed 2022-01-14 19:39:40 -08:00
1 parent 9681ded4d0
commit 349a71e31c
2 files changed
+59 -1

No files matched your search

+57 -1
View File
@@ -363,15 +363,71 @@ func StudentLogin(c *fiber.Ctx) error {
"error": err,
})
}
defer cancel()
var localAccountDisabled = false
if student.Attempts >= 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{
"accountdisabled": true,
"attempts": 0,
"updated_at": update_time,
},
}
_, updateErr := studentCollection.UpdateOne(
ctx,
bson.M{"sid": data["sid"]},
update,
)
if updateErr != nil {
cancel()
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"success": false,
"message": "the student could not be updated",
"error": updateErr,
})
}
}
if localAccountDisabled || student.AccountDisabled {
cancel()
return c.Status(fiber.StatusForbidden).JSON(fiber.Map{
"success": false,
"message": "Account is Disabled, contact an Admin",
})
}
var verified bool = student.ComparePasswords(data["password"])
if verified == false {
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
update := bson.M{
"$set": bson.M{
"attempts": student.Attempts + 1,
"updated_at": update_time,
},
}
_, updateErr := studentCollection.UpdateOne(
ctx,
bson.M{"sid": data["sid"]},
update,
)
cancel()
if updateErr != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"success": false,
"message": "the student could not be updated",
"error": updateErr,
})
}
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"success": false,
"message": "incorrect password",
})
}
defer cancel()
claims := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.StandardClaims{
Issuer: student.SID,
+2
View File
@@ -13,6 +13,7 @@ import (
type Student struct {
ID primitive.ObjectID `bson:"_id"`
AccountDisabled bool `bson:"accountdisabled"`
FirstName string `json:"firstname" validate:"required"`
MiddleName string `json:"middlename"`
LastName string `json:"lastname" validate:"required"`
@@ -22,6 +23,7 @@ type Student struct {
SchoolEmail string `json:"schoolemail"`
Password string `json:"-" validate:"min=10,max=32"`
TempPassword bool `json:"temppassword"`
Attempts int `json:"attempts"` // login attempts max 5
SID string `json:"sid"` // Student ID
PEN string `json:"ped"` // Personal Education Number
Homeroom string `json:"homeroom"`