Refactor/Formattingandstuff #60

Merged
cami merged 1 commit from refactor/formattingAndStuff into main 2021-06-26 22:31:14 +00:00
2 changed files with 16 additions and 18 deletions

View file

@ -75,10 +75,10 @@ with app.app_context():
db.create_all() db.create_all()
if db.session.query(User).filter_by(username='Yasoob').count() < 1: if db.session.query(User).filter_by(username='Yasoob').count() < 1:
db.session.add(User( db.session.add(User(
username='Yasoob', username='Yasoob',
password=guard.hash_password('strongpassword'), password=guard.hash_password('strongpassword'),
roles='admin' roles='admin'
)) ))
db.session.commit() db.session.commit()
@ -87,7 +87,7 @@ with app.app_context():
def home(): def home():
return {"Hello": "World"}, 200 return {"Hello": "World"}, 200
@app.route('/api/login', methods=['POST']) @app.route('/api/login', methods=['POST'])
def login(): def login():
""" """
@ -104,7 +104,7 @@ def login():
ret = {'access_token': guard.encode_jwt_token(user)} ret = {'access_token': guard.encode_jwt_token(user)}
return ret, 200 return ret, 200
@app.route('/api/refresh', methods=['POST']) @app.route('/api/refresh', methods=['POST'])
def refresh(): def refresh():
""" """
@ -119,8 +119,8 @@ def refresh():
new_token = guard.refresh_jwt_token(old_token) new_token = guard.refresh_jwt_token(old_token)
ret = {'access_token': new_token} ret = {'access_token': new_token}
return ret, 200 return ret, 200
@app.route('/api/protected') @app.route('/api/protected')
@flask_praetorian.auth_required @flask_praetorian.auth_required
def protected(): def protected():
@ -133,7 +133,8 @@ def protected():
""" """
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'])
@app.route('/api/register', methods=['POST'])
def register(): def register():
req = flask.request.get_json(force=True) req = flask.request.get_json(force=True)
username = req.get('username', None) username = req.get('username', None)

View file

@ -19,28 +19,25 @@ function Navbar() {
} }
}; };
const isLoggedIn = useAuth();
/* Shows the button after resizing the screen */ /* Shows the button after resizing the screen */
useEffect(() => { useEffect(() => {
showButton(); showButton();
}, []); }, []);
window.addEventListener("resize", showButton); window.addEventListener("resize", showButton);
return ( return (
<> <>
{" "}
<nav className="navbar"> <nav className="navbar">
{" "}
<div className="navbar-container"> <div className="navbar-container">
{" "}
<Link to="/" className="navbar-logo" onClick={closeMobileMenu}> <Link to="/" className="navbar-logo" onClick={closeMobileMenu}>
{" "}
Bachelorarbeit Marco Camenzind{" "} Bachelorarbeit Marco Camenzind{" "}
</Link>{" "} </Link>
<div className="menu-icon" onClick={handleClick}> <div className="menu-icon" onClick={handleClick}>
{" "} <i className={click ? "fas fa-times" : "fas fa-bars"} />
<i className={click ? "fas fa-times" : "fas fa-bars"} />{" "} </div>
</div>{" "}
<ul className={click ? "nav-menu active" : "nav-menu"}> <ul className={click ? "nav-menu active" : "nav-menu"}>
{" "}
<li className="nav-item"> <li className="nav-item">
<Link to="/" className="nav-links" onClick={closeMobileMenu}> <Link to="/" className="nav-links" onClick={closeMobileMenu}>
Startseite Startseite