Skip to content

Commit

Permalink
fixed dashboard2 model update if user exits page
Browse files Browse the repository at this point in the history
  • Loading branch information
Jai0212 committed Nov 21, 2024
1 parent d10f910 commit 1a110a3
Show file tree
Hide file tree
Showing 46 changed files with 121 additions and 77 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ frontend/.env
backend/NodeJS/node_modules
backend/__pycache__
backend/app/__pycache__
backend/controllers/__pycache__
backend/app/controllers/__pycache__
backend/__pycache__
backend/app/__pycache__

# Frontend
# Logs
Expand Down
Binary file removed backend/__pycache__/main.cpython-311.pyc
Binary file not shown.
Binary file removed backend/__pycache__/main.cpython-312.pyc
Binary file not shown.
Binary file removed backend/app/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed backend/app/entities/__pycache__/user.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed backend/ml_model/__pycache__/model.cpython-311.pyc
Binary file not shown.
Binary file removed backend/ml_model/__pycache__/model.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified backend/ml_model/model_with_score.pkl
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 0 additions & 4 deletions backend/vercel.json

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/src/Components/UserNavbar/UserNavbar.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Link } from "react-router-dom";
import { useNavigate } from "react-router-dom";
import axios from "axios"; // You will need to install axios for making API requests
import axios from "axios";
import "./UserNavbar.css";

function UserNavbar() {
Expand Down
1 change: 0 additions & 1 deletion frontend/src/pages/ChangePassword/ChangePassword.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useForm } from "react-hook-form";
import { ErrorMessage } from '@hookform/error-message';
import swal from 'sweetalert2';
import { useState } from 'react';

const ChangePassword = () => {
const VITE_BACKEND_URL = import.meta.env.VITE_BACKEND_URL;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/ModelTester/Dashboard2/Dashboard2.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useRef } from "react";
import React, { useState, useEffect } from "react";
import ChartComponent2 from "../ChartComponenet2/ChartComponent2.jsx";
import ControlButton2 from "../ControlButtons2/ControlButtons2.jsx";
import "./Dashboard2.css";
Expand Down
155 changes: 90 additions & 65 deletions frontend/src/pages/UserLogin/UserLogin.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
import { useState } from "react";
import React, { useEffect } from "react";
import { useForm } from "react-hook-form";
import { ErrorMessage } from "@hookform/error-message";
import swal from "sweetalert2";
import { useNavigate } from "react-router-dom";
import "./UserLogin.css";
import axios from "axios";

const UserLogin = () => {
const navigate = useNavigate();
const VITE_BACKEND_URL = import.meta.env.VITE_BACKEND_URL;

useEffect(() => {
const uploadedFiles = localStorage.getItem("uploadedFiles");

if (uploadedFiles && uploadedFiles.length > 0) {
handleLogout();
}

localStorage.removeItem("uploadedFiles");
}, []);

const handleLogout = async () => {
try {
const response = await axios.post(`${VITE_BACKEND_URL}/logout`);

if (response.data.error === false) {
navigate("/");
} else {
console.error("Logout failed:", response.data.message);
}
} catch (error) {
console.error("Error during logout:", error);
}
};

const {
register,
handleSubmit,
Expand All @@ -27,78 +52,78 @@ const UserLogin = () => {
},
body: JSON.stringify(data),
})
.then((res) => res.json())
.then((res) => {
console.log(res.data);
if (res.error === true) {
swal.fire({
icon: "error",
.then((res) => res.json())
.then((res) => {
console.log(res.data);
if (res.error === true) {
swal.fire({
icon: "error",
title: res.message,
});
} else {
document.getElementById("form").reset();
swal
.fire({
icon: "success",
title: res.message,
timer: 1500,
})
.then(() => {
console.log("Login successful");
navigate("/dashboard");
});
} else {
document.getElementById("form").reset();
swal
.fire({
icon: "success",
title: res.message,
timer: 1500,
})
.then(() => {
console.log("Login successful");
navigate("/dashboard");
});
}
})
.catch((e) => {
console.log(e);
});
}
})
.catch((e) => {
console.log(e);
});
};

return (
<>
<div className="container">
<h1>User Login</h1>
</div>
<>
<div className="container">
<h1>User Login</h1>
</div>

<hr />
<div className="alert alert-primary">
<form onSubmit={handleSubmit(handleForm)} id={"form"}>
<div className="mb-3">
<label htmlFor="email">Email</label>
<input
{...register("email", { required: "This field is required" })}
type="email"
className={"form-control"}
/>
<ErrorMessage
errors={errors}
name="email"
render={({ message }) => (
<p className={"text-danger"}>{message}</p>
)}
/>
</div>
<hr />
<div className="alert alert-primary">
<form onSubmit={handleSubmit(handleForm)} id={"form"}>
<div className="mb-3">
<label htmlFor="email">Email</label>
<input
{...register("email", { required: "This field is required" })}
type="email"
className={"form-control"}
/>
<ErrorMessage
errors={errors}
name="email"
render={({ message }) => (
<p className={"text-danger"}>{message}</p>
)}
/>
</div>

<div className="mb-3">
<label htmlFor="password">Password</label>
<input
{...register("password", { required: "This field is required" })}
type="password"
className={"form-control"}
/>
<ErrorMessage
errors={errors}
name="password"
render={({ message }) => (
<p className={"text-danger"}>{message}</p>
)}
/>
</div>
<div className="mb-3">
<label htmlFor="password">Password</label>
<input
{...register("password", { required: "This field is required" })}
type="password"
className={"form-control"}
/>
<ErrorMessage
errors={errors}
name="password"
render={({ message }) => (
<p className={"text-danger"}>{message}</p>
)}
/>
</div>

<button className={"btn btn-primary"}>Login</button>
</form>
</div>
</>
<button className={"btn btn-primary"}>Login</button>
</form>
</div>
</>
);
};

Expand Down
26 changes: 26 additions & 0 deletions frontend/src/pages/UserSignup/UserSignup.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
import React, { useEffect } from "react";
import { useForm } from "react-hook-form";
import { ErrorMessage } from "@hookform/error-message";
import swal from "sweetalert2";
import { useNavigate } from "react-router-dom";
import "bootstrap/dist/css/bootstrap.min.css";
import "./UserSignup.css";
import axios from "axios";

const UserSignup = () => {
const VITE_BACKEND_URL = import.meta.env.VITE_BACKEND_URL;

const navigate = useNavigate();

useEffect(() => {
const uploadedFiles = localStorage.getItem("uploadedFiles");

if (uploadedFiles && uploadedFiles.length > 0) {
handleLogout();
}

localStorage.removeItem("uploadedFiles");
}, []);

const handleLogout = async () => {
try {
const response = await axios.post(`${VITE_BACKEND_URL}/logout`);

if (response.data.error === false) {
navigate("/");
} else {
console.error("Logout failed:", response.data.message);
}
} catch (error) {
console.error("Error during logout:", error);
}
};

const {
register,
handleSubmit,
Expand Down
4 changes: 0 additions & 4 deletions test_example.py

This file was deleted.

0 comments on commit 1a110a3

Please sign in to comment.