Added very simple register backend and frontend

This commit is contained in:
cami 2021-06-23 01:26:55 +02:00
parent 5d94eafaa9
commit c7d4b0c262
2 changed files with 45 additions and 3 deletions

View file

@ -132,6 +132,22 @@ def protected():
-H "Authorization: Bearer <your_token>" -H "Authorization: Bearer <your_token>"
""" """
return {'message': f'protected endpoint (allowed user {flask_praetorian.current_user().username})'} return {'message': f'protected endpoint (allowed user {flask_praetorian.current_user().username})'}
@app.route('/api/register', methods=['POST'])
def register():
req = flask.request.get_json(force=True)
username = req.get('username', None)
password = req.get('password', None)
new_user = User(
username=username,
password=guard.hash_password(password)
)
db.session.add(new_user)
db.session.commit()
ret = {'message': 'Account erstellt für den Account {}'.format(
new_user.username
)}
return ret, 200
@app.route('/time') @app.route('/time')
def get_current_time(): def get_current_time():

View file

@ -1,28 +1,54 @@
import React from "react"; import React from "react";
import { useState } from "react/cjs/react.development";
import "../../App.css"; import "../../App.css";
import Footer from "../../Footer"; import Footer from "../../Footer";
import InputField from "../InputField"; import InputField from "../InputField";
import SubmitField from "../SubmitField"; import SubmitField from "../SubmitField";
export default function Login() { export default function Login() {
const [username, setUsername] = useState('')
const [password, setPassword] = useState('')
const onSubmitClick = (e) => {
e.preventDefault();
let opts = {
username: username,
password: password,
};
console.log(opts);
fetch("/api/register", {
method: "post",
body: JSON.stringify(opts),
})
};
const handleUsernameChange = (e) => {
setUsername(e.target.value);
};
const handlePasswordChange = (e) => {
setPassword(e.target.value);
};
return ( return (
<> <>
<div className="sitePage"> <div className="sitePage">
<h1>Registrierung</h1> <h1>Registrierung</h1>
<p>Herzlich willkommen bei meiner Bachelorarbeit. Du kannst dich hier einfach registrieren, sodass du mir ein positives Feedback hinterlassen kannst. Bei der ersten Registrierung geht es darum, dass ich ein paar Sachen über dich kennenlerne. Ich werde diese Fragen strikt trennen mit der eigentlichen Fragestellung. Diese Fragen dienen mir dazu, dass ich einschätzen kann, welche Leute ich befragt habe.</p>
<form> <form>
<InputField <InputField
LabelName="Benutzername / Kennung" LabelName="Benutzername / Kennung"
InputType="" InputType="text"
onChange={handleUsernameChange}
InputName="username" InputName="username"
/> />
<InputField <InputField
LabelName="Passwort" LabelName="Passwort"
InputType="password" InputType="password"
onChange={handlePasswordChange}
InputName="password" InputName="password"
/> />
<br /> <br />
<SubmitField LabelName="Einloggen" /> <SubmitField onClick={onSubmitClick} LabelName="Einloggen" />
</form> </form>
</div> </div>
<Footer /> <Footer />