Skip to content

Commit

Permalink
create auth package and update template files
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoWzk committed Feb 17, 2019
1 parent b53df7a commit 110be76
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 75 deletions.
156 changes: 89 additions & 67 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ def create_app(config_name):
from .main import main as main_blueprint
app.register_blueprint(main_blueprint)

from .auth import auth as auth_blueprint
app.register_blueprint(auth_blueprint, url_prefix='/auth')
return app
Binary file modified app/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
6 changes: 6 additions & 0 deletions app/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# encoding: utf-8
# create authentication blueprint here

from flask import Blueprint
auth = Blueprint('auth', __name__)
from . import views
Binary file added app/auth/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added app/auth/__pycache__/views.cpython-35.pyc
Binary file not shown.
22 changes: 22 additions & 0 deletions app/auth/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# encoding: utf-8
# define routes for authenticated url

from flask import render_template, redirect, url_for, flash
from app.forms import loginForm
from ..models import User
from flask_login import login_required, login_user, logout_user
from ..auth import auth

@auth.route('/login')
def sign_in():
form = loginForm()
if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data).first()
if user and user.verify_pass(form.password.data):
return redirect(url_for('auth.dashboard'))
else:
flash('Invalid credentials')
return render_template('auth/login.html', form=form)
return render_template('auth/login.html', form=form)


9 changes: 9 additions & 0 deletions app/templates/auth/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends 'base.html' %}
{% import 'macro/wtf.html' as wtf %}
{% block main %}
<div class="signup-form">
<div class="container">
{{ wtf.loginForm(form) }}
</div>
</div>
{% endblock %}
3 changes: 3 additions & 0 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<li class="nav-item">
<a class="nav-link" href="{{ url_for('main.user_register') }}">REGISTER</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('auth.sign_in') }}">LOGIN</a>
</li>
</ul>
<form class="form-inline mt-2 mt-md-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
Expand Down
16 changes: 8 additions & 8 deletions app/templates/macro/wtf.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
</form>
{% endmacro %}

{#{% macro loginForm(form) %}#}
{# <form action="{{ url_for('auth.login') }}", method='POST'>#}
{# {{ form.hidden_tag() }}#}
{# {{ form.email() }}#}
{# {{ form.password() }}#}
{# {{ form.submit() }}#}
{# </form>#}
{#{% endmacro %}#}
{% macro loginForm(form) %}
<form action="{{ url_for('auth.sign_in') }}", method='POST'>
{{ form.hidden_tag() }}
{{ form.email(class='form-control', placeholder='Your registered email') }}
{{ form.password(class='form-control', placeholder='Password') }}
{{ form.submit(class='btn btn-primary btn-block') }}
</form>
{% endmacro %}

0 comments on commit 110be76

Please sign in to comment.