More files
This commit is contained in:
@ -4,9 +4,9 @@ from werkzeug.security import check_password_hash
|
||||
from app import db
|
||||
from .models import User
|
||||
|
||||
auth = Blueprint('auth', __name__)
|
||||
bp = Blueprint('auth', __name__, template_folder='templates')
|
||||
|
||||
@auth.route('/auth/login', methods=['GET', 'POST'])
|
||||
@bp.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
if request.method == 'POST':
|
||||
email = request.form['email']
|
||||
@ -15,14 +15,33 @@ def login():
|
||||
if user and check_password_hash(user.password_hash, password):
|
||||
login_user(user)
|
||||
flash('Logged in successfully.', 'success')
|
||||
return redirect(url_for('core.user_dashboard'))
|
||||
return redirect(url_for('core_ui.home'))
|
||||
else:
|
||||
flash('Invalid credentials.', 'danger')
|
||||
return render_template('login.html')
|
||||
return render_template('auth/login.html')
|
||||
|
||||
@auth.route('/auth/logout')
|
||||
@bp.route('/logout')
|
||||
@login_required
|
||||
def logout():
|
||||
logout_user()
|
||||
flash('Logged out.', 'info')
|
||||
return redirect(url_for('core.index'))
|
||||
return redirect(url_for('core_ui.home'))
|
||||
|
||||
@bp.route('/register', methods=['GET', 'POST'])
|
||||
def register():
|
||||
if request.method == 'POST':
|
||||
email = request.form['email']
|
||||
password = request.form['password']
|
||||
|
||||
existing_user = User.query.filter_by(email=email).first()
|
||||
if existing_user:
|
||||
flash('Email already registered.', 'warning')
|
||||
else:
|
||||
user = User(email=email)
|
||||
user.set_password(password)
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
flash('Account created. You can now log in.', 'success')
|
||||
return redirect(url_for('auth.login'))
|
||||
|
||||
return render_template('auth/register.html')
|
||||
|
Reference in New Issue
Block a user