From 2e439cfc32ab8c7ad8ac790296ca10684c06e2ad Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Thu, 17 Mar 2022 22:26:36 -0500 Subject: [PATCH 1/2] saving imports on SmugFolio.js --- src/SmugFolio.js | 16 ++++++++++++++-- src/nav/NavBar.js | 6 ++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/SmugFolio.js b/src/SmugFolio.js index ad9a475..4ffa13d 100644 --- a/src/SmugFolio.js +++ b/src/SmugFolio.js @@ -1,4 +1,16 @@ - +import { Route } from "react-router-dom" +import { ApplicationViews } from "./ApplicationViews" +import { NavBar } from "./nav/NavBar" export const SmugFolio = () => { - + + if (localStorage.getItem("sf_token")) { + return( + <> + + + + + + ) + } } \ No newline at end of file diff --git a/src/nav/NavBar.js b/src/nav/NavBar.js index e69de29..7a71a34 100644 --- a/src/nav/NavBar.js +++ b/src/nav/NavBar.js @@ -0,0 +1,6 @@ +import react, {useState, useEffect} from "react" +import { useHistory } from "react-router-dom" + +export const NavBar = () => { + +} \ No newline at end of file -- 2.47.3 From 015a453e99fa73950c8613e028372bfb16bbffb9 Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Fri, 18 Mar 2022 11:44:25 -0500 Subject: [PATCH 2/2] saving completed login functionality --- src/SmugFolio.js | 16 +++++++- src/auth/Login.js | 5 +-- src/auth/Register.js | 91 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 4 deletions(-) diff --git a/src/SmugFolio.js b/src/SmugFolio.js index 4ffa13d..71caeae 100644 --- a/src/SmugFolio.js +++ b/src/SmugFolio.js @@ -1,6 +1,8 @@ -import { Route } from "react-router-dom" +import { Route, Redirect } from "react-router-dom" import { ApplicationViews } from "./ApplicationViews" import { NavBar } from "./nav/NavBar" +import { Login } from "./auth/Login" +import { Register } from "./auth/Register" export const SmugFolio = () => { if (localStorage.getItem("sf_token")) { @@ -12,5 +14,17 @@ export const SmugFolio = () => { ) + } else { + return <> + + + + + + + + + + } } \ No newline at end of file diff --git a/src/auth/Login.js b/src/auth/Login.js index 962ffc0..d577703 100644 --- a/src/auth/Login.js +++ b/src/auth/Login.js @@ -1,6 +1,5 @@ import React, { useRef } from "react" import { Link, useHistory } from "react-router-dom" -import "./Auth.css" export const Login = () => { @@ -46,8 +45,8 @@ export const Login = () => {

SmugFolio

Please sign in

- - + +
diff --git a/src/auth/Register.js b/src/auth/Register.js index e69de29..cb773bf 100644 --- a/src/auth/Register.js +++ b/src/auth/Register.js @@ -0,0 +1,91 @@ +import React, { useRef } from "react" +import { Link, useHistory } from "react-router-dom" + + +export const Register = () => { + const firstName = useRef() + const lastName = useRef() + const username = useRef() + const bio = useRef() + const password = useRef() + const verifyPassword = useRef() + const passwordDialog = useRef() + const history = useHistory() + + const handleRegister = (e) => { + e.preventDefault() + + if (password.current.value === verifyPassword.current.value) { + const newUser = { + "username": username.current.value, + "first_name": firstName.current.value, + "last_name": lastName.current.value, + "password": password.current.value + } + + return fetch("http://127.0.0.1:8000/register", { + method: "POST", + headers: { + "Content-Type": "application/json", + "Accept": "application/json" + }, + body: JSON.stringify(newUser) + }) + .then(res => res.json()) + .then(res => { + if ("token" in res) { + localStorage.setItem("sf_token", res.token) + history.push("/") + } + }) + } else { + passwordDialog.current.showModal() + } + } + + return ( +
+ + +
Passwords do not match
+ +
+ +
+

Register an account

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +