update/hash-pass-history

This commit is contained in:
SowinskiBraeden committed 2022-02-08 13:56:44 -08:00
1 parent 516eb8c9e0
commit c56dc732bd
2 files changed
+27 -6

No files matched your search

+12 -1
View File
@@ -258,7 +258,7 @@ func UpdateStudentPassword(c *fiber.Ctx) error {
claims := token.Claims.(*jwt.StandardClaims)
var student models.Student
findErr := studentCollection.FindOne(context.TODO(), bson.M{"schooldata.sid": claims.Issuer}).Decode(&student)
findErr := studentCollection.FindOne(ctx, bson.M{"schooldata.sid": claims.Issuer}).Decode(&student)
if findErr != nil {
cancel()
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
@@ -292,6 +292,14 @@ func UpdateStudentPassword(c *fiber.Ctx) error {
})
}
if student.UsedPassword(data["newpassword1"]) {
cancel()
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"success": false,
"message": "Your new password cannot be the same as a previous password",
})
}
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
update := bson.M{
"$set": bson.M{
@@ -299,6 +307,9 @@ func UpdateStudentPassword(c *fiber.Ctx) error {
"accountdata.temppassword": false, // If it were a temp password, its not now
"updated_at": update_time,
},
"$push": bson.M{
"accountdata.hashhistory": student.HashPassword(data["newpassword1"]),
},
}
result, updateErr := studentCollection.UpdateOne(