Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
165c17cdd6 |
No files matched your search
@@ -2,6 +2,5 @@ mongoURI=mongodb://localhost:27017
|
||||
dbo=school
|
||||
secret=<your 256 bit secret>
|
||||
PORT=8000
|
||||
SYSTEM_EMAIL_ADDRESS=<@exampleschoolemail.com>
|
||||
SYSTEM_EMAIL=<your system email>
|
||||
SYSTEM_PASSWORD=<your system password>
|
||||
+21
-758
@@ -7,52 +7,8 @@ The School Management API Documentation, defining all functions and their purpos
|
||||
* [Getting Started](#getting-started)
|
||||
* [General Functions](#general-functions)
|
||||
* [Creating Accounts](#creating-accounts)
|
||||
* [Creating Administrators](#creating-administrators)
|
||||
* [Registering a Teacher](#registering-a-teacher)
|
||||
* [Enrolling a Student](#enrolling-a-student)
|
||||
* [Additional Info](#additional-information-after-creating-an-account)
|
||||
* [Log into Accounts](#log-into-accounts)
|
||||
* [Logging Into Admin](#logging-into-admin)
|
||||
* [Logging Into Teacher](#logging-into-teacher)
|
||||
* [Logging Into Student](#logging-into-student)
|
||||
* [Get Account](#get-account)
|
||||
* [Get Admin Account](#get-admin-account)
|
||||
* [Get Teacher Account](#get-teacher-account)
|
||||
* [Get Student Account](#get-student-account)
|
||||
* [Updating Account information](#updating-accounts)
|
||||
* **Update Student...**
|
||||
* [Name](#update-student-name)
|
||||
* [Grade Level](#update-student-grade-level)
|
||||
* [Homeroom](#update-student-homeroom)
|
||||
* [Locker](#update-student-locker)
|
||||
* [YOG](#update-student-year-of-graduation)
|
||||
* [Password](#update-student-password)
|
||||
* [Email](#update-student-email)
|
||||
* [Address](#update-student-address)
|
||||
* [Photo](#update-student-photo)
|
||||
<br></br>
|
||||
* **Update Teacher...**
|
||||
* [Name](#update-teacher-name)
|
||||
* [Homeroom](#update-teacher-homeroom)
|
||||
* [Password](#update-teacher-password)
|
||||
* [Email](#update-teacher-email)
|
||||
* [Address](#update-teacher-address)
|
||||
* [Photo](#update-teacher-photo)
|
||||
<br></br>
|
||||
* **Update Admin...**
|
||||
* [Name](#update-admin-name) - **(Coming Soon)**
|
||||
* [Password](#update-admin-password) - **(Coming Soon)**
|
||||
* [Email](#update-admin-email) - **(Coming Soon)**
|
||||
* [Photo](#update-admin-photo) - **(Coming Soon)**
|
||||
* [Managing Contacts](#managing-contacts) - **(Not Documented)**
|
||||
* [Create Contact](#create-contact) - **(Not Documented)**
|
||||
* [Update Contact Name](#update-contact-name) - **(Not Documented)**
|
||||
* [Update Contact Address](#update-contact-address) - **(Not Documented)**
|
||||
* [Update Contact Home Phone](#update-contact-home-phone) - **(Not Documented)**
|
||||
* [Update Contact Work Phone](#update-contact-work-phone) - **(Not Documented)**
|
||||
* [Update Contact Email](#update-contact-email) - **(Not Documented)**
|
||||
* [Update Contact Priority](#update-contact-priority) - **(Not Documented)**
|
||||
* [Delete Contact](#delete-contact) - **(Not Documented)**
|
||||
|
||||
<br>
|
||||
|
||||
@@ -62,7 +18,7 @@ The School Management API Documentation, defining all functions and their purpos
|
||||
The API is an all in one package and is simple and easy to deploy. Eliminating any long unforgiving configurations you may face in other software.
|
||||
|
||||
1. Clone the repo
|
||||
```bash
|
||||
```
|
||||
$ git clone https://github.com/SowinskiBraeden/school-management-api
|
||||
$ cd school-management-api
|
||||
```
|
||||
@@ -70,7 +26,7 @@ The School Management API Documentation, defining all functions and their purpos
|
||||
2. Rename `.env.example` to `.env`
|
||||
|
||||
3. Enter desired values into `.env`
|
||||
```bash
|
||||
```
|
||||
mongoURI='your mongo URI'
|
||||
dbo='school'
|
||||
secret='your 256 bit secret'
|
||||
@@ -85,14 +41,14 @@ The School Management API Documentation, defining all functions and their purpos
|
||||
```
|
||||
|
||||
4. Run the system in your terminal
|
||||
```bash
|
||||
```
|
||||
$ go run main.go
|
||||
```
|
||||
|
||||
Or...
|
||||
|
||||
5. Build and compile the system into an executable
|
||||
```bash
|
||||
```
|
||||
$ go build
|
||||
```
|
||||
|
||||
@@ -120,7 +76,7 @@ The School Management API Documentation, defining all functions and their purpos
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
```
|
||||
{
|
||||
"success": true,
|
||||
"message": "the API is active"
|
||||
@@ -136,17 +92,17 @@ There are several account that can be registered into the system. As you may gue
|
||||
<br>
|
||||
|
||||
+ ### Creating Administrators
|
||||
You can create Administrates- who will have permissions to perform majority of the actions in the API. It is common that there are more than one Administrator to help manage the system.
|
||||
You can create Administratos who will have permissions to perform majority of the actions in the API. It is common that there are more than one Administrator to help manage the system.
|
||||
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/admin/create
|
||||
<API_URL>/admin/create
|
||||
```
|
||||
|
||||
**Required:**
|
||||
+ Logged into an existing Admin account
|
||||
+ JSON:
|
||||
```jsonc
|
||||
```
|
||||
{
|
||||
"firstname": "John",
|
||||
"lastname": "Doe",
|
||||
@@ -158,7 +114,7 @@ There are several account that can be registered into the system. As you may gue
|
||||
**Returns:**
|
||||
+ Status 200: `OK`
|
||||
+ JSON:
|
||||
```jsonc
|
||||
```
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully inserted admin"
|
||||
@@ -168,17 +124,17 @@ There are several account that can be registered into the system. As you may gue
|
||||
<br>
|
||||
|
||||
+ ### Registering a Teacher
|
||||
Obviously a school management system will require teachers to manage and teach students. Teachers have an important role for the system.
|
||||
Obviosuly a school management system will require teachers to manage and teach students. Teachers have an important role for the system.
|
||||
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/teacher/register
|
||||
<API_URL>/teacher/register
|
||||
```
|
||||
|
||||
**Required:**
|
||||
+ Logged into an existing Admin account
|
||||
+ JSON:
|
||||
```jsonc
|
||||
```
|
||||
{
|
||||
"firstname": "Homer",
|
||||
"middlename": "Jay",
|
||||
@@ -191,7 +147,7 @@ There are several account that can be registered into the system. As you may gue
|
||||
**Returns:**
|
||||
+ Status 200: `OK`
|
||||
+ JSON:
|
||||
```jsonc
|
||||
```
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully inserted teacher"
|
||||
@@ -199,17 +155,17 @@ There are several account that can be registered into the system. As you may gue
|
||||
```
|
||||
|
||||
+ ### Enrolling a Student
|
||||
What is a school without students? A professional day, but not the point. Students when their application to the school has been accepted by an admin can be enrolled into the school.
|
||||
What is a school withouth students? A professional day, but not the point. Students when their application to the school has been accepted by an admin can be enrolled into the school.
|
||||
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/student/enroll
|
||||
<API_URL>/student/enroll
|
||||
```
|
||||
|
||||
**Required:**
|
||||
+ Logged into an existing Admin account
|
||||
+ JSON:
|
||||
```jsonc
|
||||
```
|
||||
{
|
||||
"firstname": "Bart",
|
||||
"middlename": "JoJo",
|
||||
@@ -227,714 +183,21 @@ There are several account that can be registered into the system. As you may gue
|
||||
**Returns:**
|
||||
+ Status 200: `OK`
|
||||
+ JSON:
|
||||
```jsonc
|
||||
```
|
||||
{
|
||||
"success": true,
|
||||
"successfully inserted student"
|
||||
}
|
||||
```
|
||||
|
||||
+ ### Additional Information After creating an account
|
||||
1. After successfully creating an account for another admin, teacher or student. A school email will be generated for them using their first and last name, each formatted differently based on the type of account.
|
||||
1. After successfully creating an account for another admin, teacher or student. A school email will be generated for them using their first and last name, each formated differently based on the type of account.
|
||||
|
||||
2. All users are given a random ID used to sign into the system. Each ID is a random 6 digit number.
|
||||
|
||||
3. Students are given a random PEN (Personal Education Number). A random 12 digit number.
|
||||
|
||||
4. Accounts are given a default profile image. This can be updated in the future.
|
||||
4. Accounts are given a defaul profile image. This can be updated in the future.
|
||||
|
||||
**(Coming Soon)**
|
||||
5. All new users, once have verified their email, will receive and email containing their ID.
|
||||
5. All new users, once have verified their email, will recieve and email containing their ID.
|
||||
|
||||
**(Currently No verified email required)**
|
||||
6. All new users, once have verified their email, will receive and email containing their temporary password.
|
||||
|
||||
<br>
|
||||
|
||||
## Log Into Accounts
|
||||
|
||||
+ ### Logging into Admin
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/admin/login
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"tid": "123456",
|
||||
"password": "myawesomepassword123"
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```
|
||||
{
|
||||
"success": true,
|
||||
"message": "correct password"
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
+ ### Logging into Teacher
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/teacher/login
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"tid": "123456",
|
||||
"password": "myawesomepassword123"
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "correct password"
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
+ ### Logging into Student
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/student/login
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"sid": "123456",
|
||||
"password": "myawesomepassword123"
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "correct password"
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## Get Account
|
||||
|
||||
+ ### Get Admin Account
|
||||
**Method:** `GET`
|
||||
```
|
||||
<API_URL>/api/v1/admin
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into an admin account
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully logged into admin",
|
||||
"admin:" <admin object>
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
+ ### Get Teacher Account
|
||||
**Method:** `GET`
|
||||
```
|
||||
<API_URL>/api/v1/teacher
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into an teacher account
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully logged into teacher",
|
||||
"teacher:" <teacher object>
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
+ ### Get Student Account
|
||||
**Method:** `GET`
|
||||
```
|
||||
<API_URL>/api/v1/student
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into an admin account
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully logged into teacher",
|
||||
"student:" <student object>
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## Updating Account Information
|
||||
|
||||
+ ### Update Student Name
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/student/updateName
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into an admin account
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"sid": "123456",
|
||||
"firstname": "Lisa",
|
||||
"middlename": "Marie", // (OPTIONAL)
|
||||
"lastname": "Simpson"
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully updated student"
|
||||
}
|
||||
```
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Student Grade Level
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/student/updateGradeLevel
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into an admin account
|
||||
* JSON":
|
||||
```jsonc
|
||||
{
|
||||
"sid": "123456",
|
||||
"gradelevel": 11
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully updated student"
|
||||
}
|
||||
```
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Student Homeroom
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/student/updateHomeroom
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into an admin account
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"sid": "123456",
|
||||
"homeroom": "A123"
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully updated student"
|
||||
}
|
||||
```
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Student Locker
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/student/updateLocker
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into an admin account
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"sid": "123456",
|
||||
"lockernumber": "B123"
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully updated student"
|
||||
}
|
||||
```
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Student Year of Graduation
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/student/updateYOG
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into an admin account
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"sid": "123456",
|
||||
"yog": 2020
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully updated student"
|
||||
}
|
||||
```
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Student Password
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/student/updatePassword
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into students account
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"password": "myOldPassword",
|
||||
"newpassword1": "myNewPassword",
|
||||
"newpassword2": "myNewPassword"
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully updated student password"
|
||||
}
|
||||
```
|
||||
* Emails student an alert of password change
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Student Email
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/student/updateEmail
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into an admin account
|
||||
__or__
|
||||
* Logged into students account
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"sid": "123456", // (Only required if signed in as admin)
|
||||
"email": "BartSimpsonsCoolEmail@example.com"
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully updated"
|
||||
}
|
||||
```
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Student Address
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/student/updateAddress
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into an admin account
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"sid": "123456",
|
||||
"address": "742 Evergreen Terrace",
|
||||
"city": "Springfield",
|
||||
"province": "...",
|
||||
"postal": "..."
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully updated student"
|
||||
}
|
||||
```
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Student Photo
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/student/updatePhoto
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into an admin account
|
||||
* Form Submission:
|
||||
```
|
||||
sid: "123456"
|
||||
image: newStudentPhoto.png
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully updated student photo"
|
||||
}
|
||||
```
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Teacher Name
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/teacher/updateName
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into an admin account
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"tid": "123456",
|
||||
"firstname": "Marjorie",
|
||||
"middlename": "Jacqueline", // (Optional)
|
||||
"lastname": "Simpson"
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully updated teacher"
|
||||
}
|
||||
```
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Teacher Homeroom
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/teacher/updateHomeroom
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into an admin account
|
||||
* JSON:
|
||||
```
|
||||
{
|
||||
"tid": "123456",
|
||||
"homeroom": "A123"
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully updated teacher"
|
||||
}
|
||||
```
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Teacher Password
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/teacher/updatePassword
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into teacher account
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"password": "myOldPassword",
|
||||
"newpassword1": "myNewPassword",
|
||||
"newpassword2": "myNewPassword"
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully updated teacher password"
|
||||
}
|
||||
```
|
||||
* Emails teacher an alert of password change
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Teacher Email
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/teacher/updateEmail
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into an admin account
|
||||
**or**
|
||||
* Logged into teachers account
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"tid": "123456", // (Only required if igned in as admin)
|
||||
"email": "MargeSimpson@example.com"
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully updated teacher"
|
||||
}
|
||||
```
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Teacher Address
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/teacher/updateAddress
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into an admin account
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"tid": "123456",
|
||||
"address": "742 Evergreen Terrace",
|
||||
"city": "Springfield",
|
||||
"province": "...",
|
||||
"postal": "..."
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully updated teacher"
|
||||
}
|
||||
```
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Teacher Photo
|
||||
**Method:** `POST`
|
||||
```
|
||||
<API_URL>/api/v1/teacher/updatePhoto
|
||||
```
|
||||
|
||||
**Required:**
|
||||
* Logged into an admin
|
||||
* Form Submission:
|
||||
```
|
||||
tid: "123456"
|
||||
image: newTeacherPhoto.png
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
* Status 200: `OK`
|
||||
* JSON:
|
||||
```jsonc
|
||||
{
|
||||
"success": true,
|
||||
"message": "successfully updated teacher photo"
|
||||
}
|
||||
```
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Admin Name
|
||||
**Coming Soon...**
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Admin Password
|
||||
**Coming Soon...**
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Admin Email
|
||||
**Coming Soon...**
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Admin Photo
|
||||
**Coming Soon...**
|
||||
|
||||
<br></br>
|
||||
|
||||
## Managing Conacts
|
||||
**To be Documented...**
|
||||
|
||||
+ ### Creating Contact
|
||||
**To be Documented...**
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Contact Name
|
||||
**To be Documented...**
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Contact Address
|
||||
**To be Documented...**
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Contact Home Phone
|
||||
**To be Documented...**
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Contact Work Phone
|
||||
**To be Documented...**
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Contact Email
|
||||
**To be Documented...**
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Update Contact Priority
|
||||
**To be Documented...**
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Delete Conotact
|
||||
**To be Documented...**
|
||||
|
||||
<br></br>
|
||||
|
||||
## Remove Users
|
||||
**To be Documented...**
|
||||
|
||||
+ ### Remove Admin
|
||||
**To be Documented...**
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Remove Teacher
|
||||
**To be Documented...**
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Remove Student
|
||||
**To be Documented...**
|
||||
|
||||
<br></br>
|
||||
|
||||
### Admin Commands
|
||||
Administrators play a very important role in managing a school, they do much work behind the scenes to make sure that everything is correctly organized and working.
|
||||
|
||||
+ ### Update Locker Combination
|
||||
**To be Documented...**
|
||||
|
||||
<br></br>
|
||||
|
||||
+ ### Enable Student Account
|
||||
In the case a students acount has been disabled, an admin would require to enable the account.
|
||||
|
||||
**To be Documented...**
|
||||
<br></br>
|
||||
|
||||
+ ### Enable Teacher Account
|
||||
In the case a teachers acount has been disabled, an admin would require to enable the account.
|
||||
|
||||
**To be Documented...**
|
||||
<br></br>
|
||||
6. All new users, once have verified their email, will recieve and email containing their temporary password.
|
||||
@@ -63,7 +63,9 @@ func CreateDefaultAdmin() models.Admin {
|
||||
admin.LastName = lastname
|
||||
admin.Email = email
|
||||
|
||||
admin.SchoolEmail = admin.GenerateSchoolEmail()
|
||||
temp := admin.GenerateSchoolEmail()
|
||||
fmt.Println(temp)
|
||||
admin.SchoolEmail = temp
|
||||
|
||||
pass := strings.TrimSuffix(string(password), "\n")
|
||||
admin.Password = admin.HashPassword(pass)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/SowinskiBraeden/school-management-api/database"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
var courseCollection *mongo.Collection = database.OpenCollection(database.Client, "courses")
|
||||
|
||||
func CreateCourse(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||
"success": true,
|
||||
})
|
||||
}
|
||||
|
||||
func DeleteCourse(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||
"success": true,
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateCourseCode(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||
"success": true,
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateCourseName(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||
"success": true,
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateCourseCredit(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||
"success": true,
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateCourseGradelevel(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||
"success": true,
|
||||
})
|
||||
}
|
||||
+55
-323
@@ -145,7 +145,7 @@ func UpdateStudentGradeLevel(c *fiber.Ctx) error {
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := studentCollection.UpdateOne(
|
||||
result, updateErr := studentCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"schooldata.sid": data["sid"].(string)},
|
||||
update,
|
||||
@@ -163,6 +163,7 @@ func UpdateStudentGradeLevel(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated student",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -216,7 +217,7 @@ func UpdateStudentHomeroom(c *fiber.Ctx) error {
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := studentCollection.UpdateOne(
|
||||
result, updateErr := studentCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"schooldata.sid": data["sid"]},
|
||||
update,
|
||||
@@ -234,6 +235,7 @@ func UpdateStudentHomeroom(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated student",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -320,7 +322,7 @@ func UpdateStudentPassword(c *fiber.Ctx) error {
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := studentCollection.UpdateOne(
|
||||
result, updateErr := studentCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"schooldata.sid": claims.Issuer},
|
||||
update,
|
||||
@@ -350,6 +352,7 @@ func UpdateStudentPassword(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated student password",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -488,7 +491,7 @@ func UpdateStudentLocker(c *fiber.Ctx) error {
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := studentCollection.UpdateOne(
|
||||
result, updateErr := studentCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"schooldata.sid": data["sid"]},
|
||||
update,
|
||||
@@ -506,6 +509,7 @@ func UpdateStudentLocker(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated student",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -551,7 +555,7 @@ func UpdateStudentAddress(c *fiber.Ctx) error {
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := studentCollection.UpdateOne(
|
||||
result, updateErr := studentCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"sid": data["sid"]},
|
||||
update,
|
||||
@@ -569,12 +573,13 @@ func UpdateStudentAddress(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated student",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
// In the case a student gets held back a grade, we need to update their YOG (Year of Graduation)
|
||||
func UpdateStudentYOG(c *fiber.Ctx) error {
|
||||
var data map[string]interface{}
|
||||
var data map[string]string
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
|
||||
if err := c.BodyParser(&data); err != nil {
|
||||
@@ -596,7 +601,7 @@ func UpdateStudentYOG(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// Check required fields are included
|
||||
if data["sid"] == "" || data["yog"] == nil {
|
||||
if data["sid"] == "" {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"success": false,
|
||||
@@ -605,7 +610,7 @@ func UpdateStudentYOG(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
var student models.Student
|
||||
findErr := studentCollection.FindOne(context.TODO(), bson.M{"schooldata.sid": data["sid"].(string)}).Decode(&student)
|
||||
findErr := studentCollection.FindOne(context.TODO(), bson.M{"schooldata.sid": data["sid"]}).Decode(&student)
|
||||
if findErr != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
@@ -617,14 +622,14 @@ func UpdateStudentYOG(c *fiber.Ctx) error {
|
||||
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||
update := bson.M{
|
||||
"$set": bson.M{
|
||||
"schooldata.yog": data["yog"].(int),
|
||||
"schooldata.yog": student.SchoolData.YOG + 1,
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
|
||||
result, updateErr := studentCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"schooldata.sid": data["sid"].(string)},
|
||||
bson.M{"schooldata.sid": data["sid"]},
|
||||
update,
|
||||
)
|
||||
if updateErr != nil {
|
||||
@@ -884,7 +889,7 @@ func UpdateStudentPhoto(c *fiber.Ctx) error {
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
_, updateErr := imageCollection.UpdateOne(
|
||||
result, updateErr := imageCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"_id": photo.ID},
|
||||
update,
|
||||
@@ -905,6 +910,7 @@ func UpdateStudentPhoto(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated student photo",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -921,10 +927,8 @@ func UpdateStudentEmail(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
var sid string
|
||||
var verifiedStudent bool
|
||||
verifiedAdmin, _ := AuthenticateUser(c, 3)
|
||||
verifiedStudent, sid = AuthenticateUser(c, 1)
|
||||
verifiedStudent, sid := AuthenticateUser(c, 1)
|
||||
// Ensure Authenticated admin sent request
|
||||
if !verifiedAdmin && !verifiedStudent {
|
||||
cancel()
|
||||
@@ -934,16 +938,6 @@ func UpdateStudentEmail(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
if verifiedAdmin && data["sid"] == "" {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "missing required fields",
|
||||
})
|
||||
} else if verifiedAdmin {
|
||||
sid = data["sid"]
|
||||
}
|
||||
|
||||
// Check required fields are included
|
||||
if data["email"] == "" {
|
||||
cancel()
|
||||
@@ -1158,7 +1152,7 @@ func UpdateTeacherHomeroom(c *fiber.Ctx) error {
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := teacherCollection.UpdateOne(
|
||||
result, updateErr := teacherCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"schooldata.tid": data["tid"]},
|
||||
update,
|
||||
@@ -1176,6 +1170,7 @@ func UpdateTeacherHomeroom(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated teacher",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1208,7 +1203,7 @@ func UpdateTeacherPassword(c *fiber.Ctx) error {
|
||||
claims := token.Claims.(*jwt.StandardClaims)
|
||||
|
||||
var teacher models.Teacher
|
||||
findErr := teacherCollection.FindOne(ctx, bson.M{"schooldata.tid": claims.Issuer}).Decode(&teacher)
|
||||
findErr := studentCollection.FindOne(ctx, bson.M{"schooldata.tid": claims.Issuer}).Decode(&teacher)
|
||||
if findErr != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
@@ -1262,7 +1257,7 @@ func UpdateTeacherPassword(c *fiber.Ctx) error {
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := teacherCollection.UpdateOne(
|
||||
result, updateErr := teacherCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"schooldata.tid": claims.Issuer},
|
||||
update,
|
||||
@@ -1291,6 +1286,7 @@ func UpdateTeacherPassword(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated teacher password",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1420,7 +1416,7 @@ func UpdateTeacherAddress(c *fiber.Ctx) error {
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := teacherCollection.UpdateOne(
|
||||
result, updateErr := teacherCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"schooldata.tid": data["tid"]},
|
||||
update,
|
||||
@@ -1438,6 +1434,7 @@ func UpdateTeacherAddress(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated teacher",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1533,7 +1530,7 @@ func UpdateTeacherPhoto(c *fiber.Ctx) error {
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
_, updateErr := imageCollection.UpdateOne(
|
||||
result, updateErr := imageCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"_id": photo.ID},
|
||||
update,
|
||||
@@ -1554,6 +1551,7 @@ func UpdateTeacherPhoto(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated teacher photo",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1570,13 +1568,8 @@ func UpdateTeacherEmail(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
var tid string
|
||||
var verifiedTeacher bool
|
||||
|
||||
verifiedAdmin, _ := AuthenticateUser(c, 3)
|
||||
verifiedTeacher, tid = AuthenticateUser(c, 2)
|
||||
// Ensure Authenticated admin sent request
|
||||
if !verifiedAdmin && !verifiedTeacher {
|
||||
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||
"success": false,
|
||||
@@ -1584,18 +1577,8 @@ func UpdateTeacherEmail(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
if verifiedAdmin && data["tid"] == "" {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "missing required fields",
|
||||
})
|
||||
} else if verifiedAdmin {
|
||||
tid = data["tid"]
|
||||
}
|
||||
|
||||
// Check required fields are included
|
||||
if data["email"] == "" {
|
||||
if data["tid"] == "" || data["email"] == "" {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"success": false,
|
||||
@@ -1611,9 +1594,9 @@ func UpdateTeacherEmail(c *fiber.Ctx) error {
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := teacherCollection.UpdateOne(
|
||||
result, updateErr := teacherCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"schooldata.tid": tid},
|
||||
bson.M{"schooldata.tid": data["tid"]},
|
||||
update,
|
||||
)
|
||||
if updateErr != nil {
|
||||
@@ -1629,6 +1612,7 @@ func UpdateTeacherEmail(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated teacher",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1675,23 +1659,17 @@ func UpdateTeacherName(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
var middlename string = ""
|
||||
|
||||
if data["middlename"] != "" {
|
||||
middlename = data["middlename"]
|
||||
}
|
||||
|
||||
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||
update := bson.M{
|
||||
"$set": bson.M{
|
||||
"personaldata.firstname": data["firstname"],
|
||||
"personaldata.middlename": middlename,
|
||||
"personaldata.middlename": data["middlename"],
|
||||
"personaldata.lastname": data["lastname"],
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := teacherCollection.UpdateOne(
|
||||
result, updateErr := teacherCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"schooldata.tid": data["tid"]},
|
||||
update,
|
||||
@@ -1709,6 +1687,7 @@ func UpdateTeacherName(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated teacher",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1753,7 +1732,7 @@ func UpdateContactName(c *fiber.Ctx) error {
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := contactCollection.UpdateOne(
|
||||
result, updateErr := contactCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"_id": data["_id"]},
|
||||
update,
|
||||
@@ -1771,6 +1750,7 @@ func UpdateContactName(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated contact",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1816,7 +1796,7 @@ func UpdateContactAddress(c *fiber.Ctx) error {
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := contactCollection.UpdateOne(
|
||||
result, updateErr := contactCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"_id": data["_id"]},
|
||||
update,
|
||||
@@ -1834,6 +1814,7 @@ func UpdateContactAddress(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated contact",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1876,7 +1857,7 @@ func UpdateContactHomePhone(c *fiber.Ctx) error {
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := contactCollection.UpdateOne(
|
||||
result, updateErr := contactCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"_id": data["_id"]},
|
||||
update,
|
||||
@@ -1894,6 +1875,7 @@ func UpdateContactHomePhone(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated contact",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1936,7 +1918,7 @@ func UpdateContactWorkPhone(c *fiber.Ctx) error {
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := contactCollection.UpdateOne(
|
||||
result, updateErr := contactCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"_id": data["_id"]},
|
||||
update,
|
||||
@@ -1954,6 +1936,7 @@ func UpdateContactWorkPhone(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated contact",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1996,7 +1979,7 @@ func UpdateContactEmail(c *fiber.Ctx) error {
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := contactCollection.UpdateOne(
|
||||
result, updateErr := contactCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"_id": data["_id"]},
|
||||
update,
|
||||
@@ -2014,6 +1997,7 @@ func UpdateContactEmail(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated contact",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2056,7 +2040,7 @@ func UpdateContactPriority(c *fiber.Ctx) error {
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := contactCollection.UpdateOne(
|
||||
result, updateErr := contactCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"_id": data["_id"]},
|
||||
update,
|
||||
@@ -2074,6 +2058,7 @@ func UpdateContactPriority(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated contact",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2116,7 +2101,7 @@ func UpdateLockerCombo(c *fiber.Ctx) error {
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := lockerCollection.UpdateOne(
|
||||
result, updateErr := lockerCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"lockernumber": data["lockernumber"]},
|
||||
update,
|
||||
@@ -2134,6 +2119,7 @@ func UpdateLockerCombo(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated locker",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2178,7 +2164,7 @@ func RemoveStudent(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
_, deleteErr = studentCollection.DeleteOne(ctx, bson.M{"schooldata.sid": data["sid"]})
|
||||
result, deleteErr := studentCollection.DeleteOne(ctx, bson.M{"schooldata.sid": data["sid"]})
|
||||
if deleteErr != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
@@ -2192,6 +2178,7 @@ func RemoveStudent(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully deleted student",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2236,7 +2223,7 @@ func RemoveTeacher(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
_, deleteErr = teacherCollection.DeleteOne(ctx, bson.M{"schooldata.tid": data["tid"]})
|
||||
result, deleteErr := teacherCollection.DeleteOne(ctx, bson.M{"schooldata.tid": data["tid"]})
|
||||
if deleteErr != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
@@ -2250,6 +2237,7 @@ func RemoveTeacher(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully deleted teacher",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2294,7 +2282,7 @@ func RemoveAdmin(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
_, deleteErr = adminCollection.DeleteOne(ctx, bson.M{"aid": data["aid"]})
|
||||
result, deleteErr := adminCollection.DeleteOne(ctx, bson.M{"aid": data["aid"]})
|
||||
if deleteErr != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
@@ -2308,262 +2296,6 @@ func RemoveAdmin(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully deleted admin",
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateAdminName(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,
|
||||
})
|
||||
}
|
||||
|
||||
cookie := c.Cookies("jwt")
|
||||
|
||||
token, err := jwt.ParseWithClaims(cookie, &jwt.StandardClaims{}, func(token *jwt.Token) (interface{}, error) {
|
||||
return []byte(SecretKey), nil
|
||||
})
|
||||
if err != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "not authorized",
|
||||
})
|
||||
}
|
||||
|
||||
claims := token.Claims.(*jwt.StandardClaims)
|
||||
|
||||
var admin models.Admin
|
||||
findErr := adminCollection.FindOne(ctx, bson.M{"aid": claims.Issuer}).Decode(&admin)
|
||||
if findErr != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "admin not found",
|
||||
})
|
||||
}
|
||||
|
||||
// Check required fields are included
|
||||
if data["firstname"] == "" || data["lastname"] == "" {
|
||||
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{
|
||||
"firstname": data["firstname"],
|
||||
"lastname": data["lastname"],
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := teacherCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"aid": claims.Issuer},
|
||||
update,
|
||||
)
|
||||
if updateErr != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "the admin password could not be updated",
|
||||
"error": updateErr,
|
||||
})
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated admin",
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateAdminEmail(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,
|
||||
})
|
||||
}
|
||||
|
||||
cookie := c.Cookies("jwt")
|
||||
|
||||
token, err := jwt.ParseWithClaims(cookie, &jwt.StandardClaims{}, func(token *jwt.Token) (interface{}, error) {
|
||||
return []byte(SecretKey), nil
|
||||
})
|
||||
if err != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "not authorized",
|
||||
})
|
||||
}
|
||||
|
||||
claims := token.Claims.(*jwt.StandardClaims)
|
||||
|
||||
var admin models.Admin
|
||||
findErr := adminCollection.FindOne(ctx, bson.M{"aid": claims.Issuer}).Decode(&admin)
|
||||
if findErr != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "admin not found",
|
||||
})
|
||||
}
|
||||
|
||||
// Check required fields are included
|
||||
if data["email"] == "" {
|
||||
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{
|
||||
"email": data["email"],
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := teacherCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"aid": claims.Issuer},
|
||||
update,
|
||||
)
|
||||
if updateErr != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "the admin password could not be updated",
|
||||
"error": updateErr,
|
||||
})
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated admin",
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateAdminPassword(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,
|
||||
})
|
||||
}
|
||||
|
||||
cookie := c.Cookies("jwt")
|
||||
|
||||
token, err := jwt.ParseWithClaims(cookie, &jwt.StandardClaims{}, func(token *jwt.Token) (interface{}, error) {
|
||||
return []byte(SecretKey), nil
|
||||
})
|
||||
if err != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "not authorized",
|
||||
})
|
||||
}
|
||||
|
||||
claims := token.Claims.(*jwt.StandardClaims)
|
||||
|
||||
var admin models.Admin
|
||||
findErr := adminCollection.FindOne(ctx, bson.M{"aid": claims.Issuer}).Decode(&admin)
|
||||
if findErr != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "admin not found",
|
||||
})
|
||||
}
|
||||
|
||||
// Check required fields are included
|
||||
if data["password"] == "" || data["newpassword1"] == "" || data["newpassword2"] == "" {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "missing required fields",
|
||||
})
|
||||
}
|
||||
|
||||
if !admin.ComparePasswords(data["password"]) {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "Your password is incorrect",
|
||||
})
|
||||
}
|
||||
|
||||
if data["newpassword1"] != data["newpassword2"] {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "Your new passwords must match",
|
||||
})
|
||||
}
|
||||
|
||||
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||
update := bson.M{
|
||||
"$set": bson.M{
|
||||
"password": admin.HashPassword(data["newpassword1"]),
|
||||
"temppassword": false, // If it were a temp password, its not now
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
|
||||
_, updateErr := teacherCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"aid": claims.Issuer},
|
||||
update,
|
||||
)
|
||||
if updateErr != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "the admin password could not be updated",
|
||||
"error": updateErr,
|
||||
})
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
subject := "Password Changed"
|
||||
receiver := admin.Email
|
||||
r := NewRequest([]string{receiver}, subject)
|
||||
|
||||
if sent := r.Send("./templates/selfPasswordChanged.html", map[string]string{"username": admin.FirstName}); !sent {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "Could not send password to admins email",
|
||||
})
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated admin password",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package models
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
@@ -26,8 +25,7 @@ type Admin struct {
|
||||
}
|
||||
|
||||
func (a *Admin) GenerateSchoolEmail() string {
|
||||
addr := os.Getenv("SYSTEM_EMAIL_ADDRESS")
|
||||
var email string = strings.ToLower(a.LastName) + "_" + strings.ToLower(string(a.FirstName[0])) + addr
|
||||
var email string = strings.ToLower(a.LastName) + "_" + strings.ToLower(string(a.FirstName[0])) + "@surreyschools.ca"
|
||||
// Add check to see if email already exists
|
||||
return email
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package models
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -82,16 +81,15 @@ func (s *Student) EmailExists(email string) bool {
|
||||
}
|
||||
|
||||
func (s *Student) GenerateSchoolEmail(offset int, lastEmail string) string {
|
||||
addr := os.Getenv("SYSTEM_EMAIL_ADDRESS")
|
||||
var email string = strings.ToLower(string(s.PersonalData.FirstName[0])) + "." + strings.ToLower(s.PersonalData.LastName) + addr
|
||||
var email string = strings.ToLower(string(s.PersonalData.FirstName[0])) + "." + strings.ToLower(s.PersonalData.LastName) + "@surreyschools.ca"
|
||||
if offset > 0 && offset < len([]rune(s.PersonalData.FirstName))-1 {
|
||||
email = lastEmail[:offset] + strings.ToLower(string(s.PersonalData.FirstName[offset])) + lastEmail[offset:] + addr
|
||||
email = lastEmail[:offset] + strings.ToLower(string(s.PersonalData.FirstName[offset])) + lastEmail[offset:]
|
||||
}
|
||||
if offset == len([]rune(s.PersonalData.FirstName))-1 {
|
||||
email = strings.ToLower(s.PersonalData.FirstName) + "." + strings.ToLower(s.PersonalData.LastName) + addr
|
||||
email = strings.ToLower(s.PersonalData.FirstName) + "." + strings.ToLower(s.PersonalData.LastName) + "@surreyschools.ca"
|
||||
}
|
||||
if offset > len([]rune(s.PersonalData.FirstName))-1 {
|
||||
email = strings.ToLower(s.PersonalData.FirstName) + "." + strings.ToLower(s.PersonalData.LastName) + strconv.Itoa(offset-len([]rune(s.PersonalData.FirstName))) + addr
|
||||
email = strings.ToLower(s.PersonalData.FirstName) + "." + strings.ToLower(s.PersonalData.LastName) + strconv.Itoa(offset-len([]rune(s.PersonalData.FirstName))) + "@surreyschools.ca"
|
||||
}
|
||||
return email
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package models
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -80,16 +79,15 @@ func (t *Teacher) EmailExists(email string) bool {
|
||||
}
|
||||
|
||||
func (t *Teacher) GenerateSchoolEmail(offset int, lastEmail string) string {
|
||||
addr := os.Getenv("SYSTEM_EMAIL_ADDRESS")
|
||||
var email string = strings.ToLower(t.PersonalData.LastName) + "_" + strings.ToLower(string(t.PersonalData.FirstName[0])) + addr
|
||||
var email string = strings.ToLower(t.PersonalData.LastName) + "_" + strings.ToLower(string(t.PersonalData.FirstName[0])) + "@surreyschools.ca"
|
||||
if offset > 0 && offset < len([]rune(t.PersonalData.FirstName))-1 {
|
||||
email = lastEmail[:strings.Index(lastEmail, "_")+offset+1] + strings.ToLower(string(t.PersonalData.FirstName[offset])) + addr
|
||||
email = lastEmail[:strings.Index(lastEmail, "_")+offset+1] + strings.ToLower(string(t.PersonalData.FirstName[offset])) + "@surreyschools.ca"
|
||||
}
|
||||
if offset == len([]rune(t.PersonalData.FirstName))-1 {
|
||||
email = strings.ToLower(t.PersonalData.LastName) + "_" + strings.ToLower(t.PersonalData.FirstName) + addr
|
||||
email = strings.ToLower(t.PersonalData.LastName) + "_" + strings.ToLower(t.PersonalData.FirstName) + "@surreyschools.ca"
|
||||
}
|
||||
if offset > len([]rune(t.PersonalData.FirstName))-1 {
|
||||
email = strings.ToLower(t.PersonalData.LastName) + "_" + strings.ToLower(t.PersonalData.FirstName) + strconv.Itoa(offset-len([]rune(t.PersonalData.FirstName))) + addr
|
||||
email = strings.ToLower(t.PersonalData.LastName) + "_" + strings.ToLower(t.PersonalData.FirstName) + strconv.Itoa(offset-len([]rune(t.PersonalData.FirstName))) + "@surreyschools.ca"
|
||||
}
|
||||
return email
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 36 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 34 KiB |
@@ -72,11 +72,6 @@ func Setup(app *fiber.App) {
|
||||
app.Post(routerPrefix+"/admin/create", controllers.CreateAdmin)
|
||||
app.Post(routerPrefix+"/admin/login", controllers.AdminLogin)
|
||||
|
||||
// Admin Update Handler
|
||||
app.Post(routerPrefix+"/admin/updateName", controllers.UpdateAdminName)
|
||||
app.Post(routerPrefix+"/admin/updateEmail", controllers.UpdateAdminEmail)
|
||||
app.Post(routerPrefix+"/admin/updatePassword", controllers.UpdateAdminPassword)
|
||||
|
||||
// General Command Handling
|
||||
app.Post(routerPrefix+"/admin/updateLockerCombo", controllers.UpdateLockerCombo)
|
||||
app.Post(routerPrefix+"/admin/enableStudent", controllers.RemoveStudentsDisabled)
|
||||
|
||||
Reference in new issue
Block a user