Changeset a26f6a1 for frontend


Ignore:
Timestamp:
08/09/22 16:09:32 (2 years ago)
Author:
Danilo <danilo.najkov@…>
Branches:
master
Children:
a569b7c
Parents:
899b19d
Message:

full auth flow

Location:
frontend/src
Files:
4 added
8 edited
1 moved

Legend:

Unmodified
Added
Removed
  • frontend/src/App.js

    r899b19d ra26f6a1  
    66import {Spin} from "antd";
    77import React, {useEffect, useState} from "react";
    8 import {Login, Register} from "./auth";
     8import {Login, Register} from "./Auth/auth";
    99import Dashboard from "./Dashboard";
    1010import Reservations from "./Dashboard/Reservations";
     
    1313import Menu from "./Dashboard/Menu";
    1414import Review from "./Dashboard/Review";
     15import Confirm from "./Auth/Confirm";
     16import SendConfirm from "./Auth/SendConfirm";
     17import SendReset from "./Auth/SendReset";
     18import Reset from "./Auth/Reset";
    1519
    1620
    1721function App() {
    1822  const [user, setUser] = useState(undefined)
    19   const [loading, setLoading] = useState(false)
     23  const [loading, setLoading] = useState(true)
    2024  useEffect(()=>{
    2125    getUser()
     
    2428  const getUser = () => {
    2529    setLoading(true)
    26     axios.get(env.api+'Users/authed',{headers:{Authorization:sessionStorage.getItem('Auth')}}).then(res=>{
    27       console.log(!res.data)
     30    axios.get(env.api+'Users/authed',{headers:{Authorization:localStorage.getItem('Auth')}}).then(res=>{
     31      console.log(res.data)
    2832      setUser(res.data)
    2933      setLoading(false)
     
    3236  const logout = () => {
    3337    setUser(undefined);
    34     sessionStorage.removeItem('Auth');
     38    localStorage.removeItem('Auth');
    3539    window.location.replace('/')
    3640  }
     
    4852            <Route path="/login" element={loading ? <Spin /> :  !user ? <Login setUser={setUser}/> :  <Navigate to="/dashboard" replace={true} />}/>
    4953            <Route path="/register" element={loading ? <Spin /> :  !user ? <Register setUser={setUser}/> :  <Navigate to="/dashboard" replace={true} />}/>
     54            <Route path="/reset-password" element={loading ? <Spin /> : <SendReset/>}/>
     55            <Route path="/reset" element={loading ? <Spin /> : <Reset/>}/>
     56            <Route path="/confirm" element={loading ? <Spin /> : <Confirm setUser={setUser} user={user}/>}/>
     57            <Route path="/confirm-email" element={loading ? <Spin /> : <SendConfirm setUser={setUser} user={user}/>}/>
    5058            <Route path="/" element={<FrontPage user={user} logout={logout}/>}/>
    5159          </Routes>
  • frontend/src/Auth/auth.js

    r899b19d ra26f6a1  
    44import { UserOutlined, LockOutlined } from '@ant-design/icons';
    55import axios from "axios";
    6 import './App.css'
    7 import env from "./env";
     6import '../App.css'
     7import env from "../env";
    88
    99const setAuthCookie = (token) => {
    10     sessionStorage.setItem('Auth','Bearer '+token)
     10    localStorage.setItem('Auth','Bearer '+token)
    1111}
    1212
     
    103103            setUser(res.data)
    104104            setLoading(false)
    105             history(res.data.isAdmin ? '/dashboard' : '/')
     105            history('/confirm-email')
    106106        })
    107107    }
  • frontend/src/Dashboard.js

    r899b19d ra26f6a1  
    1111    const history = useNavigate()
    1212    const logout = () => {
    13         sessionStorage.removeItem('Auth');
     13        localStorage.removeItem('Auth');
    1414        setUser(false)
    1515    }
  • frontend/src/Dashboard/Menu.js

    r899b19d ra26f6a1  
    2525    const addMenu = (data) => {
    2626        setLoadingSave(true);
    27         axios.post(env.api + 'Menu/',{...data,price: parseInt(data.price)}, { headers: {Authorization: sessionStorage.getItem('Auth')}
     27        axios.post(env.api + 'Menu/',{...data,price: parseInt(data.price)}, { headers: {Authorization: localStorage.getItem('Auth')}
    2828        }).then(res => {
    2929            notification['success']({
     
    4242
    4343    const deleteMenu = (id) => {
    44         axios.delete(env.api + 'Menu/'+id, {headers: {Authorization: sessionStorage.getItem('Auth')}
     44        axios.delete(env.api + 'Menu/'+id, {headers: {Authorization: localStorage.getItem('Auth')}
    4545        }).then(res => {
    4646            notification['success']({
  • frontend/src/Dashboard/Reservations.js

    r899b19d ra26f6a1  
    2626                    from: date[0].format('YYYY-MM-DDThh:mm:ss') + 'Z',
    2727                    to: date[1].format('YYYY-MM-DDThh:mm:ss') + 'Z'
    28                 }, headers: {Authorization: sessionStorage.getItem('Auth')}
     28                }, headers: {Authorization: localStorage.getItem('Auth')}
    2929            }).then(res => {
    3030                axios.get(env.api + 'Reservations/new', {
    31                      headers: {Authorization: sessionStorage.getItem('Auth')}
     31                     headers: {Authorization: localStorage.getItem('Auth')}
    3232                }).then(newres=>{
    3333                    setNewReservations(newres.data);
     
    5454            params: {
    5555                status: newStatus
    56             }, headers: {Authorization: sessionStorage.getItem('Auth')}
     56            }, headers: {Authorization: localStorage.getItem('Auth')}
    5757        }).then(res => {
    5858            getReservations()
     
    6868            params: {
    6969                tableId: ev.target.value == '' ? 0 : ev.target.value
    70             }, headers: {Authorization: sessionStorage.getItem('Auth')}
     70            }, headers: {Authorization: localStorage.getItem('Auth')}
    7171        }).then(res => {
    7272            console.log("success");
  • frontend/src/Dashboard/Restaurant.js

    r899b19d ra26f6a1  
    3737    const submitEdit = (form) => {
    3838        setLoadingSave(true);
    39         axios.put(env.api + 'Restaurants/',{...form}, { headers: {Authorization: sessionStorage.getItem('Auth')}
     39        axios.put(env.api + 'Restaurants/',{...form}, { headers: {Authorization: localStorage.getItem('Auth')}
    4040        }).then(res => {
    4141            notification['success']({
  • frontend/src/Dashboard/Review.js

    r899b19d ra26f6a1  
    11import React, {useEffect, useState} from 'react'
    2 import {Button, Card, Input, List, Rate, Spin, Tooltip} from "antd";
     2import {Button, Card, Input, List, notification, Rate, Spin, Tooltip} from "antd";
    33import axios from "axios";
    44import env from "../env";
     
    1212        setLoading(true);
    1313        getRestaurant()
     14        console.log(props.user)
    1415    },[])
    1516    useEffect(()=> {
     
    3637                {props.front ?
    3738                    (props.user?
    38                         <Button style={{float:'right'}} type={'primary'} onClick={()=>props.setVisible(true)}>Внеси оценка</Button>
     39                        <Button style={{float:'right'}} type={'primary'} onClick={()=>props.user.isConfirmed ? props.setVisible(true) : notification['error']({message: <p>Мора да го потврдите вашиот мејл за да оставите оценка. <a href={'/confirm-email'}>Потврдете го тука</a></p>})}>Внеси оценка</Button>
    3940                        : <Tooltip title={'Мора да се најавите за да оставите оценка'}><Button style={{float:'right'}} disabled type={'primary'} onClick={()=>props.setVisible(true)}>Внеси оценка</Button></Tooltip>)
    4041                    : ''
  • frontend/src/FrontPage.js

    r899b19d ra26f6a1  
    11import React, {useState, useEffect} from 'react'
    22import {Header} from "./Header";
    3 import {useNavigate} from "react-router-dom";
     3import {Link, useNavigate} from "react-router-dom";
    44import {Button, Card, DatePicker, Form, Image, Input, Modal, notification, Rate, Spin} from "antd";
    55import placeholderImage from '../src/Assets/placeholder.png'
     
    2626    },[])
    2727
     28    useEffect(()=>{
     29        if(user && !user.isConfirmed) {
     30            notification['warning']({
     31                message: <p>Вашиот емаил не е потврден. <a href={'/confirm-email'}>Потврдете го тука</a></p>
     32            });
     33        }
     34    },[user])
     35
    2836    const saveNewReview = data =>{
    2937        setSaveModalLoading(true)
    30         axios.post(env.api + 'Reviews',data,{ headers: {Authorization: sessionStorage.getItem('Auth')}}).then(res=>{
     38        axios.post(env.api + 'Reviews',data,{ headers: {Authorization: localStorage.getItem('Auth')}}).then(res=>{
    3139            setNewReviewModal(false)
    3240            setSaveModalLoading(false)
  • frontend/src/index.js

    r899b19d ra26f6a1  
    66const root = ReactDOM.createRoot(document.getElementById('root'));
    77root.render(
    8   <React.StrictMode>
    98    <App />
    10   </React.StrictMode>
    119);
Note: See TracChangeset for help on using the changeset viewer.