From 09f08480aad0ac774570336a11e63a0f2c0aa019 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 15 Jan 2021 11:33:37 +0100 Subject: login pagina werkt --- api/auth/login.py | 2 +- src/pages/login.tsx | 42 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/api/auth/login.py b/api/auth/login.py index 5326b6f..8eb0eea 100644 --- a/api/auth/login.py +++ b/api/auth/login.py @@ -1,4 +1,4 @@ -from flask import Blueprint, request +from flask import Blueprint, request, make_response from main import cursor import auth.token as token import passwords diff --git a/src/pages/login.tsx b/src/pages/login.tsx index 2c33bd7..bdaebc6 100644 --- a/src/pages/login.tsx +++ b/src/pages/login.tsx @@ -1,7 +1,43 @@ +import { v4 as uuidv4 } from 'uuid'; +import axios from 'axios'; + import { NavBar } from '../components/navbar'; import { CenteredPage } from '../components/page'; import { Vierkant, Input, Button } from '../components/ui'; +var ids = { + email: uuidv4(), + password: uuidv4() +} + +function submitLogin() { + var formData = { + email: (document.getElementById(ids.email) as HTMLInputElement).value, + password: (document.getElementById(ids.password) as HTMLInputElement).value + } + + if ( !formData.email || + !formData.password ) { + alert("Vul alsjeblieft alle velden in!"); + return; + } + + axios({ + method: "post", + url: `${window.location.origin}/api/auth/login`, + headers: {"content-type": "application/json"}, + data: formData + }) + .then(() => window.location.pathname = "/") + .catch(error => { + if (error.response.status === 401) { + alert("Verkeerde gebruikersnaam/wachtwoord combinatie!") + return; + } + alert("Er is iets fout gegaan!"); + }); +} + export default function LoginPage() { return (
@@ -15,8 +51,8 @@ export default function LoginPage() { textAlign: "center" }}> - - + +
- +
-- cgit v1.2.3