update/admin-reenable-student
This commit is contained in:
1 parent
349a71e31c
commit
ee7ab8eff9
1 file changed
+62
@@ -244,6 +244,68 @@ func UpdateStudentEmail(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
func RemoveStudentsDisabled(c *fiber.Ctx) error {
|
||||
var data map[string]string
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
|
||||
if err := c.BodyParser(&data); err != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "Failed to parse body",
|
||||
"error": err,
|
||||
})
|
||||
}
|
||||
|
||||
// Ensure Authorized admin sent request
|
||||
if !AuthAdmin(c) {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "Unauthorized: only an admin can perform this action",
|
||||
})
|
||||
}
|
||||
|
||||
// Check required fields are included
|
||||
if data["sid"] == "" {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "missing required fields",
|
||||
})
|
||||
}
|
||||
|
||||
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||
update := bson.M{
|
||||
"$set": bson.M{
|
||||
"accountdisabled": false,
|
||||
"attempts": 0,
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
|
||||
result, 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 account could not be re-enabled",
|
||||
"error": updateErr,
|
||||
})
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully re-enabled student account",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateTeacherHomeroom(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||
"success": nil,
|
||||
|
||||
Reference in new issue
Block a user