From 459ddf542a73b7a5a833fc0744e710926537d1c4 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 14 Jun 2022 13:17:59 -0700 Subject: [PATCH] email users their id --- controllers/authController.go | 38 ++++++++++++- models/studentModel.go | 1 + models/teacherModel.go | 1 + templates/accountRegistered.html | 95 ++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 templates/accountRegistered.html diff --git a/controllers/authController.go b/controllers/authController.go index dd6171a..43d10bc 100644 --- a/controllers/authController.go +++ b/controllers/authController.go @@ -246,6 +246,18 @@ func Enroll(c *fiber.Ctx) error { } student.SchoolData.SID = sid + // Send student personal email student ID + subject = "Account Registered" + r = NewRequest([]string{receiver}, subject) + + if sent := r.Send("./templates/accountRegisreded.html", map[string]string{"username": student.PersonalData.FirstName, "id": sid, "userType": "student"}); !sent { + cancel() + return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{ + "success": false, + "message": "Could not send ID to students email", + }) + } + var pen string for { pen = GenerateID(9) @@ -382,6 +394,18 @@ func RegisterTeacher(c *fiber.Ctx) error { } teacher.SchoolData.TID = tid + // Send teacher personal email student ID + subject = "Account Registered" + r = NewRequest([]string{receiver}, subject) + + if sent := r.Send("./templates/accountRegisreded.html", map[string]string{"username": teacher.PersonalData.FirstName, "id": tid, "userType": "teacher"}); !sent { + cancel() + return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{ + "success": false, + "message": "Could not send ID to teachers email", + }) + } + teacher.Created_at, _ = time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) teacher.Updated_at, _ = time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) teacher.ID = primitive.NewObjectID() @@ -454,7 +478,7 @@ func CreateAdmin(c *fiber.Ctx) error { cancel() return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{ "success": false, - "message": "Could not send password to students email", + "message": "Could not send password to admins email", }) } @@ -467,6 +491,18 @@ func CreateAdmin(c *fiber.Ctx) error { } admin.AID = aid + // Send student personal email student ID + subject = "Account Registered" + r = NewRequest([]string{receiver}, subject) + + if sent := r.Send("./templates/accountRegisreded.html", map[string]string{"username": admin.FirstName, "id": aid, "userType": "admin"}); !sent { + cancel() + return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{ + "success": false, + "message": "Could not send ID to admins email", + }) + } + admin.Created_at, _ = time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) admin.Updated_at, _ = time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) admin.ID = primitive.NewObjectID() diff --git a/models/studentModel.go b/models/studentModel.go index 391c97b..73ca761 100644 --- a/models/studentModel.go +++ b/models/studentModel.go @@ -46,6 +46,7 @@ type Student struct { PhotoName string `json:"photoname"` // name of photo in db } `json:"schooldata"` AccountData struct { + VerifiedEmail bool `json:"verifiedemail"` SchoolEmail string `json:"schoolemail"` Password string `json:"-" validate:"min=10,max=32"` AccountDisabled bool `bson:"accountdisabled"` diff --git a/models/teacherModel.go b/models/teacherModel.go index 87304f2..b301451 100644 --- a/models/teacherModel.go +++ b/models/teacherModel.go @@ -45,6 +45,7 @@ type Teacher struct { PhotoName string `json:"photoname"` // name of photo in db } `json:"schooldata"` AccountData struct { + VerifiedEmail bool `json:"verifiedemail"` SchoolEmail string `json:"schoolemail"` Password string `json:"-" validate:"min=10,max=32"` AccountDisabled bool `bson:"accountdisabled"` diff --git a/templates/accountRegistered.html b/templates/accountRegistered.html new file mode 100644 index 0000000..5bf48e2 --- /dev/null +++ b/templates/accountRegistered.html @@ -0,0 +1,95 @@ + + + + + + Account Registered + + + + + + + + + + + + + + + + +
+ Account Registered +
+

+ Hi {{ .username }},
+ Your account has been registered into the system. You can now log into your account. +

+
+ + \ No newline at end of file