diff --git a/prisma/migrations/20240724063400_auth_overhaul_1/migration.sql b/prisma/migrations/20240724063400_auth_overhaul_1/migration.sql new file mode 100644 index 0000000..d8bb8f1 --- /dev/null +++ b/prisma/migrations/20240724063400_auth_overhaul_1/migration.sql @@ -0,0 +1,32 @@ +/* + Warnings: + + - You are about to drop the column `addr` on the `User` table. All the data in the column will be lost. + - You are about to drop the column `bdate` on the `User` table. All the data in the column will be lost. + - You are about to drop the column `cnum` on the `User` table. All the data in the column will be lost. + - You are about to drop the column `emailaddr` on the `User` table. All the data in the column will be lost. + - You are about to drop the column `isOnline` on the `User` table. All the data in the column will be lost. + - You are about to drop the column `login_password` on the `User` table. All the data in the column will be lost. + - You are about to drop the column `mname` on the `User` table. All the data in the column will be lost. + - The values [Clinic] on the enum `User_type` will be removed. If these variants are still used in the database, this will fail. + - You are about to drop the `Otp` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropIndex +DROP INDEX `User_emailaddr_key` ON `User`; + +-- DropIndex +DROP INDEX `User_fname_mname_lname_key` ON `User`; + +-- AlterTable +ALTER TABLE `User` DROP COLUMN `addr`, + DROP COLUMN `bdate`, + DROP COLUMN `cnum`, + DROP COLUMN `emailaddr`, + DROP COLUMN `isOnline`, + DROP COLUMN `login_password`, + DROP COLUMN `mname`, + MODIFY `type` ENUM('Student', 'Teacher', 'Guidance', 'Admin') NOT NULL; + +-- DropTable +DROP TABLE `Otp`; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index d421b55..82dbc72 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -13,24 +13,18 @@ datasource db { url = env("DATABASE_URL") } +// TODO: Remove references to the removed fields model User { - id String @id @default(uuid()) - fname String @db.VarChar(30) - mname String? @db.VarChar(30) - lname String @db.VarChar(30) - isOnline Boolean? @default(false) - - addr String @db.VarChar(255) - cnum String @db.VarChar(50) - emailaddr String @unique @db.VarChar(50) - bdate DateTime @db.Date + id String @id @default(uuid()) + fname String @db.VarChar(30) + lname String @db.VarChar(30) + createdAt DateTime @default(now()) updatedAt DateTime @default(now()) @updatedAt type user_type login_username String @unique - login_password String approved user_approval_type @default(Pending) @@ -42,8 +36,6 @@ model User { Notifications Notifications[] Feedback Feedback? GuidanceRecord GuidanceRecord[] - - @@unique([fname, mname, lname]) } model RefreshToken { @@ -131,19 +123,11 @@ model Notifications { usersToNotify User[] } -model Otp { - id String @id @default(uuid()) - revoked Boolean @default(false) - emailaddr String @unique - otp Int - createdAt DateTime @default(now()) -} - +// TODO: Remove references to removed field Clinic enum user_type { Student Teacher Guidance - Clinic Admin } diff --git a/routes/admin.routes.js b/routes/admin.routes.js index 72a140d..02363fc 100644 --- a/routes/admin.routes.js +++ b/routes/admin.routes.js @@ -22,12 +22,7 @@ router.get("/users", async (req, res, next) => { select: { id: true, fname: true, - mname: true, lname: true, - addr: true, - cnum: true, - emailaddr: true, - bdate: true, type: true, login_username: true, }, @@ -47,12 +42,7 @@ router.get("/archivedusers", async (req, res, next) => { select: { id: true, fname: true, - mname: true, lname: true, - addr: true, - cnum: true, - emailaddr: true, - bdate: true, type: true, login_username: true, }, @@ -71,7 +61,6 @@ router.get("/feedbacks", async (req, res, next) => { select: { id: true, fname: true, - mname: true, lname: true, type: true, }, @@ -94,12 +83,7 @@ router.get("/pendingusers", async (req, res, next) => { select: { id: true, fname: true, - mname: true, lname: true, - addr: true, - cnum: true, - emailaddr: true, - bdate: true, type: true, login_username: true, }, @@ -224,12 +208,10 @@ router.post("/unarchive/:id", async (req, res) => { res.json(message); } catch (error) { console.error(error); - res - .status(500) - .json({ - error: "An error occurred while unarchiving the user", - errbody: error, - }); + res.status(500).json({ + error: "An error occurred while unarchiving the user", + errbody: error, + }); } }); @@ -339,12 +321,10 @@ router.delete("/user/:id", async (req, res) => { } } catch (error) { console.error(error); - res - .status(500) - .json({ - error: "An error occurred while deleting the user", - errbody: error, - }); + res.status(500).json({ + error: "An error occurred while deleting the user", + errbody: error, + }); } }); diff --git a/routes/appointments.routes.js b/routes/appointments.routes.js index 4a96b78..2b725a0 100644 --- a/routes/appointments.routes.js +++ b/routes/appointments.routes.js @@ -27,7 +27,6 @@ router.get("/students", async (req, res, next) => { select: { id: true, fname: true, - mname: true, lname: true, }, }); @@ -60,7 +59,6 @@ router.get("/staff", async (req, res, next) => { select: { id: true, fname: true, - mname: true, lname: true, type: true, }, @@ -152,7 +150,6 @@ router.get("/schedules", async (req, res, next) => { select: { id: true, fname: true, - mname: true, lname: true, type: true, }, @@ -236,7 +233,6 @@ router.get("/staff-availability", async (req, res, next) => { select: { id: true, fname: true, - mname: true, lname: true, }, }, @@ -292,7 +288,6 @@ router.get("/schedules/by-user/:id", async (req, res, next) => { select: { id: true, fname: true, - mname: true, lname: true, type: true, }, @@ -319,7 +314,6 @@ router.get("/schedule/:id", async (req, res) => { select: { id: true, fname: true, - mname: true, lname: true, type: true, }, @@ -525,7 +519,6 @@ router.get("/messages/by-schedule/:id", async (req, res, next) => { select: { login_username: true, fname: true, - mname: true, lname: true, }, }, diff --git a/routes/auth.routes.js b/routes/auth.routes.js index f34e3b2..8333b3c 100644 --- a/routes/auth.routes.js +++ b/routes/auth.routes.js @@ -39,60 +39,25 @@ const emailheader = "Scheduler Project by Christian Aranas"; router.post("/register", async (req, res, next) => { try { - const { - fname, - lname, - login_username, - login_password, - addr, - cnum, - emailaddr, - bdate, - type, - otp: otpInReq, - } = req.body; + const { fname, lname, login_username, type } = req.body; + // console.log(req.body); - if ( - !login_username || - !login_password || - !fname || - !lname || - !addr || - !cnum || - !emailaddr || - !bdate || - !type - ) { + if (!login_username || !fname || !lname || !type) { res.status(400); throw new Error(`You must provide an all required fields.`); } - if (await findUserByEmail(emailaddr)) { - res.status(400); - throw new Error( - "That email is already registered. If that is not you, please contact the developers.", - ); - } const existingUser = await findUserByUsername(login_username); if (existingUser) { res.status(400); - throw new Error("LRN/Username already in use"); + throw new Error("Username already in use"); } - let otpInDatabase = await prisma.otp.findUnique({ - where: { - emailaddr: emailaddr, - }, - }); - - verifySession(otpInDatabase, otpInReq); - if (type == user_type.Admin) { res.status(400); throw new Error("Unauthorized"); } - delete req.body.otp; const user = await createUser(req.body); createNotification({ @@ -110,26 +75,17 @@ router.post("/register", async (req, res, next) => { router.post("/login", async (req, res, next) => { try { - const { login_username, login_password } = req.body; - if (!login_username || !login_password) { + const { login_username } = req.body; + if (!login_username) { res.status(400); - throw new Error("You must provide an email and a password."); + throw new Error("You must provide your username."); } const existingUser = await findUserByUsername(login_username); if (!existingUser) { res.status(403); - throw new Error("Invalid login credentials."); - } - - const validPassword = await bcrypt.compareSync( - login_password, - existingUser.login_password, - ); - if (!validPassword) { - res.status(403); - throw new Error("Invalid login credentials."); + throw new Error("Invalid username used."); } switch (existingUser.approved) { @@ -341,13 +297,15 @@ router.post("/googlelogin", async (req, res, next) => { const existingUser = await prisma.user.findUnique({ where: { - emailaddr: email, + login_username: email, }, }); if (!existingUser) { res.status(403); - throw new Error("Invalid login credentials."); + throw new Error( + "Invalid login credentials. Make sure that the email of your Google account matches your registered username.", + ); } switch (existingUser.approved) { diff --git a/routes/guidancerecords.routes.js b/routes/guidancerecords.routes.js index 31c2d10..bb1345c 100644 --- a/routes/guidancerecords.routes.js +++ b/routes/guidancerecords.routes.js @@ -72,7 +72,6 @@ router.get("/students", async (req, res, next) => { select: { id: true, fname: true, - mname: true, lname: true, type: true, }, diff --git a/routes/medrecords.routes.js b/routes/medrecords.routes.js index 8959c17..98874b8 100644 --- a/routes/medrecords.routes.js +++ b/routes/medrecords.routes.js @@ -71,7 +71,6 @@ router.get("/users", async (req, res, next) => { select: { id: true, fname: true, - mname: true, lname: true, type: true, }, diff --git a/routes/users.routes.js b/routes/users.routes.js index 75c5128..b69f597 100644 --- a/routes/users.routes.js +++ b/routes/users.routes.js @@ -50,7 +50,6 @@ router.get("/onlineusers", async (req, res, next) => { }, select: { fname: true, - mname: true, lname: true, type: true, }, diff --git a/routes/users.services.js b/routes/users.services.js index 5d1153a..8acc820 100644 --- a/routes/users.services.js +++ b/routes/users.services.js @@ -1,6 +1,7 @@ const bcrypt = require("bcrypt"); const { db } = require("../db"); const jwt = require("jsonwebtoken"); +const { user_approval_type } = require("@prisma/client"); function findUserByUsername(login_username) { return db.user.findUnique({ @@ -37,7 +38,7 @@ function findUserByEmail(emailaddr) { } function createUser(user) { - user.login_password = bcrypt.hashSync(user.login_password, 12); + user.approved = user_approval_type.Approved; console.log(user); return db.user.create({ data: user, diff --git a/socket/connection.socket.js b/socket/connection.socket.js index d0ce343..3ec74ab 100644 --- a/socket/connection.socket.js +++ b/socket/connection.socket.js @@ -1,7 +1,7 @@ const { PrismaClient, Prisma } = require("@prisma/client"); -const { findUserIdByAccessToken } = require("../routes/users.services") +const { findUserIdByAccessToken } = require("../routes/users.services"); const prisma = new PrismaClient(); -const jwt = require('jsonwebtoken'); +const jwt = require("jsonwebtoken"); const { findRefreshTokenById } = require("../routes/auth.services"); const { db } = require("../db"); @@ -10,32 +10,30 @@ class Connection { this.socket = socket; this.io = io; - this.updatePeopleOnline() + this.updatePeopleOnline(); - socket.on('disconnect', () => this.disconnect()); - socket.on('connect_error', (err) => { + socket.on("disconnect", () => this.disconnect()); + socket.on("connect_error", (err) => { console.log(`connect_error due to ${err.message}`); }); } disconnect() { - console.log('🔥: A user disconnected'); - - this.updatePeopleOnline(this.socket.userId, false) + console.log("🔥: A user disconnected"); + this.updatePeopleOnline(this.socket.userId, false); } async updatePeopleOnline() { try { - const users = [] + const users = []; for (let [id, socket] of this.io.of("/").sockets) { - if (!users.some(el => el.userId === socket.userId)) + if (!users.some((el) => el.userId === socket.userId)) users.push({ userId: socket.userId, login_username: socket.login_username, fname: socket.fname, - mname: socket.mname, lname: socket.lname, - type: socket.type + type: socket.type, }); } this.io.emit("users", users); @@ -48,18 +46,17 @@ class Connection { function connect(io) { io.use(async (socket, next) => { const accessToken = socket.handshake.auth.accessToken; - const refreshToken = socket.handshake.auth.refreshToken - const userId = findUserIdByAccessToken(accessToken) + const refreshToken = socket.handshake.auth.refreshToken; + const userId = findUserIdByAccessToken(accessToken); - if (!userId) - return next(new Error("invalid access token")) + if (!userId) return next(new Error("invalid access token")); const payload = jwt.verify(refreshToken, process.env.JWT_REFRESH_SECRET); const savedRefreshToken = await findRefreshTokenById(payload.jti); - console.log(savedRefreshToken) + console.log(savedRefreshToken); if (!savedRefreshToken || savedRefreshToken.revoked === true) { - return next(new Error('unauthorized session')); + return next(new Error("unauthorized session")); } const user = await db.user.findUnique({ @@ -69,26 +66,22 @@ function connect(io) { select: { login_username: true, fname: true, - mname: true, lname: true, - type: true - } + type: true, + }, }); - - socket.userId = userId - socket.login_username = user.login_username - socket.fname = user.fname - socket.mname = user.mname - socket.lname = user.lname - socket.type = user.type - next() - }) - io.on('connect', (socket) => { + socket.userId = userId; + socket.login_username = user.login_username; + socket.fname = user.fname; + socket.lname = user.lname; + socket.type = user.type; + next(); + }); + io.on("connect", (socket) => { console.log(`⚡: ${socket.id} user just connected!`); - new Connection(io, socket) - socket.join(socket.userId) - + new Connection(io, socket); + socket.join(socket.userId); }); } module.exports = connect; diff --git a/src-frontend-react/src/App.tsx b/src-frontend-react/src/App.tsx index 6346190..704d129 100644 --- a/src-frontend-react/src/App.tsx +++ b/src-frontend-react/src/App.tsx @@ -282,12 +282,8 @@ const App: React.FC = () => { {onlineUsers.map((user) => { return ( {`[${user.type}] ${user.lname}, ${user.fname} ${ - user.mname ? user.mname[0] + "." : "" - }`} + key={user.fname + user.lname + user.type} + >{`[${user.type}] ${user.lname}, ${user.fname}`} ); })} diff --git a/src-frontend-react/src/components/AdminTools/FeedbackAnalytics/index.js b/src-frontend-react/src/components/AdminTools/FeedbackAnalytics/index.js index bab35f7..9767ca8 100644 --- a/src-frontend-react/src/components/AdminTools/FeedbackAnalytics/index.js +++ b/src-frontend-react/src/components/AdminTools/FeedbackAnalytics/index.js @@ -102,11 +102,9 @@ const FeedbackAnalytics = () => { return (

- {`[${user.type}] ${user.lname}, ${user.fname} ${ - user.mname - } (${moment(feedback.createdAt).format( - "MMM DD, YYYY hh:mm A", - )})`} + {`[${user.type}] ${user.lname}, ${user.fname} (${moment( + feedback.createdAt, + ).format("MMM DD, YYYY hh:mm A")})`}

{feedback.feedbackText}
diff --git a/src-frontend-react/src/components/AdminTools/UserApproval/index.js b/src-frontend-react/src/components/AdminTools/UserApproval/index.js index 645c8a7..032057b 100644 --- a/src-frontend-react/src/components/AdminTools/UserApproval/index.js +++ b/src-frontend-react/src/components/AdminTools/UserApproval/index.js @@ -77,9 +77,7 @@ const UserApprovalComponent = () => {

- {`${user.lname} , ${user.fname} ${ - user.mname ? user.mname : "" - }`} + {`${user.lname} , ${user.fname} `}

User Type: {user.type}
diff --git a/src-frontend-react/src/components/AdminTools/UserManagementForm/index.js b/src-frontend-react/src/components/AdminTools/UserManagementForm/index.js index adc0ee9..85969f2 100644 --- a/src-frontend-react/src/components/AdminTools/UserManagementForm/index.js +++ b/src-frontend-react/src/components/AdminTools/UserManagementForm/index.js @@ -12,15 +12,9 @@ import { user_type } from "@prisma/client"; const DEFAULT_FORM_VALUES = { id: "", fname: "", - mname: "", lname: "", - addr: "", - cnum: "", - emailaddr: "", - bdate: "", type: "", login_username: "", // Add username field - login_password: "", // Add password field }; /// NOTE The `{ ...DEFAULT_FORM_VALUES }` is used because simply @@ -102,9 +96,7 @@ export const UserManagementForm = () => { ...usersList.map((user) => { return { value: user, - label: `[${user.type}] ${user.lname}, ${user.fname}${ - user.mname ? " " + user.mname : "" - }`, + label: `[${user.type}] ${user.lname}, ${user.fname}`, }; }), ]); @@ -120,7 +112,6 @@ export const UserManagementForm = () => { const user = e.value; user.login_password = ""; - user.bdate = moment(user.bdate).format("YYYY-MM-DD"); setFormData(user); console.log(user); @@ -128,7 +119,7 @@ export const UserManagementForm = () => { const handleChange = (e) => { let { name, value } = e.target; - if (name === "fname" || name === "mname" || name === "lname") { + if (name === "fname" || name === "lname") { console.log("triggered"); value = value.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); @@ -160,41 +151,6 @@ export const UserManagementForm = () => { newFormErrors.lname = ""; } - // Validate Address - if (formData.addr.trim() === "") { - newFormErrors.addr = "Address is required"; - isValid = false; - } else { - newFormErrors.addr = ""; - } - - // Validate Email - const emailPattern = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i; - if (!formData.emailaddr.trim().match(emailPattern)) { - newFormErrors.emailaddr = "Invalid email address"; - isValid = false; - } else { - newFormErrors.emailaddr = ""; - } - - // Validate Phone Number - const phonepattern = /^(09|\+639)\d{9}$/; - if (!formData.cnum.trim().match(phonepattern)) { - newFormErrors.cnum = - "phone number must be in 09xxxxxxxxx or in +639xxxxxxxxx format"; - isValid = false; - } else { - newFormErrors.cnum = ""; - } - - // Validate Birthday (you can add custom date validation logic) - if (formData.bdate.trim() === "") { - newFormErrors.bdate = "Birthday is required"; - isValid = false; - } else { - newFormErrors.bdate = ""; - } - // Validate Username if (formData.login_username.trim() === "") { newFormErrors.login_username = "Username is required"; @@ -203,28 +159,6 @@ export const UserManagementForm = () => { newFormErrors.login_username = ""; } - // Validate Password - const passwordPattern = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@#$%^&+=!_]).{8,}$/; - if ( - !formData.login_password.trim().match(passwordPattern) && - formData.login_password.length !== 0 && - formData.id - ) { - newFormErrors.login_password = - "Password must be left blank to leave unchanged or:\n- be at least 8 characters long\n- contain at least 1 alphabet and 1 numeric character\n- contain at least 1 special character (@#$%^&+=!_)"; - - isValid = false; - } else if ( - !formData.login_password.trim().match(passwordPattern) && - !formData.id - ) { - newFormErrors.login_password = - "Password must be:\n- be at least 8 characters long\n- contain at least 1 alphabet and 1 numeric character\n- contain at least 1 special character (@#$%^&+=!_)"; - isValid = false; - } else { - newFormErrors.login_password = ""; - } - setFormErrors(newFormErrors); return isValid; }; @@ -236,12 +170,7 @@ export const UserManagementForm = () => { // Handle form submission here (e.g., send data to a server). const formatted = { fname: formData.fname, - mname: formData.mname, lname: formData.lname, - addr: formData.addr, - cnum: formData.cnum, - emailaddr: formData.emailaddr, - bdate: moment(new Date(formData.bdate)).toISOString(), type: formData.type, login_username: formData.login_username, }; @@ -388,15 +317,6 @@ export const UserManagementForm = () => { />
{formErrors.fname}
- - Middle Name - - Last Name {
{formErrors.lname}
- - Address - -
{formErrors.addr}
-
- - - Email - -
{formErrors.emailaddr}
-
- - Phone Number - -
{formErrors.cnum}
-
-
- - Birthday - -
{formErrors.bdate}
-
- + User Type
{userTypes.map((userType) => ( @@ -492,6 +366,7 @@ export const UserManagementForm = () => { Password { className="w-100 px-3 justify-content-between" > - {`[${user.type}] ${user.lname}, ${user.fname} ${user.mname}`} + {`[${user.type}] ${user.lname}, ${user.fname}`} +

+ Note: This only works if your username matches your Google's email + address. +

or
{ onSubmit={handleLogin} > - Username/LRN + Username setUsername(e.target.value)} /> @@ -158,6 +161,7 @@ export const LoginForm = ({ setIsLoading, setLoadingText, setTabKey }) => { Password {

- Demo user: demoer | Password: demo_1234 + This is a public version. Logging in is oversimplified to allow testing + of the application. No need to input a password, but a quick + registration is still required.

); diff --git a/src-frontend-react/src/components/LoginFormModal/RegistrationForm.js b/src-frontend-react/src/components/LoginFormModal/RegistrationForm.js index 752cad9..e5c4270 100644 --- a/src-frontend-react/src/components/LoginFormModal/RegistrationForm.js +++ b/src-frontend-react/src/components/LoginFormModal/RegistrationForm.js @@ -16,16 +16,9 @@ import { useGoogleLogin } from "@react-oauth/google"; const DEFAULT_FORM_VALUES = { id: "", fname: "", - mname: "", lname: "", - addr: "", - cnum: "", - emailaddr: "", - bdate: "", type: "", - login_username: "", // Add username field - login_password: "", // Add password field - otp: "", + login_username: "", }; const RegistrationForm = ({ setIsLoading, setLoadingText, setTabKey }) => { @@ -43,10 +36,6 @@ const RegistrationForm = ({ setIsLoading, setLoadingText, setTabKey }) => { setFormErrors({ ...DEFAULT_FORM_VALUES }); }; - const glogin = useGoogleLogin({ - onSuccess: (tokenResponse) => handleGoogleLoginSuccess(tokenResponse), - }); - const [isFetchingAll, setIsFetchingAll] = useState(true); const fetchAll = useCallback(() => { setIsLoading(true); @@ -76,7 +65,7 @@ const RegistrationForm = ({ setIsLoading, setLoadingText, setTabKey }) => { const handleChange = (e) => { let { name, value } = e.target; - if (name === "fname" || name === "mname" || name === "lname") { + if (name === "fname" || name === "lname") { console.log("triggered"); value = value.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); @@ -108,77 +97,22 @@ const RegistrationForm = ({ setIsLoading, setLoadingText, setTabKey }) => { newFormErrors.lname = ""; } - // Validate Address - if (formData.addr.trim() === "") { - newFormErrors.addr = "Address is required"; - isValid = false; - } else { - newFormErrors.addr = ""; - } - - // Validate Email - const emailPattern = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i; - if (!formData.emailaddr.trim().match(emailPattern)) { - newFormErrors.emailaddr = "Invalid email address"; - isValid = false; - } else { - newFormErrors.emailaddr = ""; - } - - // Validate Phone Number - const phonepattern = /^(09|\+639)\d{9}$/; - if (!formData.cnum.trim().match(phonepattern)) { - newFormErrors.cnum = - "phone number must be in 09xxxxxxxxx or in +639xxxxxxxxx format"; - isValid = false; - } else { - newFormErrors.cnum = ""; - } - - // Validate Birthday (you can add custom date validation logic) - if (formData.bdate.trim() === "") { - newFormErrors.bdate = "Birthday is required"; + // Validate User Type + if (formData.type.trim() === "") { + newFormErrors.type = "User type is required"; isValid = false; } else { - newFormErrors.bdate = ""; + newFormErrors.type = ""; } // Validate Username - const lrnPattern = /^\d{12}$/; if (formData.login_username.trim() === "") { newFormErrors.login_username = "Username is required"; isValid = false; - } else if ( - formData.type === "Student" && - !formData.login_username.trim().match(lrnPattern) - ) { - newFormErrors.login_username = "LRN must be a 12-digit LRN"; - isValid = false; } else { newFormErrors.login_username = ""; } - // Validate Password - const passwordPattern = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@#$%^&+=!_]).{8,}$/; - if ( - !formData.login_password.trim().match(passwordPattern) && - formData.login_password.length !== 0 && - formData.id - ) { - newFormErrors.login_password = - "Password must be left blank to leave unchanged or:\n- be at least 8 characters long\n- contain at least 1 alphabet and 1 numeric character\n- contain at least 1 special character (@#$%^&+=!_)"; - isValid = false; - } else if ( - !formData.login_password.trim().match(passwordPattern) && - !formData.id - ) { - newFormErrors.login_password = - "Password must be:\n- be at least 8 characters long\n- contain at least 1 alphabet and 1 numeric character\n- contain at least 1 special character (@#$%^&+=!_)"; - isValid = false; - } else { - newFormErrors.login_password = ""; - } - setFormErrors(newFormErrors); return isValid; }; @@ -191,16 +125,9 @@ const RegistrationForm = ({ setIsLoading, setLoadingText, setTabKey }) => { // Handle form submission here (e.g., send data to a server). const formatted = { fname: formData.fname, - mname: formData.mname, lname: formData.lname, - addr: formData.addr, - cnum: formData.cnum, - emailaddr: formData.emailaddr, - bdate: moment(new Date(formData.bdate)).toISOString(), type: formData.type, login_username: formData.login_username, - login_password: formData.login_password, - otp: formData.otp, }; customFetch(`${global.server_backend_url}/backend/auth/register`, { @@ -212,7 +139,7 @@ const RegistrationForm = ({ setIsLoading, setLoadingText, setTabKey }) => { if (response.ok) { setResponseHeader("Registration Successful"); setResponseBody( - "Please wait for the admin to approve your registration before you can sign in.", + "Registration successful! No need for admin to approve the registration. Feel free to login using your username.", ); resetToDefault(); setShowNotif(true); @@ -227,47 +154,11 @@ const RegistrationForm = ({ setIsLoading, setLoadingText, setTabKey }) => { } }; - // TODO Enhance security by sending access_token to register endpoint then verifying again if the email from field is similar from email fetched by access token from Google. - const handleGoogleLoginSuccess = (response) => { - setFormData({ - ...formData, - gaccesstoken: response.access_token, - }); - setIsLoading(true); - setLoadingText("Verifying your email..."); - - customFetch( - `${global.server_backend_url}/backend/auth/saveemailfromgoogle`, - { - headers: { Authorization: `Bearer ${response.access_token}` }, - }, - ) - .then((response) => { - if (response.ok) return response.json(); - else throw response; - }) - .then((data) => { - console.log("Data: ", data); - setFormData({ - ...formData, - emailaddr: data.email, - otp: data.verif, - }); - return data; - }) - .catch(async (err) => { - const errorBody = await err.json(); - setResponseHeader("Registration Failed"); - setResponseBody(errorBody.error); - setShowNotif(true); - }) - .finally(() => setIsLoading(false)); - }; return ( <> - + First Name { />
{formErrors.fname}
- - Middle Name - - - + Last Name {
{formErrors.lname}
- - Address - -
{formErrors.addr}
-
- - - Email - - - - - -
{formErrors.emailaddr}
- -
-
- - Phone Number - -
{formErrors.cnum}
-
-
- - Birthday - -
{formErrors.bdate}
-
- + User Type +

+ Each users has their own restrictions. For example, some Teacher + features don't show up to Student user types. +

{userTypes.map((userType) => ( { /> ))}
+
{formErrors.type}
- {`${ - formData.type === "Student" ? "LRN" : "Username" - }`} + Username { Password -
{formErrors.login_password}
+

+ This is a public version. Logging in is oversimplified to allow testing + of the application. No need to input a password. +

{ ...usersList.map((user) => { return { value: user, - label: `[${user.type}] ${user.lname}, ${user.fname} ${ - user.mname ? user.mname[0] + "." : "" - }`, + label: `[${user.type}] ${user.lname}, ${user.fname}`, }; }), ]); diff --git a/src-frontend-react/src/components/MedicalRecords/SelectedMedicalRecords/index.js b/src-frontend-react/src/components/MedicalRecords/SelectedMedicalRecords/index.js index efe864f..296442f 100644 --- a/src-frontend-react/src/components/MedicalRecords/SelectedMedicalRecords/index.js +++ b/src-frontend-react/src/components/MedicalRecords/SelectedMedicalRecords/index.js @@ -52,9 +52,7 @@ export const SelectedMedicalRecords = () => { ...usersList.map((user) => { return { value: user, - label: `[${user.type}] ${user.lname}, ${user.fname} ${ - user.mname ? user.mname[0] + "." : "" - }`, + label: `[${user.type}] ${user.lname}, ${user.fname}`, }; }), ]); diff --git a/src-frontend-react/src/components/PrintModal/index.js b/src-frontend-react/src/components/PrintModal/index.js index 8fc7cc5..8501cd1 100644 --- a/src-frontend-react/src/components/PrintModal/index.js +++ b/src-frontend-react/src/components/PrintModal/index.js @@ -98,8 +98,6 @@ export const PrintModal = ({ show, onClose, records }) => { {record.Users.map((user) => ( {`[${user.type}] ${user.lname}, ${ user.fname - } ${ - user.mname ? user.mname[0] + "." : "" }`} ))} @@ -147,8 +145,6 @@ export const PrintModal = ({ show, onClose, records }) => { {record.Users.map((user) => ( {`[${user.type}] ${user.lname}, ${ user.fname - } ${ - user.mname ? user.mname[0] + "." : "" }`} ))}