Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a31404
commit 4426a51
Showing
14 changed files
with
304 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from ..db_class.db import User | ||
from flask import Blueprint, render_template, redirect, url_for, request, flash | ||
from .form import LoginForm | ||
from flask_login import ( | ||
login_required, | ||
login_user, | ||
logout_user, | ||
current_user | ||
) | ||
from ..utils.utils import admin_password | ||
from ..db_class.db import User | ||
from .. import db | ||
|
||
account_blueprint = Blueprint( | ||
'account', | ||
__name__, | ||
template_folder='templates', | ||
static_folder='static' | ||
) | ||
|
||
@account_blueprint.route('/login', methods=['GET', 'POST']) | ||
def login(): | ||
"""Log in an existing user.""" | ||
form = LoginForm() | ||
if form.validate_on_submit(): | ||
if form.password.data == str(admin_password()): | ||
user = User(email="admin@admin.admin") | ||
db.session.add(user) | ||
db.session.commit() | ||
login_user(user, form.remember_me.data) | ||
flash('You are now logged in. Welcome back!', 'success') | ||
return redirect(request.args.get('next') or "/") | ||
else: | ||
flash('Invalid password.', 'error') | ||
return render_template('account/login.html', form=form) | ||
|
||
@account_blueprint.route('/logout') | ||
@login_required | ||
def logout(): | ||
User.query.filter_by(id=current_user.id).delete() | ||
logout_user() | ||
|
||
flash('You have been logged out.', 'info') | ||
return redirect(url_for('home.home')) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from flask_wtf import FlaskForm | ||
from wtforms.fields import ( | ||
BooleanField, | ||
PasswordField, | ||
SubmitField | ||
) | ||
from wtforms.validators import InputRequired | ||
|
||
|
||
class LoginForm(FlaskForm): | ||
password = PasswordField('Password', validators=[InputRequired()]) | ||
remember_me = BooleanField('Keep me logged in') | ||
submit = SubmitField('Log in') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.