Skip to content
This repository was archived by the owner on Oct 1, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions controllers/authentication.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const PASSWORD = process.env.PASSWORD;

exports.validatePassword = (req, res) => {
const { password } = req.body;
if (password === PASSWORD) {
res.status(200).json({ success: true });
} else {
res.status(401).json({ success: false });
}
};
14 changes: 10 additions & 4 deletions frontend/src/screen/Home/AdminLogin.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import React, { useState } from "react";
import users from "../../data/users.json";
import dotenv from "dotenv";
import axios from "axios";

import "./AdminLogin.scss";

const AdminLogin = ({ closeHandler, showAlert }) => {
const [adminPassword, setAdminPassword] = useState("");
dotenv.config();
const validateAdminPasswordInput = () => {
if (adminPassword.trim() === process.env.REACT_APP_Password) {

const validateAdminPasswordInput = async () => {
const {
data: { success },
} = await axios.post("/api/v1/authentication/login", {
password: adminPassword.trim(),
});

if (success) {
closeHandler();
showAlert("success", "The security code has been verified successfully.");
setTimeout(() => {
Expand Down
7 changes: 7 additions & 0 deletions routes/authentication.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const express = require("express");
const router = express.Router();
const { validatePassword } = require("../controllers/authentication");

router.route("/login").post(validatePassword);

module.exports = router;
3 changes: 2 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ app.use(express.json());

app.use("/api/v1/classes", require("./routes/classes"));
app.use("/api/v1/bookings", require("./routes/bookings"));
app.use("/api/v1/courses", require("./routes/courseCalendar"));
app.use("/api/v1/courses", require("./routes/courseCalendar"));
app.use("/api/v1/authentication", require("./routes/authentication"));

if (process.env.NODE_ENV === "production") {
app.use(express.static("frontend/build"));
Expand Down