password change and set pages for Flask.
Project description
Flask-change-password is a Flask extension that implements create and change password pages that can easily be integrated with a Flask application.
Features
Installation & Basic Usage
Install via pip:
pip install flask-change-password
After installing, wrap your Flask app with an ChangePassword, or call init_app(app).
Example:
from flask import Flask from flask_change_password import ChangePassword, ChangePasswordForm, SetPasswordForm app = Flask(__name__) app.secret_key = os.urandom(20) flask_change_password = ChangePassword(min_password_length=10, rules=dict(long_password_override=2)) flask_change_password.init_app(app)
The repository includes a small example application.
NOTE: This extension uses KnockoutJS for the page view controller and will call the JS from a CDN.
Options
- app, Flask application. Use init_app(app) to intialise later on.
Methods
- init_app(app) - Initialise and start with the given Flask application.
- change_password_template(form, submit_text=None) - Format and return a
- fragment of HTML that implements the change/set password form. form is the required password operation form. submit_text is the text to show on the submit button. Default is ‘submit’
Adding the form to a page
Call as follows in your Flask application route:
return render_template('change_password.html', password_template=password_template, title=title, form=form, user=dict(username='test.user'), )
And include the template using the jinja2 safe pipe.
{% extends "base.html" %} {% block app_content %} <h1>Test Change Password</h1> {{ password_template|safe }} {% endblock %}
Change Password
Example of calling the change password form.
@app.route('/change_password', methods=['GET', 'POST']) def page_change_password(): title = 'Change Password' form = ChangePasswordForm(username='test.user', changing=True, title=title) if form.validate_on_submit(): valid = flask_change_password.verify_password_change_form(form) if valid: return redirect(url_for('page_changed', title='changed', new_password=form.password.data)) return redirect(url_for('page_change_password')) password_template = flask_change_password.change_password_template(form, submit_text='Change') return render_template('change_password.html', password_template=password_template, title=title, form=form, user=dict(username='test.user'), )
Create Password
Example of calling the create password form. Use the SetPasswordForm class.
@app.route('/create_password', methods=['GET', 'POST']) def page_create_password(): title = 'Create Password' form = SetPasswordForm(username='test.user', title=title) if form.validate_on_submit(): valid = flask_change_password.verify_password_change_form(form) if valid: return redirect(url_for('page_changed', title='created', new_password=form.password.data)) return redirect(url_for('page_create_password')) password_template = flask_change_password.change_password_template(form, submit_text='Submit') return render_template('create_password.html', password_template=password_template, title=title, form=form, user=dict(username='test.user'), )
Licensing
- Apache 2.0
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size flask-change-password-0.0.3.tar.gz (10.8 kB) | File type Source | Python version None | Upload date | Hashes View |
Hashes for flask-change-password-0.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d6ea17df992b75a2b069df5977fd1987283e4099e10036f5ec28832f9f8575c |
|
MD5 | 000494f627bc2949a37a087db1843699 |
|
BLAKE2-256 | 124ff19817cbf79b3c2c37c07ae0434597faf043a8ba4f173d669924413a7372 |