Commit b5833775 authored by Petrus J.v.Rensburg's avatar Petrus J.v.Rensburg

Add new 'auth' example, using Flask-Security.

parent 15581d05
This diff is collapsed.
# Create dummy secrey key so we can use sessions
SECRET_KEY = '123456790'
# Create in-memory database
DATABASE_FILE = 'sample_db.sqlite'
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + DATABASE_FILE
SQLALCHEMY_ECHO = True
# Flask-Security config
SECURITY_URL_PREFIX = "/admin"
SECURITY_PASSWORD_HASH = "pbkdf2_sha512"
SECURITY_PASSWORD_SALT = "ATGUOHAELKiubahiughaerGOJAEGj"
# Flask-Security URLs, overridden because they don't put a / at the end
SECURITY_LOGIN_URL = "/login/"
SECURITY_LOGOUT_URL = "/logout/"
SECURITY_REGISTER_URL = "/register/"
SECURITY_POST_LOGIN_VIEW = "/admin/"
SECURITY_POST_LOGOUT_VIEW = "/admin/"
SECURITY_POST_REGISTER_VIEW = "/admin/"
# Flask-Security features
SECURITY_REGISTERABLE = True
SECURITY_SEND_REGISTER_EMAIL = False
\ No newline at end of file
Flask Flask
Flask-Admin Flask-Admin
Flask-SQLAlchemy Flask-SQLAlchemy
Flask-Login Flask-Security==1.7.4
\ No newline at end of file
...@@ -3,37 +3,27 @@ ...@@ -3,37 +3,27 @@
{{ super() }} {{ super() }}
<div class="row-fluid"> <div class="row-fluid">
<div> <div>
{% if current_user.is_authenticated() %} <h1>Flask-Admin example</h1>
<h1>Flask-Admin example</h1> <p class="lead">
<p class="lead"> Authentication
Authentication </p>
</p> <p>
<p> This example shows how you can use Flask-Security for authentication.
This example shows how you can use Flask-Login for authentication. It is only intended as a basic demonstration. </p>
</p> {% if not current_user.is_authenticated() %}
{% else %} <p>You can register as a regular user, or log in as a superuser with the following credentials:
<form method="POST" action=""> <ul>
{{ form.hidden_tag() if form.hidden_tag }} <li>email: <b>admin</b></li>
{% for f in form if f.type != 'CSRFTokenField' %} <li>password: <b>admin</b></li>
<div> </ul>
{{ f.label }} </p>
{{ f }} <p>
{% if f.errors %} <a class="btn btn-default" href="{{ url_for('security.login') }}">login</a> <a class="btn btn-default" href="{{ url_for('security.register') }}">register</a>
<ul> </p>
{% for e in f.errors %} {% endif %}
<li>{{ e }}</li> </div>
{% endfor %}
</ul>
{% endif %}
</div>
{% endfor %}
<button class="btn" type="submit">Submit</button>
</form>
{{ link | safe }}
{% endif %}
</div>
<a class="btn btn-primary" href="/"><i class="icon-arrow-left icon-white"></i> Back</a> <a class="btn btn-primary" href="/"><i class="icon-arrow-left icon-white"></i> Back</a>
</div> </div>
{% endblock body %} {% endblock body %}
\ No newline at end of file
...@@ -4,10 +4,15 @@ ...@@ -4,10 +4,15 @@
{% if current_user.is_authenticated() %} {% if current_user.is_authenticated() %}
<div class="btn-group pull-right"> <div class="btn-group pull-right">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#"> <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
<i class="icon-user"></i> {{ current_user.login }} <span class="caret"></span> <i class="icon-user"></i>
{% if current_user.first_name -%}
{{ current_user.first_name }}
{% else -%}
{{ current_user.email }}
{%- endif %} <span class="caret"></span>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="{{ url_for('admin.logout_view') }}">Log out</a></li> <li><a href="{{ url_for('security.logout') }}">Log out</a></li>
</ul> </ul>
</div> </div>
{% endif %} {% endif %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment