login and dashboard pages
This commit is contained in:
33
py_app/app/routes.py
Normal file
33
py_app/app/routes.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from flask import Blueprint, render_template, redirect, url_for, request, flash, session
|
||||
|
||||
bp = Blueprint('main', __name__)
|
||||
|
||||
# Dummy user data
|
||||
users = {"admin@home.com": "1234"}
|
||||
|
||||
@bp.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
if request.method == 'POST':
|
||||
email = request.form['email']
|
||||
password = request.form['password']
|
||||
if email in users and users[email] == password:
|
||||
session['user'] = email
|
||||
return redirect(url_for('main.dashboard'))
|
||||
else:
|
||||
flash('Invalid credentials. Please try again.')
|
||||
return render_template('login.html')
|
||||
|
||||
@bp.route('/dashboard')
|
||||
def dashboard():
|
||||
if 'user' not in session:
|
||||
return redirect(url_for('main.login'))
|
||||
return render_template('dashboard.html')
|
||||
|
||||
@bp.route('/logout')
|
||||
def logout():
|
||||
session.pop('user', None)
|
||||
return redirect(url_for('main.login'))
|
||||
|
||||
@bp.route('/settings')
|
||||
def settings():
|
||||
return render_template('settings.html')
|
||||
Reference in New Issue
Block a user