Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6c5c29c92 | ||
|
|
a663f70e24 | ||
|
|
10dc621cac | ||
|
|
bee6c0093e | ||
|
|
cd9685fdf7 | ||
|
|
0c017082ee | ||
|
|
0338189ffa | ||
|
|
a092e82f7f | ||
|
|
fede9ff793 | ||
|
|
2914859505 | ||
|
|
ce964edcd4 | ||
|
|
b140869281 | ||
|
|
4c4bad4be0 | ||
|
|
807758d924 | ||
|
|
0d29e1f382 | ||
|
|
c3aaec9798 | ||
|
|
28b92f4eda | ||
|
|
bbe4ecf705 | ||
|
|
40886aa815 | ||
|
|
1bd0da305d | ||
|
|
06e0eea782 | ||
|
|
79acbc377a | ||
|
|
fdd5401b06 | ||
|
|
d7d19ffb2d | ||
|
|
1b643c0bc2 | ||
|
|
0f183559e5 | ||
|
|
46d46c71a6 | ||
|
|
60d87dcf35 | ||
|
|
322821289e | ||
|
|
27d84c3c99 | ||
|
|
cb7298077d | ||
|
|
135066bad2 | ||
|
|
b27da3f095 | ||
|
|
459ddf542a | ||
|
|
e2d085a534 | ||
|
|
61d97ea429 | ||
|
|
1692b77a99 | ||
|
|
9511270b71 | ||
|
|
a98b10c816 | ||
|
|
c025a00415 | ||
|
|
c05e3a3879 | ||
|
|
fa8acec7a8 | ||
|
|
7ed53fc539 | ||
|
|
315f33b3e7 | ||
|
|
3aa4f72b33 | ||
|
|
2071e94516 | ||
|
|
50e672849b | ||
|
|
956fe306e5 | ||
|
|
dcabacdc8c | ||
|
|
8032b79989 | ||
|
|
255ea25edf | ||
|
|
7e85215fcc | ||
|
|
84b8c1ae5e | ||
|
|
ca4020f0ee | ||
|
|
596533753c | ||
|
|
e97f185e22 | ||
|
|
fdd489345d | ||
|
|
724b61cc2e | ||
|
|
b456a02178 | ||
|
|
41e7ca4f87 | ||
|
|
ae88f5d149 | ||
|
|
421943d5d4 | ||
|
|
8ee6c40bde | ||
|
|
c83f05674e | ||
|
|
e8c3272677 | ||
|
|
974c512cd1 | ||
|
|
f177e8cef7 | ||
|
|
55ca35034e | ||
|
|
2ef9c71f59 | ||
|
|
f402b27222 | ||
|
|
7bd33decc9 | ||
|
|
456dab3d6f | ||
|
|
27eb0937c7 | ||
|
|
eb065c4142 | ||
|
|
22d41d04dc | ||
|
|
dd0cd7d76c | ||
|
|
52e1c0fb5b | ||
|
|
f8ff2cf90e | ||
|
|
66112d4158 | ||
|
|
39400b371a | ||
|
|
9d44f98ff1 | ||
|
|
c054e3f065 | ||
|
|
b708f1d815 | ||
|
|
471d1c94a0 | ||
|
|
f37e677dbf | ||
|
|
0bf7f538f4 | ||
|
|
2a17752e71 | ||
|
|
86a105e922 | ||
|
|
3f844a8220 | ||
|
|
109debbe99 | ||
|
|
6bb2607420 | ||
|
|
7573ebcdf4 | ||
|
|
13cb0bde26 | ||
|
|
c2945bc013 | ||
|
|
a1fffd12aa | ||
|
|
fbbb36e7d4 | ||
|
|
17dd4e9561 | ||
|
|
20e9ae19f3 | ||
|
|
360fc9ce66 | ||
|
|
9fecc6f696 | ||
|
|
8a8f8d4b87 | ||
|
|
65d79a8ee0 | ||
|
|
587b01b857 | ||
|
|
d6f86e5013 | ||
|
|
0a06f425ff | ||
|
|
5c0d6d8279 | ||
|
|
1813f1e79f | ||
|
|
e582745c07 | ||
|
|
73590ccbf9 | ||
|
|
a2d365625e | ||
|
|
1c1f0ee6f0 | ||
|
|
327f4f7d8d | ||
|
|
803bdb8fdd | ||
|
|
e50a779ec8 | ||
|
|
9d861d14c2 | ||
|
|
29d0456236 | ||
|
|
b0832d70bd | ||
|
|
9a4c3916eb | ||
|
|
bfaacebc2d | ||
|
|
39a732f007 | ||
|
|
4ebe4a4716 | ||
|
|
71d59f7227 | ||
|
|
d5636831dc | ||
|
|
996cf963ae | ||
|
|
fa1f6648a5 | ||
|
|
ffa58fd85b | ||
|
|
f0d0f4cd7e | ||
|
|
eec6c57e15 | ||
|
|
dc4b28ae4c | ||
|
|
e82b39d0b7 | ||
|
|
2ea40bfe6f | ||
|
|
9a09218f86 | ||
|
|
6ca42f3dd9 | ||
|
|
38a41169ad | ||
|
|
17027d89d2 | ||
|
|
bf08c023c1 | ||
|
|
dfdb6bf35a | ||
|
|
b206a2b22a | ||
|
|
27936cd012 | ||
|
|
22c87ee1de | ||
|
|
3f9511e77a | ||
|
|
2aa3530173 | ||
|
|
b9da4a5f43 | ||
|
|
f121be35b8 | ||
|
|
d66d497353 | ||
|
|
f7cc7abaa4 | ||
|
|
db41ea7cae | ||
|
|
2fb89c607c | ||
|
|
90cf967701 | ||
|
|
d6115844f2 | ||
|
|
c500ceff44 | ||
|
|
38cd356efb | ||
|
|
4d57a93e69 | ||
|
|
0493f8b147 | ||
|
|
de213b348a | ||
|
|
190daffced | ||
|
|
8ba683154a | ||
|
|
c39e1a221d | ||
|
|
2421c2e022 | ||
|
|
3d5171c53e | ||
|
|
e819998b7d | ||
|
|
9df8e3529c | ||
|
|
f024cc2f6c | ||
|
|
0bfc6049b5 | ||
|
|
6d071c3b65 | ||
|
|
0fd16b62f2 |
No files matched your search
@@ -1,6 +0,0 @@
|
|||||||
mongoURI=mongodb://localhost:27017
|
|
||||||
dbo=school
|
|
||||||
secret=
|
|
||||||
PORT=8000
|
|
||||||
SYSTEM_EMAIL=
|
|
||||||
SYSTEM_PASSWORD=
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
github: SowinskiBraeden
|
||||||
+9
-2
@@ -1,9 +1,16 @@
|
|||||||
# Environment
|
# Environment
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
# Vendor
|
||||||
|
/vendor/*
|
||||||
|
|
||||||
# Pycache
|
# Pycache
|
||||||
/test/__pycache__/*
|
/test/__pycache__/*
|
||||||
|
/test/util/__pycache__/*
|
||||||
|
/test/scheduleGenerator/__pycache__/*
|
||||||
|
|
||||||
|
# Test
|
||||||
|
/test/test.py
|
||||||
|
|
||||||
# Test output
|
# Test output
|
||||||
/test/schedule.json
|
/test/output/*
|
||||||
/test/students.json
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
<!-- CONTRIBUTING -->
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
|
|
||||||
|
|
||||||
If you have a suggestion that would make this better, please create a pull request. You can also simply open an issue with the tag "enhancement".
|
|
||||||
Don't forget to give the project a star! Thanks again!
|
|
||||||
|
|
||||||
1. Clone the Project
|
|
||||||
2. Create your Feature Branch (`git checkout -b update/AmazingFeature`)
|
|
||||||
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
|
|
||||||
4. Push to the Branch (`git push origin update/AmazingFeature`)
|
|
||||||
5. Open a Pull Request
|
|
||||||
+1357
File diff suppressed because it is too large.
Load diff
@@ -1,21 +1,674 @@
|
|||||||
MIT License
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
Copyright (c) 2022 Braeden Sowinski
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Preamble
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The GNU General Public License is a free, copyleft license for
|
||||||
copies or substantial portions of the Software.
|
software and other kinds of works.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
The licenses for most software and other practical works are designed
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
to take away your freedom to share and change the works. By contrast,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
share and change all versions of a program--to make sure it remains free
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
GNU General Public License for most of our software; it applies also to
|
||||||
SOFTWARE.
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
@@ -2,38 +2,56 @@
|
|||||||
|
|
||||||
The backend API for a school management system accessible by staff and students.
|
The backend API for a school management system accessible by staff and students.
|
||||||
|
|
||||||
<a href="https://github.com/SowinskiBraeden/school-management-api"><strong>Explore the docs »</strong></a>
|
***Explore the docs »***
|
||||||
<br>
|
* [Getting Started](#getting-started)
|
||||||
<br>
|
* [Usage/Documenation](#usage)
|
||||||
|
* [License](#license)
|
||||||
## About The Project
|
* [Contact](#contact)
|
||||||
|
|
||||||
Originally started as a personal project to improve my overall Go knowledge and skills, driven by the complains
|
|
||||||
of my current school management system for students to view their grades, credits, course selections etc. I took
|
|
||||||
this on as a full project to work on for my Software Engineering class and is now a staple of my work. I plan to
|
|
||||||
work on this till completion, starting with this API, and then the front end, learning new tricks and languages
|
|
||||||
along the way.
|
|
||||||
|
|
||||||
## Future Plans
|
|
||||||
|
|
||||||
After the majority completion of vital api functionalities such as the ability to update information, create new
|
|
||||||
information, generate information, delete information, authentication etc. I plan on creating a new repository
|
|
||||||
for a new frontier of this project. I plan on making the [School Management Website](https://github.com/SowinskiBraeden/school-management-website).
|
|
||||||
|
|
||||||
This is most likely going to be written in another programming language or framework I am unfamiliar with. The
|
|
||||||
idea is to have a modern designed website capable of being used easily on any device or platform. I may use the
|
|
||||||
[React.js](https://reactjs.org/) or [Vue.js](https://vuejs.org/) frameworks to build the front end design.
|
|
||||||
<br>
|
|
||||||
|
|
||||||
### Built With
|
### Built With
|
||||||
|
|
||||||
* [Golang](https://go.dev/)
|
* [Golang](https://go.dev/)
|
||||||
* [GoFiber](https://gofiber.io/)
|
* [GoFiber](https://gofiber.io/)
|
||||||
* [GoMongo Driver](https://docs.mongodb.com/drivers/go/current/)
|
* [GoMongo Driver](https://docs.mongodb.com/drivers/go/current/)
|
||||||
|
* [golang-jwt](https://github.com/golang-jwt/jwt)
|
||||||
|
|
||||||
|
## About The Project
|
||||||
|
|
||||||
|
Originally started as a personal project to improve my overall Go knowledge and skills, driven by the complaints
|
||||||
|
of my current school management system for students to view their grades, credits, course selections etc. I took
|
||||||
|
this on as a full project to work on for my Software Engineering class and is now a staple of my work. I plan to
|
||||||
|
work on this till completion, starting with this API, and then the front end, learning new tricks and languages
|
||||||
|
along the way.
|
||||||
|
|
||||||
|
Developing the API has has me face many challenges. With me developing my techniques in Go, and increasing my
|
||||||
|
ability to work with Go frameworks. Understanding the workflow of packages and the Go ecosystem.
|
||||||
|
|
||||||
|
I started by developing authentication; a solid footing to the project, without the authentication of users,
|
||||||
|
the rest of the project would fail to work. As the purpose of this API handles sensitive data on students.
|
||||||
|
|
||||||
|
Once the authentication was complete, I took to working on majority of the user data handling. Such as
|
||||||
|
setting, updating and or deleting user attributes. Building a few more key authentication features only
|
||||||
|
allowing the proper authenticated user, an admin, perfom many of the actions.
|
||||||
|
|
||||||
|
Once this was complete I started work on conceptualizing the next major step of the API. Course management,
|
||||||
|
including course selection, schedule generation, etc. This can be viewed in this [request](https://github.com/SowinskiBraeden/school-management-api/issues/5).
|
||||||
|
To start off on this new set of features, I decided to tackle the largest and most complex problem,
|
||||||
|
schedule generation. This algorithm generates a master timetable as well as updates the student schedule.
|
||||||
|
All the while keeping track of any errors for admins to handle personally. This can be found in `testing`,
|
||||||
|
The [schedule generation](/test/scheduleGenerator) file is of the latest version, version 3. Though this has
|
||||||
|
been moved to its own [repository](https://github.com/SowinskiBraeden/ScheduleGeneratorApp).
|
||||||
|
|
||||||
|
## Related Work
|
||||||
|
|
||||||
|
After the majority completion of vital api functionalities such as the ability to update information, create new
|
||||||
|
information, generate information, delete information, authentication etc. I have created a new repository
|
||||||
|
for the next frontier of this project. I am now concurrently working on the [School Management Website](https://github.com/SowinskiBraeden/school-management-vue).
|
||||||
|
|
||||||
|
The School Management Website, is going to be written using the [Vue.js](https://vuejs.org/) framework as there were issues trying to use Next.js in an [older test](https://github.com/SowinskiBraeden/school-management).
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
The systems is easy to start and your local machine. Eliminating and long unforgiving configurations you may face in other software.
|
The systems is easy to start and your local machine. Eliminating any long unforgiving configurations you may face in other software.
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
@@ -43,20 +61,34 @@ The systems is easy to start and your local machine. Eliminating and long unforg
|
|||||||
$ cd school-management-api
|
$ cd school-management-api
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Rename `.env.example` to `.env`
|
<br>
|
||||||
|
|
||||||
|
2. Rename `.env.example` to `.env`
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
3. Enter desired values into `.env`
|
3. Enter desired values into `.env`
|
||||||
```
|
```
|
||||||
mongoURI='your mongo URI'
|
mongoURI='your mongo URI'
|
||||||
dbo=school
|
dbo=school
|
||||||
secret='your secret'
|
secret='your 256 bit secret'
|
||||||
PORT='your desired port'
|
PORT='your desired port'
|
||||||
SYSTEM_EMAIL='your system email'
|
SYSTEM_EMAIL='your system email'
|
||||||
SYSTEM_PASSWORD='your system email password'
|
SYSTEM_PASSWORD='your system email password'
|
||||||
```
|
```
|
||||||
4. Run the sytem in your console
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
4. Run the system in your console
|
||||||
```
|
```
|
||||||
go run main.go
|
go run main.go
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* The first time the API is run, you will be promted to enter in the systems defualt administrator account detials.
|
||||||
|
This is required, in order to use majority of the API you'll need to be in an authenticated admin account.
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
5. Build and compile the system into an executable
|
5. Build and compile the system into an executable
|
||||||
```
|
```
|
||||||
go build
|
go build
|
||||||
@@ -68,12 +100,7 @@ The systems is easy to start and your local machine. Eliminating and long unforg
|
|||||||
|
|
||||||
The usage for this API is in the name, school management, it's not an easy task in the areas I live near. Overcrowded schools are far too common and the need for a better school management system is there. The current systems issued by the government work but are poor and outdated.
|
The usage for this API is in the name, school management, it's not an easy task in the areas I live near. Overcrowded schools are far too common and the need for a better school management system is there. The current systems issued by the government work but are poor and outdated.
|
||||||
|
|
||||||
|
To see a full list of features and how to use the system, read the [documentation](DOCUMENTATION.md)
|
||||||
<!-- CONTRIBUTING -->
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
Please refer to [CONTRIBUTING](CONTRIBUTING.md) for contributing to the project.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- LICENSE -->
|
<!-- LICENSE -->
|
||||||
@@ -85,6 +112,6 @@ Distributed under the MIT License. See [LICENSE](LICENSE) for more information.
|
|||||||
<!-- CONTACT -->
|
<!-- CONTACT -->
|
||||||
## Contact
|
## Contact
|
||||||
|
|
||||||
Braeden Sowinski - [@BraedenSowinski](https://twitter.com/BraedenSowinski) - sowinskibraeden@gmail.com
|
Braeden Sowinski - [@BraedenSowinski](https://twitter.com/BraedenSowinski) - sowinskibraeden@gmail.com - McDazzzled#5307 on Discord
|
||||||
|
|
||||||
Project Link: [https://github.com/SowinskiBraeden/school-management-api](https://github.com/SowinskiBraeden/school-management-api)
|
Project Link: [https://github.com/SowinskiBraeden/school-management-api](https://github.com/SowinskiBraeden/school-management-api)
|
||||||
+644
-214
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,78 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
|
"net/smtp"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Server string
|
||||||
|
Port int
|
||||||
|
Email string
|
||||||
|
Password string
|
||||||
|
}
|
||||||
|
|
||||||
|
var config Config = Config{
|
||||||
|
Server: "smtp.gmail.com",
|
||||||
|
Port: 587,
|
||||||
|
Email: os.Getenv("SYSTEM_EMAIL"),
|
||||||
|
Password: os.Getenv("SYSTEM_PASSWORD"),
|
||||||
|
}
|
||||||
|
|
||||||
|
type Request struct {
|
||||||
|
to []string
|
||||||
|
subject string
|
||||||
|
body string
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
MIME = "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewRequest(to []string, subject string) *Request {
|
||||||
|
return &Request{
|
||||||
|
to: to,
|
||||||
|
subject: subject,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Request) parseTemplate(fileName string, data interface{}) error {
|
||||||
|
t, err := template.ParseFiles(fileName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
buffer := new(bytes.Buffer)
|
||||||
|
if err = t.Execute(buffer, data); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
r.body = buffer.String()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Request) sendMail() bool {
|
||||||
|
body := "To: " + r.to[0] + "\r\nSubject: " + r.subject + "\r\n" + MIME + "\r\n" + r.body
|
||||||
|
SMTP := fmt.Sprintf("%s:%d", config.Server, config.Port)
|
||||||
|
if err := smtp.SendMail(SMTP, smtp.PlainAuth("", config.Email, config.Password, config.Server), config.Email, r.to, []byte(body)); err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Request) Send(templateName string, items interface{}) bool {
|
||||||
|
err := r.parseTemplate(templateName, items)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if ok := r.sendMail(); ok {
|
||||||
|
log.Printf("Email has been sent to %s\n", r.to)
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
log.Printf("Failed to send the email to %s\n", r.to)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,24 +14,22 @@ import (
|
|||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
var idCollection *mongo.Collection = database.OpenCollection(database.Client, "cids")
|
var IdCollection *mongo.Collection = database.OpenCollection(database.Client, "cids")
|
||||||
|
|
||||||
var table = [...]byte{'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}
|
var table = [...]byte{'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}
|
||||||
|
|
||||||
func ValidateID(id string) bool { // true: valid id, false: id already in use
|
func ValidateID(id string, userType int) bool { // true: valid id, false: id already in use
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
var foundID models.Id
|
var foundID models.Id
|
||||||
err := idCollection.FindOne(ctx, bson.M{"cid": id}).Decode(&foundID)
|
err := IdCollection.FindOne(ctx, bson.M{"cid": id}).Decode(&foundID)
|
||||||
cancel()
|
cancel()
|
||||||
if err != nil { // If there is no id found create new ID object to be stored and return true (unless insert error then try again)
|
if err != nil { // If there is no id found create new ID object to be stored and return true (unless insert error then try again)
|
||||||
var newID models.Id
|
var newID models.Id
|
||||||
newID.CID = id
|
newID.CID = id
|
||||||
|
newID.ParentType = userType
|
||||||
newID.ID = primitive.NewObjectID()
|
newID.ID = primitive.NewObjectID()
|
||||||
_, insertErr := idCollection.InsertOne(context.Background(), newID)
|
_, insertErr := IdCollection.InsertOne(context.Background(), newID)
|
||||||
if insertErr != nil {
|
return insertErr == nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -39,12 +37,9 @@ func ValidateID(id string) bool { // true: valid id, false: id already in use
|
|||||||
func ValidatePEN(pen string) bool { // true: valid pen, false: pen already in use
|
func ValidatePEN(pen string) bool { // true: valid pen, false: pen already in use
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
var foundID models.Id
|
var foundID models.Id
|
||||||
err := studentCollection.FindOne(ctx, bson.M{"schooldata.pen": pen}).Decode(&foundID)
|
err := StudentCollection.FindOne(ctx, bson.M{"school.pen": pen}).Decode(&foundID)
|
||||||
cancel()
|
cancel()
|
||||||
if err != nil {
|
return err != nil
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateID(length int) string {
|
func GenerateID(length int) string {
|
||||||
@@ -0,0 +1,461 @@
|
|||||||
|
package update
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
. "github.com/SowinskiBraeden/school-management-api/controllers"
|
||||||
|
"github.com/SowinskiBraeden/school-management-api/models"
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/golang-jwt/jwt"
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
Several of these functions aren't directly for updating admin
|
||||||
|
information, but for admins only to update information of other
|
||||||
|
object types such as lockers, enabling user accounts after being
|
||||||
|
disbaled, etc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
func UpdateLockerCombo(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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Unauthorized: only an admin can perform this action",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check locker number is included
|
||||||
|
if data["lockernumber"] == "" || data["newlockercombo"] == "" {
|
||||||
|
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{
|
||||||
|
"lockercombo": data["newlockercombo"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, updateErr := LockerCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"lockernumber": data["lockernumber"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the locker could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated locker",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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 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",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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 verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
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["uid"] == "" {
|
||||||
|
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{
|
||||||
|
"account.accountdisabled": false,
|
||||||
|
"account.alerted": false,
|
||||||
|
"account.attempts": 0,
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result, updateErr := StudentCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.sid": data["uid"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the student account could not be enabled",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully enabled student account",
|
||||||
|
"result": result,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveTeachersDisabled(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 verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
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["uid"] == "" {
|
||||||
|
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{
|
||||||
|
"account.accountdisabled": false,
|
||||||
|
"account.attempts": 0,
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result, updateErr := TeacherCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.tid": data["uid"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the teacher account could not be enabled",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully enabled teacher account",
|
||||||
|
"result": result,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,392 @@
|
|||||||
|
package update
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
. "github.com/SowinskiBraeden/school-management-api/controllers"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
)
|
||||||
|
|
||||||
|
func UpdateContactName(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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
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["_id"] == "" || data["firstname"] == "" || data["lastname"] == "" {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "missing required fields",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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{
|
||||||
|
"firstname": data["firstname"],
|
||||||
|
"middlename": middlename,
|
||||||
|
"lastname": data["lastname"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, updateErr := ContactCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"_id": data["_id"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the contact could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated contact",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateContactAddress(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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
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["_id"] == "" || data["address"] == "" || data["city"] == "" || data["province"] == "" || data["postal"] == "" {
|
||||||
|
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{
|
||||||
|
"address": data["address"],
|
||||||
|
"city": data["city"],
|
||||||
|
"province": data["province"],
|
||||||
|
"postal": data["postal"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, updateErr := ContactCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"_id": data["_id"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the contact could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated contact",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateContactHomePhone(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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Unauthorized: only an admin can perform this action",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check id of contact and new priority number is included
|
||||||
|
if data["_id"] == "" || data["newnumber"] == "" {
|
||||||
|
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{
|
||||||
|
"homephone": data["newnumber"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, updateErr := ContactCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"_id": data["_id"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "contact could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated contact",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateContactWorkPhone(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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Unauthorized: only an admin can perform this action",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check id of contact and new priority number is included
|
||||||
|
if data["_id"] == "" || data["newnumber"] == "" {
|
||||||
|
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{
|
||||||
|
"workphone": data["newnumber"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, updateErr := ContactCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"_id": data["_id"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "contact could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated contact",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateContactEmail(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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Unauthorized: only an admin can perform this action",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check id of contact and new priority number is included
|
||||||
|
if data["_id"] == "" || 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 := ContactCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"_id": data["_id"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "contact could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated contact",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateContactPriority(c *fiber.Ctx) error {
|
||||||
|
var data map[string]interface{}
|
||||||
|
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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Unauthorized: only an admin can perform this action",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check id of contact and new priority number is included
|
||||||
|
if data["_id"] == nil || data["priority"] == nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "missing required fields",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var priority int = data["priority"].(int)
|
||||||
|
|
||||||
|
if priority > 10 || priority < 1 {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "invalid priority",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
|
update := bson.M{
|
||||||
|
"$set": bson.M{
|
||||||
|
"priority": priority,
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, updateErr := ContactCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"_id": data["_id"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "contact could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated contact",
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,979 @@
|
|||||||
|
package update
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
. "github.com/SowinskiBraeden/school-management-api/controllers"
|
||||||
|
"github.com/SowinskiBraeden/school-management-api/models"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/golang-jwt/jwt"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
)
|
||||||
|
|
||||||
|
func toBase64(b []byte) string {
|
||||||
|
return base64.StdEncoding.EncodeToString(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStudentName(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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Unauthorized: only an admin can perform this action",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check id and names are included
|
||||||
|
// Middle name is optional
|
||||||
|
if data["uid"] == "" || data["firstname"] == "" || data["lastname"] == "" {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "missing required fields",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var updateMiddle bool = false
|
||||||
|
if data["middlename"] != "" {
|
||||||
|
updateMiddle = true
|
||||||
|
}
|
||||||
|
|
||||||
|
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
|
var update bson.M
|
||||||
|
if updateMiddle {
|
||||||
|
update = bson.M{
|
||||||
|
"$set": bson.M{
|
||||||
|
"personal.firstname": data["firstname"],
|
||||||
|
"personal.middlename": data["middlename"],
|
||||||
|
"personal.lastname": data["lastname"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
update = bson.M{
|
||||||
|
"$set": bson.M{
|
||||||
|
"personal.firstname": data["firstname"],
|
||||||
|
"personal.lastname": data["lastname"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result, updateErr := StudentCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.sid": data["uid"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the student could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated student",
|
||||||
|
"result": result,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStudentGradeLevel(c *fiber.Ctx) error {
|
||||||
|
var data map[string]interface{}
|
||||||
|
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 verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
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["uid"] == nil || data["gradelevel"] == nil {
|
||||||
|
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{
|
||||||
|
"school.gradelevel": data["gradelevel"].(float64),
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, updateErr := StudentCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.sid": data["uid"].(string)},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the student could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated student",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Far later on this function is going to be completely automated.
|
||||||
|
Instead of an admin sending a request to update the homeroom of
|
||||||
|
a student or teacher, the system will take the room number of
|
||||||
|
the teacher's or student's Block 2 class from their schedule.
|
||||||
|
|
||||||
|
Though this function would remain for students only, for example
|
||||||
|
a student requests a course change, if its their block 2 the
|
||||||
|
admin would have to alter their homeroom to be the new class
|
||||||
|
number.
|
||||||
|
*/
|
||||||
|
func UpdateStudentHomeroom(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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
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["uid"] == "" || data["homeroom"] == "" {
|
||||||
|
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{
|
||||||
|
"school.homeroom": data["homeroom"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, updateErr := StudentCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.sid": data["uid"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the student could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated student",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStudentPassword(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 student models.Student
|
||||||
|
findErr := StudentCollection.FindOne(ctx, bson.M{"school.sid": claims.Issuer}).Decode(&student)
|
||||||
|
if findErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "student 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 !student.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 password must match",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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{
|
||||||
|
"account.password": student.HashPassword(data["newpassword1"]),
|
||||||
|
"account.temppassword": false, // If it were a temp password, its not now
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
"$push": bson.M{
|
||||||
|
"account.hashhistory": student.HashPassword(data["newpassword1"]),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, updateErr := StudentCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.sid": claims.Issuer},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the student password could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
// Alert email the password has changed
|
||||||
|
subject := "Password Changed"
|
||||||
|
receiver := student.Personal.Email
|
||||||
|
r := NewRequest([]string{receiver}, subject)
|
||||||
|
|
||||||
|
if sent := r.Send("./templates/selfPasswordChanged.html", map[string]string{"username": student.Personal.FirstName}); !sent {
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "failed to send email to student",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated student password",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is for students to reset their password if they are unable to login
|
||||||
|
func ResetStudentPassword(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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check required fields are included (email must be personal email)
|
||||||
|
if data["uid"] == "" || data["email"] == "" {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "missing required fields",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var student models.Student
|
||||||
|
findErr := StudentCollection.FindOne(context.TODO(), bson.M{"school.sid": data["uid"]}).Decode(&student)
|
||||||
|
if findErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "student not found",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if student.Personal.Email != data["email"] {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Your personal email is incorrect",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
tempPass := student.GeneratePassword(12, 1, 1, 1)
|
||||||
|
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
|
update := bson.M{
|
||||||
|
"$set": bson.M{
|
||||||
|
"account.password": student.HashPassword(tempPass),
|
||||||
|
"account.temppassword": true,
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result, updateErr := StudentCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.sid": data["uid"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the student password could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
// Send student personal email temp password
|
||||||
|
subject := "Password Changed"
|
||||||
|
receiver := student.Personal.Email
|
||||||
|
r := NewRequest([]string{receiver}, subject)
|
||||||
|
|
||||||
|
if sent := r.Send("./templates/passwordChanged.html", map[string]string{"username": student.Personal.FirstName, "password": tempPass}); !sent {
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Could not send password to students email",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated student password",
|
||||||
|
"result": result,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStudentLocker(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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Unauthorized: only an admin can perform this action",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check id and locker are included
|
||||||
|
if data["uid"] == "" || data["lockernumber"] == "" {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "missing required fields",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var locker models.Locker
|
||||||
|
err := LockerCollection.FindOne(ctx, bson.M{"lockernumber": data["lockernumber"]}).Decode(&locker)
|
||||||
|
if err != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "locker not found",
|
||||||
|
"error": err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
|
update := bson.M{
|
||||||
|
"$set": bson.M{
|
||||||
|
"school.locker": locker.ID,
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, updateErr := StudentCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.sid": data["uid"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the student could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated student",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStudentAddress(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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
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["uid"] == "" || data["address"] == "" || data["city"] == "" || data["province"] == "" || data["postal"] == "" {
|
||||||
|
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{
|
||||||
|
"personal.address": data["address"],
|
||||||
|
"personal.city": data["city"],
|
||||||
|
"personal.province": data["province"],
|
||||||
|
"personal.postal": data["postal"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, updateErr := StudentCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"sid": data["uid"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the student could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated student",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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{}
|
||||||
|
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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
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["uid"] == "" || data["yog"] == nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "missing required fields",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var student models.Student
|
||||||
|
findErr := StudentCollection.FindOne(context.TODO(), bson.M{"school.sid": data["uid"].(string)}).Decode(&student)
|
||||||
|
if findErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "student not found",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
|
update := bson.M{
|
||||||
|
"$set": bson.M{
|
||||||
|
"school.yog": data["yog"].(int),
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result, updateErr := StudentCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.sid": data["uid"].(string)},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the student could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated student",
|
||||||
|
"result": result,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveStudentContact(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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Unauthorized: only an admin can perform this action",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check id and contact id are included
|
||||||
|
if data["uid"] == "" || data["contactid"] == "" {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "missing required fields",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var contact models.Contact
|
||||||
|
err := ContactCollection.FindOne(ctx, bson.M{"_id": data["contactid"]}).Decode(&contact)
|
||||||
|
if err != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "contact not found",
|
||||||
|
"error": err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
|
update := bson.M{
|
||||||
|
"$set": bson.M{
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
"$pull": bson.M{
|
||||||
|
"personal.contacts": contact.ID,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result, updateErr := StudentCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.sid": data["uid"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the contact could not be added",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully added contact",
|
||||||
|
"result": result,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddStudentContact(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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Unauthorized: only an admin can perform this action",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check id and contact id are included
|
||||||
|
if data["uid"] == "" || data["contactid"] == "" {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "missing required fields",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var contact models.Contact
|
||||||
|
err := ContactCollection.FindOne(ctx, bson.M{"_id": data["contactid"]}).Decode(&contact)
|
||||||
|
if err != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "contact not found",
|
||||||
|
"error": err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
|
update := bson.M{
|
||||||
|
"$set": bson.M{
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
"$push": bson.M{
|
||||||
|
"personal.contacts": contact.ID,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result, updateErr := StudentCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.sid": data["uid"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the contact could not be added",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully added contact",
|
||||||
|
"result": result,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStudentPhoto(c *fiber.Ctx) error {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
|
||||||
|
//Ensure Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Unauthorized: only an admin can perform this action",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
sid := c.FormValue("sid")
|
||||||
|
if sid == "" {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "missing required fields",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get student
|
||||||
|
var student models.Student
|
||||||
|
findErr := StudentCollection.FindOne(context.TODO(), bson.M{"school.sid": sid}).Decode(&student)
|
||||||
|
if findErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the student could not be found",
|
||||||
|
"error": findErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect image
|
||||||
|
file, err := c.FormFile("image")
|
||||||
|
if err != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the image could not be retrieved",
|
||||||
|
"error": err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get student photo
|
||||||
|
var photo models.Photo
|
||||||
|
findErr = ImageCollection.FindOne(context.TODO(), bson.M{"name": student.School.PhotoName}).Decode(&photo)
|
||||||
|
if findErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the student image could not be found",
|
||||||
|
"error": findErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save image to local
|
||||||
|
uniqueId := uuid.New()
|
||||||
|
filename := strings.Replace(uniqueId.String(), "-", "", -1)
|
||||||
|
fileExt := strings.Split(file.Filename, ".")[1]
|
||||||
|
image := fmt.Sprintf("%s.%s", filename, fileExt)
|
||||||
|
err = c.SaveFile(file, fmt.Sprintf("./database/images/%s", image))
|
||||||
|
if err != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the image could not be saved",
|
||||||
|
"error": err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the entire file into a byte slice
|
||||||
|
bytes, err := os.ReadFile(fmt.Sprintf("./database/images/%s", image))
|
||||||
|
if err != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the image could not be read",
|
||||||
|
"error": err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var base64Encoding string = toBase64(bytes)
|
||||||
|
|
||||||
|
// Update image name and base64 data
|
||||||
|
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
|
update := bson.M{
|
||||||
|
"$set": bson.M{
|
||||||
|
"base64": base64Encoding,
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_, updateErr := ImageCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"_id": photo.ID},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the image could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
// Remove local image
|
||||||
|
os.Remove(fmt.Sprintf("./database/images/%s", image))
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated student photo",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStudentEmail(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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var sid string
|
||||||
|
var verifiedStudent bool
|
||||||
|
verifiedAdmin, _ := AuthenticateUser(c, 3)
|
||||||
|
verifiedStudent, sid = AuthenticateUser(c, 1)
|
||||||
|
// Ensure Authenticated admin sent request
|
||||||
|
if !verifiedAdmin && !verifiedStudent {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Unauthorized: only an admin or teacher can perform this action",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if verifiedAdmin && data["uid"] == "" {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "missing required fields",
|
||||||
|
})
|
||||||
|
} else if verifiedAdmin {
|
||||||
|
sid = data["uid"]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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{
|
||||||
|
"personal.email": data["email"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result, updateErr := StudentCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.sid": 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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated student",
|
||||||
|
"result": result,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,621 @@
|
|||||||
|
package update
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
. "github.com/SowinskiBraeden/school-management-api/controllers"
|
||||||
|
|
||||||
|
"github.com/SowinskiBraeden/school-management-api/models"
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/golang-jwt/jwt"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
Far later on this function is going to be completely automated.
|
||||||
|
Instead of an admin sending a request to update the homeroom of
|
||||||
|
a student or teacher, the system will take the room number of
|
||||||
|
the teacher's or student's Block 2 class from their schedule.
|
||||||
|
|
||||||
|
Though this function would remain for students only, for example
|
||||||
|
a student requests a course change, if its their block 2 the
|
||||||
|
admin would have to alter their homeroom to be the new class
|
||||||
|
number.
|
||||||
|
*/
|
||||||
|
func UpdateTeacherHomeroom(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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
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["uid"] == "" || data["homeroom"] == "" {
|
||||||
|
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{
|
||||||
|
"school.homeroom": data["homeroom"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, updateErr := TeacherCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.tid": data["uid"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the teacher could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated teacher",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateTeacherPassword(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 teacher models.Teacher
|
||||||
|
findErr := TeacherCollection.FindOne(ctx, bson.M{"school.tid": claims.Issuer}).Decode(&teacher)
|
||||||
|
if findErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "teacher 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 !teacher.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",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if teacher.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{
|
||||||
|
"account.password": teacher.HashPassword(data["newpassword1"]),
|
||||||
|
"account.temppassword": false, // If it were a temp password, its not now
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
"$push": bson.M{
|
||||||
|
"account.hashhistory": teacher.HashPassword(data["newpassword1"]),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, updateErr := TeacherCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.tid": claims.Issuer},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the teacher password could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
subject := "Password Changed"
|
||||||
|
receiver := teacher.Personal.Email
|
||||||
|
r := NewRequest([]string{receiver}, subject)
|
||||||
|
|
||||||
|
if sent := r.Send("./templates/selfPasswordChanged.html", map[string]string{"username": teacher.Personal.FirstName}); !sent {
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Could not send password to teachers email",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated teacher password",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func ResetTeacherPassword(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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check required fields are included (email must be personal email)
|
||||||
|
if data["uid"] == "" || data["email"] == "" {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "missing required fields",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var teacher models.Teacher
|
||||||
|
findErr := TeacherCollection.FindOne(context.TODO(), bson.M{"school.tid": data["uid"]}).Decode(&teacher)
|
||||||
|
if findErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "teacher not found",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if teacher.Personal.Email != data["email"] {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Your personal email is incorrect",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
tempPass := teacher.GeneratePassword(12, 1, 1, 1)
|
||||||
|
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
|
update := bson.M{
|
||||||
|
"$set": bson.M{
|
||||||
|
"account.password": teacher.HashPassword(tempPass),
|
||||||
|
"account.temppassword": true,
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result, updateErr := StudentCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.tid": data["uid"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the teacher password could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
// Send teacher personal email temp password
|
||||||
|
subject := "Password Changed"
|
||||||
|
receiver := teacher.Personal.Email
|
||||||
|
r := NewRequest([]string{receiver}, subject)
|
||||||
|
|
||||||
|
if sent := r.Send("./templates/passwordChanged.html", map[string]string{"username": teacher.Personal.FirstName, "password": tempPass}); !sent {
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Could not send password to teachers email",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated teacher password",
|
||||||
|
"result": result,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateTeacherAddress(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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
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["uid"] == "" || data["address"] == "" || data["city"] == "" || data["province"] == "" || data["postal"] == "" {
|
||||||
|
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{
|
||||||
|
"personal.address": data["address"],
|
||||||
|
"personal.city": data["city"],
|
||||||
|
"personal.province": data["province"],
|
||||||
|
"personal.postal": data["postal"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, updateErr := TeacherCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.tid": data["uid"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the teacher could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated teacher",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateTeacherPhoto(c *fiber.Ctx) error {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
|
||||||
|
//Ensure Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Unauthorized: only an admin can perform this action",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
tid := c.FormValue("tid")
|
||||||
|
if tid == "" {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "missing required fields",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get teacher
|
||||||
|
var teacher models.Teacher
|
||||||
|
findErr := TeacherCollection.FindOne(context.TODO(), bson.M{"school.tid": tid}).Decode(&teacher)
|
||||||
|
if findErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the teacher could not be found",
|
||||||
|
"error": findErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect image
|
||||||
|
file, err := c.FormFile("image")
|
||||||
|
if err != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the image could not be retrieved",
|
||||||
|
"error": err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get student photo
|
||||||
|
var photo models.Photo
|
||||||
|
findErr = ImageCollection.FindOne(context.TODO(), bson.M{"name": teacher.School.PhotoName}).Decode(&photo)
|
||||||
|
if findErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the student image could not be found",
|
||||||
|
"error": findErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save image to local
|
||||||
|
uniqueId := uuid.New()
|
||||||
|
filename := strings.Replace(uniqueId.String(), "-", "", -1)
|
||||||
|
fileExt := strings.Split(file.Filename, ".")[1]
|
||||||
|
image := fmt.Sprintf("%s.%s", filename, fileExt)
|
||||||
|
err = c.SaveFile(file, fmt.Sprintf("./database/images/%s", image))
|
||||||
|
if err != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the image could not be saved",
|
||||||
|
"error": err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the entire file into a byte slice
|
||||||
|
bytes, err := os.ReadFile(fmt.Sprintf("./database/images/%s", image))
|
||||||
|
if err != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the image could not be read",
|
||||||
|
"error": err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var base64Encoding string = toBase64(bytes)
|
||||||
|
|
||||||
|
// Update image name and base64 data
|
||||||
|
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
|
update := bson.M{
|
||||||
|
"$set": bson.M{
|
||||||
|
"base64": base64Encoding,
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_, updateErr := ImageCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"_id": photo.ID},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the image could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
// Remove local image
|
||||||
|
os.Remove(fmt.Sprintf("./database/images/%s", image))
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated teacher photo",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateTeacherEmail(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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var tid string
|
||||||
|
var verifiedTeacher bool
|
||||||
|
|
||||||
|
verifiedAdmin, _ := AuthenticateUser(c, 3)
|
||||||
|
verifiedTeacher, tid = AuthenticateUser(c, 2)
|
||||||
|
// Ensure Authenticated admin sent request
|
||||||
|
if !verifiedAdmin && !verifiedTeacher {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Unauthorized: only an admin or teacher can perform this action",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if verifiedAdmin && data["uid"] == "" {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "missing required fields",
|
||||||
|
})
|
||||||
|
} else if verifiedAdmin {
|
||||||
|
tid = data["uid"]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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{
|
||||||
|
"personal.email": data["email"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, updateErr := TeacherCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.tid": tid},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the teacher could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated teacher",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateTeacherName(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 Authenticated admin sent request
|
||||||
|
if verified, _ := AuthenticateUser(c, 3); !verified {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "Unauthorized: only an admin can perform this action",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check id and names are included
|
||||||
|
if data["uid"] == "" || data["firstname"] == "" || data["lastname"] == "" {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "missing required fields",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get teacher
|
||||||
|
var teacher models.Teacher
|
||||||
|
findErr := TeacherCollection.FindOne(ctx, bson.M{"school.tid": data["uid"]}).Decode(&teacher)
|
||||||
|
if findErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the teacher could not be found",
|
||||||
|
"error": findErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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{
|
||||||
|
"personal.firstname": data["firstname"],
|
||||||
|
"personal.middlename": middlename,
|
||||||
|
"personal.lastname": data["lastname"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, updateErr := TeacherCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"school.tid": data["uid"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the teacher could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated teacher",
|
||||||
|
})
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,19 +1,34 @@
|
|||||||
module github.com/SowinskiBraeden/school-management-api
|
module github.com/SowinskiBraeden/school-management-api
|
||||||
|
|
||||||
go 1.16
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
github.com/gofiber/fiber/v2 v2.36.0
|
||||||
github.com/gofiber/fiber/v2 v2.26.0
|
github.com/golang-jwt/jwt v3.2.2+incompatible
|
||||||
github.com/google/go-cmp v0.5.6 // indirect
|
|
||||||
github.com/google/uuid v1.3.0
|
github.com/google/uuid v1.3.0
|
||||||
github.com/joho/godotenv v1.3.0
|
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef
|
||||||
github.com/stretchr/testify v1.7.0 // indirect
|
github.com/joho/godotenv v1.4.0
|
||||||
go.mongodb.org/mongo-driver v1.7.2
|
go.mongodb.org/mongo-driver v1.10.1
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
|
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
)
|
||||||
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
|
|
||||||
|
require (
|
||||||
|
github.com/andybalholm/brotli v1.0.4 // indirect
|
||||||
|
github.com/golang/snappy v0.0.4 // indirect
|
||||||
|
github.com/google/go-cmp v0.5.8 // indirect
|
||||||
|
github.com/klauspost/compress v1.15.9 // indirect
|
||||||
|
github.com/montanaflynn/stats v0.6.6 // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
github.com/stretchr/testify v1.8.0 // indirect
|
||||||
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
|
github.com/valyala/fasthttp v1.38.0 // indirect
|
||||||
|
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||||
|
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||||
|
github.com/xdg-go/scram v1.1.1 // indirect
|
||||||
|
github.com/xdg-go/stringprep v1.0.3 // indirect
|
||||||
|
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
|
||||||
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
|
||||||
|
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
|
||||||
golang.org/x/text v0.3.7 // indirect
|
golang.org/x/text v0.3.7 // indirect
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
|
||||||
)
|
)
|
||||||
@@ -1,152 +1,96 @@
|
|||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
|
||||||
github.com/andybalholm/brotli v1.0.2 h1:JKnhI/XQ75uFBTiuzXpzFrUriDPiZjlOSzh6wXogP0E=
|
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||||
github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
github.com/gofiber/fiber/v2 v2.36.0 h1:1qLMe5rhXFLPa2SjK10Wz7WFgLwYi4TYg7XrjztJHqA=
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
github.com/gofiber/fiber/v2 v2.36.0/go.mod h1:tgCr+lierLwLoVHHO/jn3Niannv34WRkQETU8wiL9fQ=
|
||||||
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
|
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
|
||||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
|
||||||
github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0=
|
|
||||||
github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY=
|
|
||||||
github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg=
|
|
||||||
github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
|
|
||||||
github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
|
|
||||||
github.com/gobuffalo/flect v0.1.0/go.mod h1:d2ehjJqGOH/Kjqcoz+F7jHTBbmDb38yXA598Hb50EGs=
|
|
||||||
github.com/gobuffalo/flect v0.1.1/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI=
|
|
||||||
github.com/gobuffalo/flect v0.1.3/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI=
|
|
||||||
github.com/gobuffalo/genny v0.0.0-20190329151137-27723ad26ef9/go.mod h1:rWs4Z12d1Zbf19rlsn0nurr75KqhYp52EAGGxTbBhNk=
|
|
||||||
github.com/gobuffalo/genny v0.0.0-20190403191548-3ca520ef0d9e/go.mod h1:80lIj3kVJWwOrXWWMRzzdhW3DsrdjILVil/SFKBzF28=
|
|
||||||
github.com/gobuffalo/genny v0.1.0/go.mod h1:XidbUqzak3lHdS//TPu2OgiFB+51Ur5f7CSnXZ/JDvo=
|
|
||||||
github.com/gobuffalo/genny v0.1.1/go.mod h1:5TExbEyY48pfunL4QSXxlDOmdsD44RRq4mVZ0Ex28Xk=
|
|
||||||
github.com/gobuffalo/gitgen v0.0.0-20190315122116-cc086187d211/go.mod h1:vEHJk/E9DmhejeLeNt7UVvlSGv3ziL+djtTr3yyzcOw=
|
|
||||||
github.com/gobuffalo/gogen v0.0.0-20190315121717-8f38393713f5/go.mod h1:V9QVDIxsgKNZs6L2IYiGR8datgMhB577vzTDqypH360=
|
|
||||||
github.com/gobuffalo/gogen v0.1.0/go.mod h1:8NTelM5qd8RZ15VjQTFkAW6qOMx5wBbW4dSCS3BY8gg=
|
|
||||||
github.com/gobuffalo/gogen v0.1.1/go.mod h1:y8iBtmHmGc4qa3urIyo1shvOD8JftTtfcKi+71xfDNE=
|
|
||||||
github.com/gobuffalo/logger v0.0.0-20190315122211-86e12af44bc2/go.mod h1:QdxcLw541hSGtBnhUc4gaNIXRjiDppFGaDqzbrBd3v8=
|
|
||||||
github.com/gobuffalo/mapi v1.0.1/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc=
|
|
||||||
github.com/gobuffalo/mapi v1.0.2/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc=
|
|
||||||
github.com/gobuffalo/packd v0.0.0-20190315124812-a385830c7fc0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4=
|
|
||||||
github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4=
|
|
||||||
github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ=
|
|
||||||
github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0=
|
|
||||||
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
|
|
||||||
github.com/gofiber/fiber/v2 v2.26.0 h1:Awnfqp3fqbZzV3wZWMRJ6Xo2U8X0Ls68M7tXjx52NcM=
|
|
||||||
github.com/gofiber/fiber/v2 v2.26.0/go.mod h1:7efVWcBOZi1PyMWznnbitjnARPA7nYZxmQXJVod0bo0=
|
|
||||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA=
|
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||||
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
|
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef h1:A9HsByNhogrvm9cWb28sjiS3i7tcKCkflWFEkHfuAgM=
|
||||||
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs=
|
||||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
|
||||||
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
|
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
|
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||||
github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||||
github.com/klauspost/compress v1.13.4 h1:0zhec2I8zGnjWcKyLl6i3gPqKANCCn5e9xmviEEeX6s=
|
github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY=
|
||||||
github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
|
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
|
|
||||||
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
|
|
||||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
||||||
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
|
github.com/montanaflynn/stats v0.6.6 h1:Duep6KMIDpY4Yo11iFsvyqJDyfzLF9+sndUKT+v64GQ=
|
||||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
|
||||||
github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
|
||||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
|
||||||
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
|
||||||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
|
||||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
|
||||||
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
|
||||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
|
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
|
||||||
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
github.com/valyala/fasthttp v1.32.0 h1:keswgWzyKyNIIjz2a7JmCYHOOIkRp6HMx9oTV6QrZWY=
|
github.com/valyala/fasthttp v1.38.0 h1:yTjSSNjuDi2PPvXY2836bIwLmiTS2T4T9p1coQshpco=
|
||||||
github.com/valyala/fasthttp v1.32.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus=
|
github.com/valyala/fasthttp v1.38.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
|
||||||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||||
github.com/xdg-go/scram v1.0.2 h1:akYIkZ28e6A96dkWNJQu3nmCzH3YfwMPQExUYDaRv7w=
|
github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E=
|
||||||
github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
|
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
|
||||||
github.com/xdg-go/stringprep v1.0.2 h1:6iq84/ryjjeRmMJwxutI51F2GIPlP5BfTvXHeYjyhBc=
|
github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs=
|
||||||
github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM=
|
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
|
||||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
|
|
||||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
|
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
|
||||||
go.mongodb.org/mongo-driver v1.7.2 h1:pFttQyIiJUHEn50YfZgC9ECjITMT44oiN36uArf/OFg=
|
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk=
|
||||||
go.mongodb.org/mongo-driver v1.7.2/go.mod h1:Q4oFMbo1+MSNqICAdYMlC/zSTrwCogR4R8NzkI+yfU8=
|
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4=
|
||||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
go.mongodb.org/mongo-driver v1.10.1 h1:NujsPveKwHaWuKUer/ceo9DzEe7HIj1SlJ6uvXZG0S4=
|
||||||
|
go.mongodb.org/mongo-driver v1.10.1/go.mod h1:z4XpeoU6w+9Vht+jAFyLgVrD+jGSQQe0+CBWFHNiHt8=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
|
|
||||||
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c=
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
|
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
|
||||||
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d h1:FjkYO/PPp4Wi0EAUOVLxePm7qVW4r4ctbWpURyuOD0E=
|
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
|
||||||
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc=
|
||||||
|
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
|
||||||
golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
|
||||||
golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
|
||||||
golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
|
||||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/SowinskiBraeden/school-management-api/routes"
|
"github.com/SowinskiBraeden/school-management-api/routes"
|
||||||
@@ -10,7 +11,10 @@ import (
|
|||||||
"github.com/gofiber/fiber/v2/middleware/cors"
|
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const version string = "\nv1.1.3-Beta"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
fmt.Println(version)
|
||||||
app := fiber.New()
|
app := fiber.New()
|
||||||
|
|
||||||
app.Use(cors.New(cors.Config{
|
app.Use(cors.New(cors.Config{
|
||||||
|
|||||||
+32
-12
@@ -1,16 +1,24 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/SowinskiBraeden/school-management-api/database"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var AdminCollection *mongo.Collection = database.OpenCollection(database.Client, "admins")
|
||||||
|
|
||||||
type Admin struct {
|
type Admin struct {
|
||||||
ID primitive.ObjectID `bson:"_id"`
|
ID primitive.ObjectID `bson:"_id"`
|
||||||
FirstName string `json:"firstname" validate:"required"`
|
FirstName string `json:"firstname" validate:"required"`
|
||||||
@@ -24,9 +32,24 @@ type Admin struct {
|
|||||||
Updated_at time.Time `json:"updated_at"`
|
Updated_at time.Time `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Admin) GenerateSchoolEmail() string {
|
func (a *Admin) EmailExists(email string) bool {
|
||||||
var email string = strings.ToLower(a.LastName) + "_" + strings.ToLower(string(a.FirstName[0])) + "@surreyschools.ca"
|
var admin Admin
|
||||||
// Add check to see if email already exists
|
findErr := AdminCollection.FindOne(context.TODO(), bson.M{"account.schoolemail": email}).Decode(&admin)
|
||||||
|
return findErr == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Admin) GenerateSchoolEmail(offset int, lastEmail string) string {
|
||||||
|
addr := os.Getenv("SYSTEM_EMAIL_ADDRESS")
|
||||||
|
var email string = strings.ToLower(a.LastName) + "_" + strings.ToLower(string(a.FirstName[0])) + addr
|
||||||
|
if offset > 0 && offset < len([]rune(a.FirstName))-1 {
|
||||||
|
email = lastEmail[:strings.Index(lastEmail, "_")+offset+1] + strings.ToLower(string(a.FirstName[offset])) + addr
|
||||||
|
}
|
||||||
|
if offset == len([]rune(a.FirstName))-1 {
|
||||||
|
email = strings.ToLower(a.LastName) + "_" + strings.ToLower(a.FirstName) + addr
|
||||||
|
}
|
||||||
|
if offset > len([]rune(a.FirstName))-1 {
|
||||||
|
email = strings.ToLower(a.LastName) + "_" + strings.ToLower(a.FirstName) + strconv.Itoa(offset-len([]rune(a.FirstName))) + addr
|
||||||
|
}
|
||||||
return email
|
return email
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,15 +58,12 @@ func (s *Admin) HashPassword(password string) string {
|
|||||||
return string(hash)
|
return string(hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Admin) ComparePasswords(password string) bool {
|
func (a *Admin) ComparePasswords(password string) bool {
|
||||||
err := bcrypt.CompareHashAndPassword([]byte(s.Password), []byte(password))
|
err := bcrypt.CompareHashAndPassword([]byte(a.Password), []byte(password))
|
||||||
if err != nil {
|
return err == nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Admin) CheckPasswordStrength(password string) bool {
|
func (a *Admin) CheckPasswordStrength(password string) bool {
|
||||||
|
|
||||||
var hasUpper bool = false
|
var hasUpper bool = false
|
||||||
for _, r := range password {
|
for _, r := range password {
|
||||||
@@ -59,14 +79,14 @@ func (s *Admin) CheckPasswordStrength(password string) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.ContainsAny(password, specialCharSet) && hasLower && hasUpper {
|
if strings.ContainsAny(password, specialCharSet) && hasLower && hasUpper && len(password) >= 8 {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Admin) GeneratePassword(passwordLength, minSpecialChar, minNum, minUpperCase int) string {
|
func (a *Admin) GeneratePassword(passwordLength, minSpecialChar, minNum, minUpperCase int) string {
|
||||||
var password strings.Builder
|
var password strings.Builder
|
||||||
|
|
||||||
//Set special character
|
//Set special character
|
||||||
|
|||||||
+3
-2
@@ -15,6 +15,7 @@ import (
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
type Id struct {
|
type Id struct {
|
||||||
ID primitive.ObjectID `bson:"_id"`
|
ID primitive.ObjectID `bson:"_id"`
|
||||||
CID string `bson:"cid"` // custom id for admin, teahcer or student
|
CID string `json:"cid"` // custom id for admin, teahcer or student
|
||||||
|
ParentType int `json:"parenttype"` // A number representing the user (1: student, 2: teacher, 3: admin)
|
||||||
}
|
}
|
||||||
+26
-28
@@ -3,6 +3,7 @@ package models
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -17,12 +18,12 @@ import (
|
|||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
var lockerCollection *mongo.Collection = database.OpenCollection(database.Client, "lockers")
|
var LockerCollection *mongo.Collection = database.OpenCollection(database.Client, "lockers")
|
||||||
var studentCollection *mongo.Collection = database.OpenCollection(database.Client, "students")
|
var StudentCollection *mongo.Collection = database.OpenCollection(database.Client, "students")
|
||||||
|
|
||||||
type Student struct {
|
type Student struct {
|
||||||
ID primitive.ObjectID `bson:"_id"`
|
ID primitive.ObjectID `bson:"_id"`
|
||||||
PersonalData struct {
|
Personal struct {
|
||||||
FirstName string `json:"firstname" validate:"required"`
|
FirstName string `json:"firstname" validate:"required"`
|
||||||
MiddleName string `json:"middlename"`
|
MiddleName string `json:"middlename"`
|
||||||
LastName string `json:"lastname" validate:"required"`
|
LastName string `json:"lastname" validate:"required"`
|
||||||
@@ -34,8 +35,8 @@ type Student struct {
|
|||||||
Postal string `json:"postal"`
|
Postal string `json:"postal"`
|
||||||
DOB string `json:"dob" validate:"required"`
|
DOB string `json:"dob" validate:"required"`
|
||||||
Contacts []string `json:"contacts"` // List of contact ID's rather than contact object
|
Contacts []string `json:"contacts"` // List of contact ID's rather than contact object
|
||||||
} `json:"personaldata"`
|
} `json:"personal"`
|
||||||
SchoolData struct {
|
School struct {
|
||||||
GradeLevel float64 `json:"gradelevel" validate:"required"`
|
GradeLevel float64 `json:"gradelevel" validate:"required"`
|
||||||
SID string `json:"sid"` // Student ID
|
SID string `json:"sid"` // Student ID
|
||||||
PEN string `json:"ped"` // Personal Education Number
|
PEN string `json:"ped"` // Personal Education Number
|
||||||
@@ -43,21 +44,23 @@ type Student struct {
|
|||||||
Locker string `json:"-"` // Locker ID
|
Locker string `json:"-"` // Locker ID
|
||||||
YOG int `json:"yog"` // Year of Graduation
|
YOG int `json:"yog"` // Year of Graduation
|
||||||
PhotoName string `json:"photoname"` // name of photo in db
|
PhotoName string `json:"photoname"` // name of photo in db
|
||||||
} `json:"schooldata"`
|
} `json:"School"`
|
||||||
AccountData struct {
|
Account struct {
|
||||||
|
VerifiedEmail bool `json:"verifiedemail"`
|
||||||
SchoolEmail string `json:"schoolemail"`
|
SchoolEmail string `json:"schoolemail"`
|
||||||
Password string `json:"-" validate:"min=10,max=32"`
|
Password string `json:"-" validate:"min=10,max=32"`
|
||||||
AccountDisabled bool `bson:"accountdisabled"`
|
AccountDisabled bool `bson:"accountdisabled"`
|
||||||
|
Alerted bool `bson:"alerted"`
|
||||||
TempPassword bool `json:"temppassword"`
|
TempPassword bool `json:"temppassword"`
|
||||||
Attempts int `json:"attempts"` // login attempts max 5
|
Attempts int `json:"attempts"` // login attempts max 5
|
||||||
HashHistory []string `json:"-"` // List of old hashed passwords (not including auto generated passwords)
|
HashHistory []string `json:"-"` // List of old hashed passwords (not including auto generated passwords)
|
||||||
} `json:"accountdata"`
|
} `json:"Account"`
|
||||||
Created_at time.Time `json:"created_at"`
|
Created_at time.Time `json:"created_at"`
|
||||||
Updated_at time.Time `json:"updated_at"`
|
Updated_at time.Time `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Student) UsedPassword(password string) bool {
|
func (s *Student) UsedPassword(password string) bool {
|
||||||
for _, oldHash := range s.AccountData.HashHistory {
|
for _, oldHash := range s.Account.HashHistory {
|
||||||
if oldHash == s.HashPassword(password) {
|
if oldHash == s.HashPassword(password) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -72,33 +75,28 @@ func (s *Student) HashPassword(password string) string {
|
|||||||
|
|
||||||
func (s *Student) EmailExists(email string) bool {
|
func (s *Student) EmailExists(email string) bool {
|
||||||
var student Student
|
var student Student
|
||||||
findErr := studentCollection.FindOne(context.TODO(), bson.M{"accountdata.schoolemail": email}).Decode(&student)
|
findErr := StudentCollection.FindOne(context.TODO(), bson.M{"account.schoolemail": email}).Decode(&student)
|
||||||
if findErr != nil {
|
return findErr == nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Student) GenerateSchoolEmail(offset int, lastEmail string) string {
|
func (s *Student) GenerateSchoolEmail(offset int, lastEmail string) string {
|
||||||
var email string = strings.ToLower(string(s.PersonalData.FirstName[0])) + "." + strings.ToLower(s.PersonalData.LastName) + "@surreyschools.ca"
|
addr := os.Getenv("SYSTEM_EMAIL_ADDRESS")
|
||||||
if offset > 0 && offset < len([]rune(s.PersonalData.FirstName))-1 {
|
var email string = strings.ToLower(string(s.Personal.FirstName[0])) + "." + strings.ToLower(s.Personal.LastName) + addr
|
||||||
email = lastEmail[:offset] + strings.ToLower(string(s.PersonalData.FirstName[offset])) + lastEmail[offset:]
|
if offset > 0 && offset < len([]rune(s.Personal.FirstName))-1 {
|
||||||
|
email = lastEmail[:offset] + strings.ToLower(string(s.Personal.FirstName[offset])) + lastEmail[offset:] + addr
|
||||||
}
|
}
|
||||||
if offset == len([]rune(s.PersonalData.FirstName))-1 {
|
if offset == len([]rune(s.Personal.FirstName))-1 {
|
||||||
email = strings.ToLower(s.PersonalData.FirstName) + "." + strings.ToLower(s.PersonalData.LastName) + "@surreyschools.ca"
|
email = strings.ToLower(s.Personal.FirstName) + "." + strings.ToLower(s.Personal.LastName) + addr
|
||||||
}
|
}
|
||||||
if offset > len([]rune(s.PersonalData.FirstName))-1 {
|
if offset > len([]rune(s.Personal.FirstName))-1 {
|
||||||
email = strings.ToLower(s.PersonalData.FirstName) + "." + strings.ToLower(s.PersonalData.LastName) + strconv.Itoa(offset-len([]rune(s.PersonalData.FirstName))) + "@surreyschools.ca"
|
email = strings.ToLower(s.Personal.FirstName) + "." + strings.ToLower(s.Personal.LastName) + strconv.Itoa(offset-len([]rune(s.Personal.FirstName))) + addr
|
||||||
}
|
}
|
||||||
return email
|
return email
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Student) ComparePasswords(password string) bool { //True: passwords match, False: no match
|
func (s *Student) ComparePasswords(password string) bool { //True: passwords match, False: no match
|
||||||
valid := bcrypt.CompareHashAndPassword([]byte(s.AccountData.Password), []byte(password))
|
valid := bcrypt.CompareHashAndPassword([]byte(s.Account.Password), []byte(password))
|
||||||
if valid != nil {
|
return valid == nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Student) CheckPasswordStrength(password string) bool {
|
func (s *Student) CheckPasswordStrength(password string) bool {
|
||||||
@@ -117,7 +115,7 @@ func (s *Student) CheckPasswordStrength(password string) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.ContainsAny(password, specialCharSet) && hasLower && hasUpper {
|
if strings.ContainsAny(password, specialCharSet) && hasLower && hasUpper && len(password) >= 8 {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
|
|||||||
+24
-27
@@ -3,6 +3,7 @@ package models
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -23,11 +24,11 @@ var (
|
|||||||
allCharSet = lowerCharSet + upperCharSet + specialCharSet + numberSet
|
allCharSet = lowerCharSet + upperCharSet + specialCharSet + numberSet
|
||||||
)
|
)
|
||||||
|
|
||||||
var teacherCollection *mongo.Collection = database.OpenCollection(database.Client, "teachers")
|
var TeacherCollection *mongo.Collection = database.OpenCollection(database.Client, "teachers")
|
||||||
|
|
||||||
type Teacher struct {
|
type Teacher struct {
|
||||||
ID primitive.ObjectID `bson:"_id"`
|
ID primitive.ObjectID `bson:"_id"`
|
||||||
PersonalData struct {
|
Personal struct {
|
||||||
FirstName string `json:"firstname" validate:"required"`
|
FirstName string `json:"firstname" validate:"required"`
|
||||||
MiddleName string `json:"middlename"`
|
MiddleName string `json:"middlename"`
|
||||||
LastName string `json:"lastname" validate:"required"`
|
LastName string `json:"lastname" validate:"required"`
|
||||||
@@ -37,26 +38,27 @@ type Teacher struct {
|
|||||||
Province string `json:"province"`
|
Province string `json:"province"`
|
||||||
Postal string `json:"postal"`
|
Postal string `json:"postal"`
|
||||||
DOB string `json:"dob" validate:"required"`
|
DOB string `json:"dob" validate:"required"`
|
||||||
} `json:"personaldata"`
|
} `json:"personal"`
|
||||||
SchoolData struct {
|
School struct {
|
||||||
TID string `json:"tid"` // Teacher ID
|
TID string `json:"tid"` // Teacher ID
|
||||||
Homeroom string `json:"homeroom"`
|
Homeroom string `json:"homeroom"`
|
||||||
PhotoName string `json:"photoname"` // name of photo in db
|
PhotoName string `json:"photoname"` // name of photo in db
|
||||||
} `json:"schooldata"`
|
} `json:"School"`
|
||||||
AccountData struct {
|
Account struct {
|
||||||
|
VerifiedEmail bool `json:"verifiedemail"`
|
||||||
SchoolEmail string `json:"schoolemail"`
|
SchoolEmail string `json:"schoolemail"`
|
||||||
Password string `json:"-" validate:"min=10,max=32"`
|
Password string `json:"-" validate:"min=10,max=32"`
|
||||||
AccountDisabled bool `bson:"accountdisabled"`
|
AccountDisabled bool `bson:"accountdisabled"`
|
||||||
TempPassword bool `json:"temppassword"`
|
TempPassword bool `json:"temppassword"`
|
||||||
Attempts int `json:"attempts"` // login attempts max 5
|
Attempts int `json:"attempts"` // login attempts max 5
|
||||||
HashHistory []string `json:"-"` // List of old hashed passwords (not including auto generated passwords)
|
HashHistory []string `json:"-"` // List of old hashed passwords (not including auto generated passwords)
|
||||||
} `json:"accountdata"`
|
} `json:"Account"`
|
||||||
Created_at time.Time `json:"created_at"`
|
Created_at time.Time `json:"created_at"`
|
||||||
Updated_at time.Time `json:"updated_at"`
|
Updated_at time.Time `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Teacher) UsedPassword(password string) bool {
|
func (t *Teacher) UsedPassword(password string) bool {
|
||||||
for _, oldHash := range t.AccountData.HashHistory {
|
for _, oldHash := range t.Account.HashHistory {
|
||||||
if oldHash == t.HashPassword(password) {
|
if oldHash == t.HashPassword(password) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -71,33 +73,28 @@ func (t *Teacher) HashPassword(password string) string {
|
|||||||
|
|
||||||
func (t *Teacher) EmailExists(email string) bool {
|
func (t *Teacher) EmailExists(email string) bool {
|
||||||
var teacher Teacher
|
var teacher Teacher
|
||||||
findErr := teacherCollection.FindOne(context.TODO(), bson.M{"accountdata.schoolemail": email}).Decode(&teacher)
|
findErr := TeacherCollection.FindOne(context.TODO(), bson.M{"account.schoolemail": email}).Decode(&teacher)
|
||||||
if findErr != nil {
|
return findErr == nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Teacher) GenerateSchoolEmail(offset int, lastEmail string) string {
|
func (t *Teacher) GenerateSchoolEmail(offset int, lastEmail string) string {
|
||||||
var email string = strings.ToLower(t.PersonalData.LastName) + "_" + strings.ToLower(string(t.PersonalData.FirstName[0])) + "@surreyschools.ca"
|
addr := os.Getenv("SYSTEM_EMAIL_ADDRESS")
|
||||||
if offset > 0 && offset < len([]rune(t.PersonalData.FirstName))-1 {
|
var email string = strings.ToLower(t.Personal.LastName) + "_" + strings.ToLower(string(t.Personal.FirstName[0])) + addr
|
||||||
email = lastEmail[:strings.Index(lastEmail, "_")+offset+1] + strings.ToLower(string(t.PersonalData.FirstName[offset])) + "@surreyschools.ca"
|
if offset > 0 && offset < len([]rune(t.Personal.FirstName))-1 {
|
||||||
|
email = lastEmail[:strings.Index(lastEmail, "_")+offset+1] + strings.ToLower(string(t.Personal.FirstName[offset])) + addr
|
||||||
}
|
}
|
||||||
if offset == len([]rune(t.PersonalData.FirstName))-1 {
|
if offset == len([]rune(t.Personal.FirstName))-1 {
|
||||||
email = strings.ToLower(t.PersonalData.LastName) + "_" + strings.ToLower(t.PersonalData.FirstName) + "@surreyschools.ca"
|
email = strings.ToLower(t.Personal.LastName) + "_" + strings.ToLower(t.Personal.FirstName) + addr
|
||||||
}
|
}
|
||||||
if offset > len([]rune(t.PersonalData.FirstName))-1 {
|
if offset > len([]rune(t.Personal.FirstName))-1 {
|
||||||
email = strings.ToLower(t.PersonalData.LastName) + "_" + strings.ToLower(t.PersonalData.FirstName) + strconv.Itoa(offset-len([]rune(t.PersonalData.FirstName))) + "@surreyschools.ca"
|
email = strings.ToLower(t.Personal.LastName) + "_" + strings.ToLower(t.Personal.FirstName) + strconv.Itoa(offset-len([]rune(t.Personal.FirstName))) + addr
|
||||||
}
|
}
|
||||||
return email
|
return email
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Teacher) ComparePasswords(password string) bool {
|
func (t *Teacher) ComparePasswords(password string) bool {
|
||||||
err := bcrypt.CompareHashAndPassword([]byte(t.AccountData.Password), []byte(password))
|
err := bcrypt.CompareHashAndPassword([]byte(t.Account.Password), []byte(password))
|
||||||
if err != nil {
|
return err == nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Teacher) CheckPasswordStrength(password string) bool {
|
func (t *Teacher) CheckPasswordStrength(password string) bool {
|
||||||
@@ -116,7 +113,7 @@ func (t *Teacher) CheckPasswordStrength(password string) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.ContainsAny(password, specialCharSet) && hasLower && hasUpper {
|
if strings.ContainsAny(password, specialCharSet) && hasLower && hasUpper && len(password) >= 8 {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
+52
-31
@@ -2,43 +2,54 @@ package routes
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/SowinskiBraeden/school-management-api/controllers"
|
"github.com/SowinskiBraeden/school-management-api/controllers"
|
||||||
|
"github.com/SowinskiBraeden/school-management-api/controllers/update"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Setup(app *fiber.App) {
|
func Setup(app *fiber.App) {
|
||||||
// API Handling
|
// Detect if system is new and needs default admin
|
||||||
|
controllers.NewSystem()
|
||||||
|
|
||||||
|
// API Handling
|
||||||
var routerPrefix string = "/api/v1"
|
var routerPrefix string = "/api/v1"
|
||||||
|
|
||||||
|
// API check
|
||||||
|
app.Get(routerPrefix+"/status", func(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "the API is active",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// Student Authentication Handler
|
// Student Authentication Handler
|
||||||
app.Get(routerPrefix+"/student", controllers.Student)
|
app.Get(routerPrefix+"/student", controllers.Student)
|
||||||
app.Post(routerPrefix+"/student/enroll", controllers.Enroll)
|
app.Post(routerPrefix+"/student/enroll", controllers.Enroll)
|
||||||
app.Post(routerPrefix+"/student/login", controllers.StudentLogin)
|
app.Post(routerPrefix+"/student/login", controllers.StudentLogin)
|
||||||
|
|
||||||
// Update Student Handler
|
// Update Student Handler
|
||||||
app.Post(routerPrefix+"/student/updateName", controllers.UpdateStudentName)
|
app.Post(routerPrefix+"/student/updateName", update.UpdateStudentName)
|
||||||
app.Post(routerPrefix+"/student/updateGradeLevel", controllers.UpdateStudentGradeLevel)
|
app.Post(routerPrefix+"/student/updateGradeLevel", update.UpdateStudentGradeLevel)
|
||||||
app.Post(routerPrefix+"/student/updateHomeroom", controllers.UpdateStudentHomeroom)
|
app.Post(routerPrefix+"/student/updateHomeroom", update.UpdateStudentHomeroom)
|
||||||
app.Post(routerPrefix+"/student/updateLocker", controllers.UpdateStudentLocker)
|
app.Post(routerPrefix+"/student/updateLocker", update.UpdateStudentLocker)
|
||||||
app.Post(routerPrefix+"/studnet/updateYOG", controllers.UpdateStudentYOG)
|
app.Post(routerPrefix+"/studnet/updateYOG", update.UpdateStudentYOG)
|
||||||
app.Post(routerPrefix+"/studnet/addContact", controllers.AddStudentContact)
|
app.Post(routerPrefix+"/studnet/addContact", update.AddStudentContact)
|
||||||
app.Post(routerPrefix+"/student/removeContact", controllers.RemoveStudentContact)
|
app.Post(routerPrefix+"/student/removeContact", update.RemoveStudentContact)
|
||||||
app.Post(routerPrefix+"/student/updatePassword", controllers.UpdateStudentPassword)
|
app.Post(routerPrefix+"/student/updatePassword", update.UpdateStudentPassword)
|
||||||
app.Post(routerPrefix+"/student/resetPassword", controllers.ResetStudentPassword)
|
app.Post(routerPrefix+"/student/resetPassword", update.ResetStudentPassword)
|
||||||
app.Post(routerPrefix+"/student/updateAddress", controllers.UpdateStudentAddress)
|
app.Post(routerPrefix+"/student/updateAddress", update.UpdateStudentAddress)
|
||||||
app.Post(routerPrefix+"/student/updatePhoto", controllers.UpdateStudentPhoto)
|
app.Post(routerPrefix+"/student/updatePhoto", update.UpdateStudentPhoto)
|
||||||
app.Post(routerPrefix+"/student/updateEmail", controllers.UpdateStudentEmail)
|
app.Post(routerPrefix+"/student/updateEmail", update.UpdateStudentEmail)
|
||||||
|
|
||||||
// Student Contact Handler
|
// Student Contact Handler
|
||||||
app.Post(routerPrefix+"/student/createContact", controllers.CreateContact)
|
app.Post(routerPrefix+"/contact/createContact", controllers.CreateContact)
|
||||||
app.Post(routerPrefix+"/student/contact/updateName", controllers.UpdateContactName)
|
app.Post(routerPrefix+"/contact/updateName", update.UpdateContactName)
|
||||||
app.Post(routerPrefix+"/student/contact/updateAddress", controllers.UpdateContactAddress)
|
app.Post(routerPrefix+"/contact/updateAddress", update.UpdateContactAddress)
|
||||||
app.Post(routerPrefix+"/student/contact/updateHomePhone", controllers.UpdateContactHomePhone)
|
app.Post(routerPrefix+"/contact/updateHomePhone", update.UpdateContactHomePhone)
|
||||||
app.Post(routerPrefix+"/student/contact/updateWorkPhone", controllers.UpdateContactWorkPhone)
|
app.Post(routerPrefix+"/contact/updateWorkPhone", update.UpdateContactWorkPhone)
|
||||||
app.Post(routerPrefix+"/student/contact/updateEmail", controllers.UpdateContactEmail)
|
app.Post(routerPrefix+"/contact/updateEmail", update.UpdateContactEmail)
|
||||||
app.Post(routerPrefix+"/student/contact/updatePriority", controllers.UpdateContactPriority)
|
app.Post(routerPrefix+"/contact/updatePriority", update.UpdateContactPriority)
|
||||||
app.Post(routerPrefix+"/student/contact/deleteContact", controllers.DeleteContact)
|
app.Post(routerPrefix+"/contact/deleteContact", controllers.DeleteContact)
|
||||||
|
|
||||||
// Teacher Authentication Handler
|
// Teacher Authentication Handler
|
||||||
app.Get(routerPrefix+"/teacher", controllers.Teacher)
|
app.Get(routerPrefix+"/teacher", controllers.Teacher)
|
||||||
@@ -46,13 +57,13 @@ func Setup(app *fiber.App) {
|
|||||||
app.Post(routerPrefix+"/teacher/login", controllers.TeacherLogin)
|
app.Post(routerPrefix+"/teacher/login", controllers.TeacherLogin)
|
||||||
|
|
||||||
// Teacher Update Handler
|
// Teacher Update Handler
|
||||||
app.Post(routerPrefix+"/teacher/updatePassword", controllers.UpdateTeacherPassword)
|
app.Post(routerPrefix+"/teacher/updatePassword", update.UpdateTeacherPassword)
|
||||||
app.Post(routerPrefix+"/teacher/updateAddress", controllers.UpdateTeacherAddress)
|
app.Post(routerPrefix+"/teacher/updateAddress", update.UpdateTeacherAddress)
|
||||||
app.Post(routerPrefix+"/teacher/updatePhoto", controllers.UpdateTeacherPhoto)
|
app.Post(routerPrefix+"/teacher/updatePhoto", update.UpdateTeacherPhoto)
|
||||||
app.Post(routerPrefix+"/teacher/updateName", controllers.UpdateTeacherName)
|
app.Post(routerPrefix+"/teacher/updateName", update.UpdateTeacherName)
|
||||||
app.Post(routerPrefix+"/teacher/updateHomeroom", controllers.UpdateTeacherHomeroom)
|
app.Post(routerPrefix+"/teacher/updateHomeroom", update.UpdateTeacherHomeroom)
|
||||||
app.Post(routerPrefix+"/teacher/updateEmail", controllers.UpdateTeacherEmail)
|
app.Post(routerPrefix+"/teacher/updateEmail", update.UpdateTeacherEmail)
|
||||||
app.Post(routerPrefix+"/teacher/resetPassword", controllers.ResetTeacherPassword)
|
app.Post(routerPrefix+"/teacher/resetPassword", update.ResetTeacherPassword)
|
||||||
|
|
||||||
// General Routes
|
// General Routes
|
||||||
app.Post(routerPrefix+"/logout", controllers.Logout)
|
app.Post(routerPrefix+"/logout", controllers.Logout)
|
||||||
@@ -62,10 +73,20 @@ func Setup(app *fiber.App) {
|
|||||||
app.Post(routerPrefix+"/admin/create", controllers.CreateAdmin)
|
app.Post(routerPrefix+"/admin/create", controllers.CreateAdmin)
|
||||||
app.Post(routerPrefix+"/admin/login", controllers.AdminLogin)
|
app.Post(routerPrefix+"/admin/login", controllers.AdminLogin)
|
||||||
|
|
||||||
|
// Admin Update Handler
|
||||||
|
app.Post(routerPrefix+"/admin/updateName", update.UpdateAdminName)
|
||||||
|
app.Post(routerPrefix+"/admin/updateEmail", update.UpdateAdminEmail)
|
||||||
|
app.Post(routerPrefix+"/admin/updatePassword", update.UpdateAdminPassword)
|
||||||
|
|
||||||
// General Command Handling
|
// General Command Handling
|
||||||
app.Post(routerPrefix+"/admin/updateLockerCombo", controllers.UpdateLockerCombo)
|
app.Post(routerPrefix+"/admin/updateLockerCombo", update.UpdateLockerCombo)
|
||||||
app.Post(routerPrefix+"/admin/renableStudent", controllers.RemoveStudentsDisabled)
|
app.Post(routerPrefix+"/admin/enableStudent", update.RemoveStudentsDisabled)
|
||||||
app.Post(routerPrefix+"/admin/renableTeacher", controllers.RemoveTeachersDisabled)
|
app.Post(routerPrefix+"/admin/enableTeacher", update.RemoveTeachersDisabled)
|
||||||
|
|
||||||
|
// Delete Handler
|
||||||
|
app.Post(routerPrefix+"/remove/student", controllers.RemoveStudent)
|
||||||
|
app.Post(routerPrefix+"/remove/teacher", controllers.RemoveTeacher)
|
||||||
|
app.Post(routerPrefix+"/remove/admin", controllers.RemoveAdmin)
|
||||||
|
|
||||||
// 404 Handler
|
// 404 Handler
|
||||||
app.Use(func(c *fiber.Ctx) error {
|
app.Use(func(c *fiber.Ctx) error {
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
dot_import_whitelist = ["github.com/SowinskiBraeden/school-management-api/controllers"]
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta name="viewport" content="width=device-width"/>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
<title>Account Disabled</title>
|
||||||
|
<style type="text/css">
|
||||||
|
body{
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0;
|
||||||
|
min-width: 100%;
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
table{
|
||||||
|
margin: 50px 0 50px 0;
|
||||||
|
}
|
||||||
|
.header{
|
||||||
|
height: 40px;
|
||||||
|
text-align: center;
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.content{
|
||||||
|
height: 100px;
|
||||||
|
font-size: 18px;
|
||||||
|
line-height: 30px;
|
||||||
|
}
|
||||||
|
.subscribe{
|
||||||
|
height: 70px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.button{
|
||||||
|
text-align: center;
|
||||||
|
font-size: 18px;
|
||||||
|
font-family: sans-serif;
|
||||||
|
font-weight: bold;
|
||||||
|
padding: 0 30px 0 30px;
|
||||||
|
}
|
||||||
|
.button a{
|
||||||
|
color: #FFFFFF;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
.buttonwrapper{
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
.footer{
|
||||||
|
text-transform: uppercase;
|
||||||
|
text-align: center;
|
||||||
|
height: 40px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
.footer a{
|
||||||
|
color: #000000;
|
||||||
|
text-decoration: none;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body bgcolor="#009587">
|
||||||
|
<table bgcolor="#FFFFFF" width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||||
|
<tr class="header">
|
||||||
|
<td style="padding: 40px;">
|
||||||
|
Uh Oh! Account Disabled!
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="content">
|
||||||
|
<td style="padding:10px;">
|
||||||
|
<p>
|
||||||
|
Hi <b>{{ .username }}</b>, <br/>
|
||||||
|
Your account has been disabled due to too many incorrect login attempts, please contact an admin to enable your account.
|
||||||
|
</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="footer">
|
||||||
|
<td style="padding: 40px;">
|
||||||
|
This is an automated system email // DO NOT REPLY
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta name="viewport" content="width=device-width"/>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
<title>Account Registered</title>
|
||||||
|
<style type="text/css">
|
||||||
|
body{
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0;
|
||||||
|
min-width: 100%;
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
table{
|
||||||
|
margin: 50px 0 50px 0;
|
||||||
|
}
|
||||||
|
.header{
|
||||||
|
height: 40px;
|
||||||
|
text-align: center;
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.content{
|
||||||
|
height: 100px;
|
||||||
|
font-size: 18px;
|
||||||
|
line-height: 30px;
|
||||||
|
}
|
||||||
|
.subscribe{
|
||||||
|
height: 70px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.button{
|
||||||
|
text-align: center;
|
||||||
|
font-size: 18px;
|
||||||
|
font-family: sans-serif;
|
||||||
|
font-weight: bold;
|
||||||
|
padding: 0 30px 0 30px;
|
||||||
|
}
|
||||||
|
.button a{
|
||||||
|
color: #FFFFFF;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
.buttonwrapper{
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
.footer{
|
||||||
|
text-transform: uppercase;
|
||||||
|
text-align: center;
|
||||||
|
height: 40px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
.footer a{
|
||||||
|
color: #000000;
|
||||||
|
text-decoration: none;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body bgcolor="#009587">
|
||||||
|
<table bgcolor="#FFFFFF" width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||||
|
<tr class="header">
|
||||||
|
<td style="padding: 40px;">
|
||||||
|
Account Registered
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="content">
|
||||||
|
<td style="padding:10px;">
|
||||||
|
<p>
|
||||||
|
Hi <b>{{ .username }}</b>, <br/>
|
||||||
|
Your account has been registered into the system. You can now log into your account.
|
||||||
|
</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="subscribe">
|
||||||
|
<td style="padding: 20px 0 0 0;">
|
||||||
|
<h3>Your {{ .userType }} ID is:</h3>
|
||||||
|
<table bgcolor="#009587" border="0" cellspacing="0" cellpadding="0" class="buttonwrapper">
|
||||||
|
<tr>
|
||||||
|
<td class="button" height="45">
|
||||||
|
{{ .id }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="footer">
|
||||||
|
<td style="padding: 40px;">
|
||||||
|
This is an automated system email // DO NOT REPLY
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta name="viewport" content="width=device-width"/>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
<title>Password has been changed</title>
|
||||||
|
<style type="text/css">
|
||||||
|
body{
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0;
|
||||||
|
min-width: 100%;
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
table{
|
||||||
|
margin: 50px 0 50px 0;
|
||||||
|
}
|
||||||
|
.header{
|
||||||
|
height: 40px;
|
||||||
|
text-align: center;
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.content{
|
||||||
|
height: 100px;
|
||||||
|
font-size: 18px;
|
||||||
|
line-height: 30px;
|
||||||
|
}
|
||||||
|
.subscribe{
|
||||||
|
height: 70px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.button{
|
||||||
|
text-align: center;
|
||||||
|
font-size: 18px;
|
||||||
|
font-family: sans-serif;
|
||||||
|
font-weight: bold;
|
||||||
|
padding: 0 30px 0 30px;
|
||||||
|
}
|
||||||
|
.button a{
|
||||||
|
color: #FFFFFF;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
.buttonwrapper{
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
.footer{
|
||||||
|
text-transform: uppercase;
|
||||||
|
text-align: center;
|
||||||
|
height: 40px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
.footer a{
|
||||||
|
color: #000000;
|
||||||
|
text-decoration: none;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body bgcolor="#009587">
|
||||||
|
<table bgcolor="#FFFFFF" width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||||
|
<tr class="header">
|
||||||
|
<td style="padding: 40px;">
|
||||||
|
Password Change!
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="content">
|
||||||
|
<td style="padding:10px;">
|
||||||
|
<p>
|
||||||
|
Hi <b>{{ .username }}</b>, <br/>
|
||||||
|
Your password has been changed by the system.
|
||||||
|
</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="subscribe">
|
||||||
|
<td style="padding: 20px 0 0 0;">
|
||||||
|
<h3>Your new password is:</h3>
|
||||||
|
<table bgcolor="#009587" border="0" cellspacing="0" cellpadding="0" class="buttonwrapper">
|
||||||
|
<tr>
|
||||||
|
<td class="button" height="45">
|
||||||
|
{{ .password }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="footer">
|
||||||
|
<td style="padding: 40px;">
|
||||||
|
This is an automated system email // DO NOT REPLY
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta name="viewport" content="width=device-width"/>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
<title>Password has been changed</title>
|
||||||
|
<style type="text/css">
|
||||||
|
body{
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0;
|
||||||
|
min-width: 100%;
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
table{
|
||||||
|
margin: 50px 0 50px 0;
|
||||||
|
}
|
||||||
|
.header{
|
||||||
|
height: 40px;
|
||||||
|
text-align: center;
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.content{
|
||||||
|
height: 100px;
|
||||||
|
font-size: 18px;
|
||||||
|
line-height: 30px;
|
||||||
|
}
|
||||||
|
.subscribe{
|
||||||
|
height: 70px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.button{
|
||||||
|
text-align: center;
|
||||||
|
font-size: 18px;
|
||||||
|
font-family: sans-serif;
|
||||||
|
font-weight: bold;
|
||||||
|
padding: 0 30px 0 30px;
|
||||||
|
}
|
||||||
|
.button a{
|
||||||
|
color: #FFFFFF;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
.buttonwrapper{
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
.footer{
|
||||||
|
text-transform: uppercase;
|
||||||
|
text-align: center;
|
||||||
|
height: 40px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
.footer a{
|
||||||
|
color: #000000;
|
||||||
|
text-decoration: none;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body bgcolor="#009587">
|
||||||
|
<table bgcolor="#FFFFFF" width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||||
|
<tr class="header">
|
||||||
|
<td style="padding: 40px;">
|
||||||
|
Password Change!
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="content">
|
||||||
|
<td style="padding:10px;">
|
||||||
|
<p>
|
||||||
|
Hi <b>{{ .username }}</b>, <br/>
|
||||||
|
Your password has been changed by you. If you did not change your password, contact an admin immediatley!
|
||||||
|
</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="footer">
|
||||||
|
<td style="padding: 40px;">
|
||||||
|
This is an automated system email // DO NOT REPLY
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
-220
@@ -1,220 +0,0 @@
|
|||||||
courses = {
|
|
||||||
"P-CL": {
|
|
||||||
"name": "Pre-Calculus",
|
|
||||||
"code": "P-CL",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"CL": {
|
|
||||||
"name": "Calculus",
|
|
||||||
"code": "CL",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"EN-CW": {
|
|
||||||
"name": "English: Creative Writing",
|
|
||||||
"code": "EN-CW",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"EN-LS": {
|
|
||||||
"name": "English: Literary Studies",
|
|
||||||
"code": "EN-LS",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"EN-C": {
|
|
||||||
"name": "English: Compisition",
|
|
||||||
"code": "EN-C",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"S-J": {
|
|
||||||
"name": "Social Justice",
|
|
||||||
"code": "S-J",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"S-H": {
|
|
||||||
"name": "History",
|
|
||||||
"code": "S-H",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"S-P": {
|
|
||||||
"name": "Psychology",
|
|
||||||
"code": "S-P",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"SC-P": {
|
|
||||||
"name": "Physics",
|
|
||||||
"code": "SC-P",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"SC-B": {
|
|
||||||
"name": "Biology",
|
|
||||||
"code": "SC-B",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"SC-C": {
|
|
||||||
"name": "Chemistry",
|
|
||||||
"code": "SC-C",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"SC-ES": {
|
|
||||||
"name": "SC-ES",
|
|
||||||
"code": "cl12",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"M": {
|
|
||||||
"name": "Music",
|
|
||||||
"code": "Ms",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"CH": {
|
|
||||||
"name": "Choir",
|
|
||||||
"code": "CH",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"DN": {
|
|
||||||
"name": "Dance",
|
|
||||||
"code": "DN",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"CS": {
|
|
||||||
"name": "Computer Science",
|
|
||||||
"code": "CS",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"GD": {
|
|
||||||
"name": "Game Development",
|
|
||||||
"code": "GD",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"WW": {
|
|
||||||
"name": "Woodwork",
|
|
||||||
"code": "WW",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"MW": {
|
|
||||||
"name": "MetwalWork",
|
|
||||||
"code": "MW",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"M-WP": {
|
|
||||||
"name": "Math: Workplace",
|
|
||||||
"code": "M-WP",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"M-F": {
|
|
||||||
"name": "Math: Foundations",
|
|
||||||
"code": "M-F",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"BN": {
|
|
||||||
"name": "Band",
|
|
||||||
"code": "BN",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"TH": {
|
|
||||||
"name": "Theatre",
|
|
||||||
"code": "TH",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
},
|
|
||||||
"VD-P": {
|
|
||||||
"name": "Video Production",
|
|
||||||
"code": "VD-P",
|
|
||||||
"credits": 4,
|
|
||||||
"gradelevel": 11,
|
|
||||||
"totalrequests": 0,
|
|
||||||
"studentindexes": [],
|
|
||||||
"teachers": 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
activeCourses = {}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
import random
|
|
||||||
import names
|
|
||||||
from courses import courses
|
|
||||||
|
|
||||||
mockStudents = []
|
|
||||||
|
|
||||||
# Generate n students for mock data
|
|
||||||
def generateMockStudents(n):
|
|
||||||
for _ in range(n):
|
|
||||||
newStudent = {
|
|
||||||
"name": names.get_full_name(),
|
|
||||||
"requests": [], # list of class codes
|
|
||||||
"schedule": {
|
|
||||||
"block1": "",
|
|
||||||
"block2": "",
|
|
||||||
"block3": "",
|
|
||||||
"block4": "",
|
|
||||||
"block5": "",
|
|
||||||
"block6": "",
|
|
||||||
"block7": "",
|
|
||||||
"block8": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
# Get list of random class choices with no repeats
|
|
||||||
# 8 primary choices, 2 secondary choices
|
|
||||||
courseSelection = random.sample(range(0, len(courses)), 10)
|
|
||||||
for courseNum in courseSelection:
|
|
||||||
newStudent["requests"].append(list(courses)[courseNum])
|
|
||||||
mockStudents.append(newStudent)
|
|
||||||
|
|
||||||
return mockStudents
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
let schedule = require('./schedule.json');
|
|
||||||
let students = require('./students.json');
|
|
||||||
|
|
||||||
// console.table(schedule)
|
|
||||||
|
|
||||||
// Display first semester
|
|
||||||
// console.table(schedule.block1)
|
|
||||||
// console.table(schedule.block2)
|
|
||||||
// console.table(schedule.block3)
|
|
||||||
// console.table(schedule.block4)
|
|
||||||
|
|
||||||
// // Display second semester
|
|
||||||
// console.table(schedule.block5)
|
|
||||||
// console.table(schedule.block6)
|
|
||||||
// console.table(schedule.block7)
|
|
||||||
// console.table(schedule.block8)
|
|
||||||
|
|
||||||
// Display each students schedule
|
|
||||||
for (let i = 0; i < students.length; i++) {
|
|
||||||
console.table(students[i].schedule)
|
|
||||||
}
|
|
||||||
-390
@@ -1,390 +0,0 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
import sys
|
|
||||||
import json
|
|
||||||
import math
|
|
||||||
from courses import courses, activeCourses
|
|
||||||
from mock import generateMockStudents
|
|
||||||
|
|
||||||
'''
|
|
||||||
I will be using python to test and
|
|
||||||
develop course selection / schedule
|
|
||||||
generation
|
|
||||||
|
|
||||||
this is honestly terrible code but
|
|
||||||
this is not an easy task for me to
|
|
||||||
do
|
|
||||||
|
|
||||||
Block 1-4 is first semester while
|
|
||||||
block 5-8 is second semester
|
|
||||||
'''
|
|
||||||
|
|
||||||
'''
|
|
||||||
schedule example:
|
|
||||||
schedule: {
|
|
||||||
"block1": "className",
|
|
||||||
"block2": "className",
|
|
||||||
"block3": "className",
|
|
||||||
"block4": "className"
|
|
||||||
"block5": "className",
|
|
||||||
"block6": "className",
|
|
||||||
"block7": "className",
|
|
||||||
"block8": "className"
|
|
||||||
}
|
|
||||||
'''
|
|
||||||
|
|
||||||
'''
|
|
||||||
running example:
|
|
||||||
running: {
|
|
||||||
"block1": {classCode:{"className":name,"students":[student Name]},classCode:{"className":name,"students":[student Name]}},
|
|
||||||
"block2": {classCode:{"className":name,"students":[student Name]},classCode:{"className":name,"students":[student Name]}},
|
|
||||||
"block3": {classCode:{"className":name,"students":[student Name]},classCode:{"className":name,"students":[student Name]}},
|
|
||||||
"block4": {classCode:{"className":name,"students":[student Name]},classCode:{"className":name,"students":[student Name]}},
|
|
||||||
"block5": {classCode:{"className":name,"students":[student Name]},classCode:{"className":name,"students":[student Name]}},
|
|
||||||
"block6": {classCode:{"className":name,"students":[student Name]},classCode:{"className":name,"students":[student Name]}},
|
|
||||||
"block7": {classCode:{"className":name,"students":[student Name]},classCode:{"className":name,"students":[student Name]}},
|
|
||||||
"block8": {classCode:{"className":name,"students":[student Name]},classCode:{"className":name,"students":[student Name]}}
|
|
||||||
}
|
|
||||||
'''
|
|
||||||
|
|
||||||
# Error 1: No classes in schedule can fit this student
|
|
||||||
# Error 2: No more room in schedule for another class
|
|
||||||
|
|
||||||
# 400 by default
|
|
||||||
studentsNum = 500
|
|
||||||
|
|
||||||
err1, err2, = 0,0
|
|
||||||
minReq, classCap, blockClassLimit = 18, 30, 18
|
|
||||||
mockStudents = []
|
|
||||||
running = {
|
|
||||||
"block1": {},
|
|
||||||
"block2": {},
|
|
||||||
"block3": {},
|
|
||||||
"block4": {},
|
|
||||||
"block5": {},
|
|
||||||
"block6": {},
|
|
||||||
"block7": {},
|
|
||||||
"block8": {}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def generateScheduleV1():
|
|
||||||
global err1, err2
|
|
||||||
# Collect data and calculate schedules
|
|
||||||
for student in mockStudents:
|
|
||||||
# Tally class request
|
|
||||||
for request in student["requests"]:
|
|
||||||
courses[request]["totalrequests"] += 1
|
|
||||||
courses[request]["studentindexes"].append(mockStudents.index(student))
|
|
||||||
# Add course to active list if enough requests
|
|
||||||
if courses[request]["totalrequests"] > minReq and courses[request]["code"] not in activeCourses: activeCourses[courses[request]["code"]] = courses[request]
|
|
||||||
|
|
||||||
for student in mockStudents:
|
|
||||||
alternateOffset = len(student["requests"])-8
|
|
||||||
alternateIndex = 8
|
|
||||||
for i in range(len(student["requests"])-alternateOffset): # Subtract x classes as they are alternatives
|
|
||||||
currentCourse = student["requests"][i]
|
|
||||||
generate = True
|
|
||||||
while generate:
|
|
||||||
# If class is allowed to run
|
|
||||||
if currentCourse in activeCourses:
|
|
||||||
blockIndex = 1
|
|
||||||
courseNum = 1
|
|
||||||
getFreeBlock = True
|
|
||||||
while getFreeBlock:
|
|
||||||
block = f"block{blockIndex}"
|
|
||||||
cname = f"{courses[currentCourse]['name']}-{courseNum}"
|
|
||||||
if cname in running[block]:
|
|
||||||
if student["schedule"][block] == "": # Add student to class
|
|
||||||
if len(running[block][cname]["students"]) < classCap:
|
|
||||||
running[block][cname]["students"].append(student["name"])
|
|
||||||
student["schedule"][block] = cname
|
|
||||||
getFreeBlock = False
|
|
||||||
else: # Find next available class or create new one
|
|
||||||
if blockIndex == 8: # No available classes
|
|
||||||
if len(student["requests"]) == 8:
|
|
||||||
# This student never had any alternatives
|
|
||||||
# How to solve?
|
|
||||||
|
|
||||||
# print(f"\nError 1: No more available classes for student {student['name']}")
|
|
||||||
generate = False
|
|
||||||
else:
|
|
||||||
if alternateIndex <= (len(student["requests"]) - 1):
|
|
||||||
currentCourse = student["requests"][alternateIndex]
|
|
||||||
alternateIndex += 1
|
|
||||||
else: # No more alterantive
|
|
||||||
# print(f"\nError 1: No more available classes for student {student['name']}")
|
|
||||||
err1 += 1
|
|
||||||
generate = False
|
|
||||||
getFreeBlock = False
|
|
||||||
else:
|
|
||||||
if (courses[currentCourse]["teachers"] - courseNum) > 0:
|
|
||||||
courseNum += 1
|
|
||||||
else:
|
|
||||||
blockIndex += 1
|
|
||||||
courseNum = 1
|
|
||||||
else:
|
|
||||||
if blockIndex == 8: # No available classes
|
|
||||||
if len(student["requests"]) == 8:
|
|
||||||
# This student never had any alternatives
|
|
||||||
# How to solve?
|
|
||||||
|
|
||||||
# print(f"\nError 1: No more available classes for student {student['name']}")
|
|
||||||
err1 += 1
|
|
||||||
generate = False
|
|
||||||
else:
|
|
||||||
if alternateIndex <= (len(student["requests"]) - 1):
|
|
||||||
currentCourse = student["requests"][alternateIndex]
|
|
||||||
alternateIndex += 1
|
|
||||||
else: # No more alternatives
|
|
||||||
# print(f"\nError 1: No more available classes for student {student['name']}")
|
|
||||||
err1 += 1
|
|
||||||
generate = False
|
|
||||||
getFreeBlock = False
|
|
||||||
else:
|
|
||||||
blockIndex += 1
|
|
||||||
courseNum = 1
|
|
||||||
else:
|
|
||||||
if blockIndex == 8:
|
|
||||||
# Class does not exists
|
|
||||||
# Create new class in first available slot
|
|
||||||
blockNum = 1
|
|
||||||
while True:
|
|
||||||
newBlock = f"block{blockNum}"
|
|
||||||
if cname not in running[newBlock] and len(running[newBlock]) < blockClassLimit:
|
|
||||||
if student["schedule"][newBlock] == "": # Add student to class
|
|
||||||
running[newBlock][cname] = {
|
|
||||||
"name": courses[currentCourse]["name"],
|
|
||||||
"students": [student["name"]]
|
|
||||||
}
|
|
||||||
student["schedule"][newBlock] = cname
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
if blockNum == 8:
|
|
||||||
# All student classes have been filled
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
blockNum += 1
|
|
||||||
courseNum = 1
|
|
||||||
else:
|
|
||||||
if blockNum == 8:
|
|
||||||
# No room in school for more classes
|
|
||||||
# print(f"\nError 2: No more room in school for another class")
|
|
||||||
err2 += 1
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
if (courses[currentCourse]["teachers"] - courseNum) > 0:
|
|
||||||
courseNum += 1
|
|
||||||
else:
|
|
||||||
blockNum += 1
|
|
||||||
courseNum = 1
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
blockIndex += 1
|
|
||||||
courseNum = 1
|
|
||||||
break
|
|
||||||
elif currentCourse not in activeCourses:
|
|
||||||
if len(student["requests"]) == 8:
|
|
||||||
# This student never had any alternatives
|
|
||||||
# How to solve?
|
|
||||||
|
|
||||||
# print(f"\nError 1: No more available classes for student {student['name']}")
|
|
||||||
err1 += 1
|
|
||||||
generate = False
|
|
||||||
else:
|
|
||||||
if alternateIndex <= (len(student["requests"]) - 1):
|
|
||||||
currentCourse = student["requests"][alternateIndex]
|
|
||||||
alternateIndex += 1
|
|
||||||
else: # Out of alternatives
|
|
||||||
# print(f"\nError 1: No more available classes for student {student['name']}")
|
|
||||||
err1 += 1
|
|
||||||
generate = False
|
|
||||||
|
|
||||||
|
|
||||||
def generateScheduleV2():
|
|
||||||
global err1, err2
|
|
||||||
# Collect data and calculate schedules
|
|
||||||
for student in mockStudents:
|
|
||||||
# Tally class request
|
|
||||||
for request in student["requests"]:
|
|
||||||
courses[request]["totalrequests"] += 1
|
|
||||||
courses[request]["studentindexes"].append(mockStudents.index(student))
|
|
||||||
# Add course to active list if enough requests
|
|
||||||
if courses[request]["totalrequests"] > minReq and courses[request]["code"] not in activeCourses: activeCourses[courses[request]["code"]] = courses[request]
|
|
||||||
|
|
||||||
# calculate # of times to run class
|
|
||||||
for i in range(len(activeCourses)):
|
|
||||||
index = list(activeCourses)[i]
|
|
||||||
classRunCount = math.floor(activeCourses[index]["totalrequests"] / classCap)
|
|
||||||
# If there is minReq+ requests left, 1 more class could be run
|
|
||||||
if (activeCourses[index]["totalrequests"] % classCap) > minReq: classRunCount += 1
|
|
||||||
activeCourses[index]["classRunCount"] = classRunCount
|
|
||||||
|
|
||||||
blockIndex = 1
|
|
||||||
while classRunCount > 0:
|
|
||||||
block = f"block{blockIndex}"
|
|
||||||
if activeCourses[index]["code"] not in running[block] and len(running[block]) < blockClassLimit:
|
|
||||||
# Generate class and sub 1 from classRunCount
|
|
||||||
running[block][activeCourses[index]["code"]] = {
|
|
||||||
"name": activeCourses[index]["name"],
|
|
||||||
"students": []
|
|
||||||
}
|
|
||||||
classRunCount -= 1
|
|
||||||
else:
|
|
||||||
if blockIndex == 8:
|
|
||||||
# No room in school for more classes
|
|
||||||
# print(f"\nError 2: No more room in school for another class")
|
|
||||||
err2 += 1
|
|
||||||
classRunCount = 0
|
|
||||||
else:
|
|
||||||
blockIndex += 1
|
|
||||||
|
|
||||||
for student in mockStudents:
|
|
||||||
alternateOffset = len(student["requests"])-8
|
|
||||||
alternateIndex = 8
|
|
||||||
for i in range(len(student["requests"])-alternateOffset): # Subtract x classes as they are alternatives
|
|
||||||
currentCourse = student["requests"][i]
|
|
||||||
generate = True
|
|
||||||
while generate:
|
|
||||||
# If class is allowed to run
|
|
||||||
if currentCourse in activeCourses:
|
|
||||||
blockIndex = 1
|
|
||||||
getFreeBlock = True
|
|
||||||
while getFreeBlock:
|
|
||||||
block = f"block{blockIndex}"
|
|
||||||
if currentCourse in running[block]:
|
|
||||||
if student["schedule"][block] == "": # Add student to class
|
|
||||||
if len(running[block][currentCourse]["students"]) < classCap:
|
|
||||||
running[block][currentCourse]["students"].append(student["name"])
|
|
||||||
student["schedule"][block] = courses[currentCourse]["name"]
|
|
||||||
getFreeBlock = False
|
|
||||||
else: # Find next available class or create new one
|
|
||||||
if blockIndex == 8: # No available classes
|
|
||||||
if len(student["requests"]) == 8:
|
|
||||||
# This student never had any alternatives
|
|
||||||
# How to solve?
|
|
||||||
|
|
||||||
# print(f"\nError 1: No more available classes for student {student['name']}")
|
|
||||||
err1 += 1
|
|
||||||
generate = False
|
|
||||||
else:
|
|
||||||
if alternateIndex <= (len(student["requests"]) - 1):
|
|
||||||
currentCourse = student["requests"][alternateIndex]
|
|
||||||
alternateIndex += 1
|
|
||||||
else: # No more alterantive
|
|
||||||
# print(f"\nError 1: No more available classes for student {student['name']}")
|
|
||||||
err1 += 1
|
|
||||||
generate = False
|
|
||||||
getFreeBlock = False
|
|
||||||
else: blockIndex += 1
|
|
||||||
else:
|
|
||||||
if blockIndex == 8: # No available classes
|
|
||||||
if len(student["requests"]) == 8:
|
|
||||||
# This student never had any alternatives
|
|
||||||
# How to solve?
|
|
||||||
|
|
||||||
# print(f"\nError 1: No more available classes for student {student['name']}")
|
|
||||||
err1 += 1
|
|
||||||
generate = False
|
|
||||||
else:
|
|
||||||
if alternateIndex <= (len(student["requests"]) - 1):
|
|
||||||
currentCourse = student["requests"][alternateIndex]
|
|
||||||
alternateIndex += 1
|
|
||||||
else: # No more alternatives
|
|
||||||
# print(f"\nError 1: No more available classes for student {student['name']}")
|
|
||||||
err1 += 1
|
|
||||||
generate = False
|
|
||||||
getFreeBlock = False
|
|
||||||
else: blockIndex += 1
|
|
||||||
else:
|
|
||||||
if blockIndex == 8:
|
|
||||||
# Class does not exists
|
|
||||||
# Resort to alternative
|
|
||||||
if alternateIndex <= (len(student["requests"]) - 1):
|
|
||||||
currentCourse = student["requests"][alternateIndex]
|
|
||||||
alternateIndex += 1
|
|
||||||
else: # Out of alternatives
|
|
||||||
# print(f"\nError 1: No more available classes for student {student['name']}")
|
|
||||||
err1 += 1
|
|
||||||
generate = False
|
|
||||||
break
|
|
||||||
else: blockIndex += 1
|
|
||||||
break
|
|
||||||
elif currentCourse not in activeCourses:
|
|
||||||
if len(student["requests"]) == 8:
|
|
||||||
# This student never had any alternatives
|
|
||||||
# How to solve?
|
|
||||||
|
|
||||||
# print(f"\nError 1: No more available classes for student {student['name']}")
|
|
||||||
err1 += 1
|
|
||||||
generate = False
|
|
||||||
else:
|
|
||||||
if alternateIndex <= (len(student["requests"]) - 1):
|
|
||||||
currentCourse = student["requests"][alternateIndex]
|
|
||||||
alternateIndex += 1
|
|
||||||
else: # Out of alternatives
|
|
||||||
# print(f"\nError 1: No more available classes for student {student['name']}")
|
|
||||||
err1 += 1
|
|
||||||
generate = False
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
if len(sys.argv) == 1:
|
|
||||||
print("Missing argument")
|
|
||||||
exit()
|
|
||||||
if sys.argv[1].upper() == 'V1':
|
|
||||||
if len(sys.argv) == 3:
|
|
||||||
try:
|
|
||||||
studentsNum = int(sys.argv[2])
|
|
||||||
except:
|
|
||||||
print("Error parsing number of students")
|
|
||||||
exit()
|
|
||||||
print("Processing...")
|
|
||||||
mockStudents = generateMockStudents(studentsNum)
|
|
||||||
generateScheduleV1()
|
|
||||||
elif sys.argv[1].upper() == 'V2':
|
|
||||||
if len(sys.argv) == 3:
|
|
||||||
try:
|
|
||||||
studentsNum = int(sys.argv[2])
|
|
||||||
except:
|
|
||||||
print("Error parsing number of students")
|
|
||||||
exit()
|
|
||||||
print("Processing...")
|
|
||||||
mockStudents = generateMockStudents(studentsNum)
|
|
||||||
generateScheduleV2()
|
|
||||||
else:
|
|
||||||
print("Invalid argument")
|
|
||||||
exit()
|
|
||||||
|
|
||||||
print("\n")
|
|
||||||
print(f"Error 1: x{err1}")
|
|
||||||
print(f"Error 2: x{err2}")
|
|
||||||
print("\n")
|
|
||||||
|
|
||||||
### Displays the number of students in each class
|
|
||||||
# for block in running:
|
|
||||||
# print(f"\nBlock: {block}")
|
|
||||||
# print("=====================")
|
|
||||||
# for cl in running[block]:
|
|
||||||
# name = running[block][cl]["name"]
|
|
||||||
# students = len(running[block][cl]["students"])
|
|
||||||
# print(f"Class: {name} | Students: {students}")
|
|
||||||
|
|
||||||
# Count errors in students schedules
|
|
||||||
errors = 0
|
|
||||||
for i in range(len(mockStudents)):
|
|
||||||
count = 0
|
|
||||||
for course in mockStudents[i]["schedule"]:
|
|
||||||
if mockStudents[i]["schedule"][course]=="": count+=1
|
|
||||||
if count > 0: errors += 1
|
|
||||||
|
|
||||||
print(f"{errors}/{studentsNum} student(s) have a issue with their schedule")
|
|
||||||
|
|
||||||
|
|
||||||
with open("schedule.json", "w") as outfile:
|
|
||||||
json.dump(running, outfile, indent=2)
|
|
||||||
|
|
||||||
with open("students.json", "w") as outfile:
|
|
||||||
json.dump(mockStudents, outfile, indent=2)
|
|
||||||
|
|
||||||
print("Done")
|
|
||||||
Reference in new issue
Block a user