Commit 06058953 authored by Kacprzak, Izabella's avatar Kacprzak, Izabella
Browse files

Enabled redirect to dashboard on logout, made My Profile display a personalized profile [BG, IK]

parent 89f2aea0
Pipeline #202623 passed with stage
in 47 seconds
......@@ -100,9 +100,9 @@ def user_login():
username, password = (request.json['username'], request.json['password'])
user = User.query.get(username)
if user == None:
return jsonify(token = "False")
return jsonify(token = "")
if bcrypt.checkpw(password.encode('utf-8'), user.password.encode('utf-8')):
return jsonify(token = "True")
return jsonify(token = username)
else:
return jsonify(token = "False")
\ No newline at end of file
return jsonify(token = "")
\ No newline at end of file
......@@ -19,11 +19,10 @@ import Login from './Login'
import useToken from './useToken';
function App() {
const { token, setToken } = useToken();
const title = "Dashboard"
const { token, setToken } = useToken();
if(token != "True") {
if(!token) {
return <Login setToken={setToken} />
}
......
import { useState } from 'react';
import { useHistory } from "react-router-dom"
import PropTypes from 'prop-types';
async function loginUser(credentials) {
......@@ -17,21 +16,21 @@ export default function Login({ setToken }) {
const [username, setUserName] = useState();
const [password, setPassword] = useState();
const history = useHistory()
const handleSubmit = async e => {
e.preventDefault();
const token = await loginUser({
username,
password
});
setToken(token);
if(token.token != "") {
setToken(token);
}
}
return (
<div className="login">
<h2> Sign In </h2>
<h1> InAGlobe Platform </h1>
<form onSubmit={handleSubmit}>
<input type="text" id="login" class="fadeIn second" name="login" placeholder="login"
onChange={e => setUserName(e.target.value)}/>
......
import { useHistory, useParams } from 'react-router';
import useFetch from './useFetch'
import useToken from './useToken';
const MyProfile = () => {
const {username} = useParams();
const history = useHistory();
const {setToken, token} = useToken();
const {data: user, error, isPending} = useFetch("/users/john34")
const {data: user, error, isPending} = useFetch("/users/" + token)
return (
<div className="my-profile">
{ isPending && <h2>Loading...</h2> }
{ user && <h2>{user.firstname + " " + user.surname}</h2> }
{ user && <h1>{"Username: " + user.username}</h1> }
{ user && <h1>{"Username: " + user.token}</h1> }
{ user && <h1>{"Title: " + user.title}</h1> }
{ user && <h1>{"Email: " + user.email}</h1> }
{ user && <h1>{"Bio: " + user.bio}</h1> }
......@@ -24,8 +24,5 @@ const MyProfile = () => {
</div>
);
}
export default MyProfile;
export default MyProfile;
\ No newline at end of file
import { Link } from 'react-router-dom'
import useToken from './useToken';
const Navbar = () => {
const {setToken, token} = useToken();
return (
<nav className="navbar" >
<a href="/" style={{
......@@ -10,7 +13,7 @@ const Navbar = () => {
}}>InAGlobe Platform</a>
<div className="links">
<Link to={`/create-project`}>New Project</Link>
<Link to={`/users/john34`}>My Profile</Link>
<Link to={`/users/` + token}>My Profile</Link>
</div>
</nav>
);
......
import React from 'react';
import { slide as Menu } from 'react-burger-menu';
import { Link } from 'react-router-dom'
import { Link, useHistory } from 'react-router-dom'
const Sidebar = () => {
const slackLink = "https://slack.com/intl/en-gb/"
export default props => {
return (
const history = useHistory();
const handleSignOut = e => {
e.preventDefault()
localStorage.clear();
window.location.reload();
history.push("/");
}
return (
<Menu>
<div className="menu-item" >
<Link to={`/`}>Home</Link>
......@@ -22,7 +34,13 @@ export default props => {
<div className="menu-item" >
<a href={slackLink} target="_blank">Go To Slack</a>
</div>
<div className="menu-item" >
<button style={{textDecoration: "underline", cursor: "pointer"}} onClick={handleSignOut}>Log Out</button>
</div>
</Menu>
);
};
\ No newline at end of file
);
}
export default Sidebar;
\ No newline at end of file
......@@ -306,7 +306,6 @@ Note: Beware of modifying this element as it can break the animations - you shou
/* General sidebar styles */
.bm-menu {
background: #373a47;
padding: 2.5em 1.5em 0;
font-size: 1.15em;
}
......@@ -512,6 +511,22 @@ Note: Beware of modifying this element as it can break the animations - you shou
margin-right: 10px;
}
/* Login Page */
.login {
text-align: center;
}
.login h1 {
color: #f1356d;
margin-bottom: 10px;
}
.login input {
padding: 6px 10px;
margin: 10px 0;
border: 1px solid #ddd;
box-sizing: border-box;
display: block;
align-items: center;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment