mirror of
https://github.com/wassname/flask-security.git
synced 2026-06-27 16:10:11 +08:00
PEP8 polish
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
:license: MIT, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
from flask import current_app as app, request
|
||||
from flask import current_app as app
|
||||
from werkzeug.local import LocalProxy
|
||||
|
||||
from .signals import password_changed
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from flask import current_app as app, request
|
||||
from flask import current_app as app
|
||||
from werkzeug.local import LocalProxy
|
||||
|
||||
from .utils import send_mail, md5, url_for_security, get_token_status,\
|
||||
|
||||
@@ -244,7 +244,7 @@ def _context_processor():
|
||||
class RoleMixin(object):
|
||||
"""Mixin for `Role` model definitions"""
|
||||
def __eq__(self, other):
|
||||
return (self.name == other or \
|
||||
return (self.name == other or
|
||||
self.name == getattr(other, 'name', None))
|
||||
|
||||
def __ne__(self, other):
|
||||
@@ -346,10 +346,10 @@ class Security(object):
|
||||
self._state = self.init_app(app, datastore, **kwargs)
|
||||
|
||||
def init_app(self, app, datastore=None, register_blueprint=True,
|
||||
login_form=None, confirm_register_form=None,
|
||||
register_form=None, forgot_password_form=None,
|
||||
reset_password_form=None, change_password_form=None,
|
||||
send_confirmation_form=None, passwordless_login_form=None):
|
||||
login_form=None, confirm_register_form=None,
|
||||
register_form=None, forgot_password_form=None,
|
||||
reset_password_form=None, change_password_form=None,
|
||||
send_confirmation_form=None, passwordless_login_form=None):
|
||||
"""Initializes the Flask-Security extension for the specified
|
||||
application and datastore implentation.
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
:license: MIT, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
|
||||
class Datastore(object):
|
||||
def __init__(self, db):
|
||||
self.db = db
|
||||
|
||||
+17
-16
@@ -96,33 +96,32 @@ class Form(BaseForm):
|
||||
|
||||
|
||||
class EmailFormMixin():
|
||||
email = TextField(get_form_field_label('email'),
|
||||
validators=[email_required,
|
||||
email_validator])
|
||||
email = TextField(
|
||||
get_form_field_label('email'),
|
||||
validators=[email_required, email_validator])
|
||||
|
||||
|
||||
class UserEmailFormMixin():
|
||||
user = None
|
||||
email = TextField(get_form_field_label('email'),
|
||||
validators=[email_required,
|
||||
email_validator,
|
||||
valid_user_email])
|
||||
email = TextField(
|
||||
get_form_field_label('email'),
|
||||
validators=[email_required, email_validator, valid_user_email])
|
||||
|
||||
|
||||
class UniqueEmailFormMixin():
|
||||
email = TextField(get_form_field_label('email'),
|
||||
validators=[email_required,
|
||||
email_validator,
|
||||
unique_user_email])
|
||||
email = TextField(
|
||||
get_form_field_label('email'),
|
||||
validators=[email_required, email_validator, unique_user_email])
|
||||
|
||||
|
||||
class PasswordFormMixin():
|
||||
password = PasswordField(get_form_field_label('password'),
|
||||
validators=[password_required])
|
||||
password = PasswordField(
|
||||
get_form_field_label('password'), validators=[password_required])
|
||||
|
||||
|
||||
class NewPasswordFormMixin():
|
||||
password = PasswordField(get_form_field_label('password'),
|
||||
password = PasswordField(
|
||||
get_form_field_label('password'),
|
||||
validators=[password_required, password_length])
|
||||
|
||||
|
||||
@@ -255,10 +254,12 @@ class ResetPasswordForm(Form, NewPasswordFormMixin, PasswordConfirmFormMixin):
|
||||
class ChangePasswordForm(Form, PasswordFormMixin):
|
||||
"""The default change password form"""
|
||||
|
||||
new_password = PasswordField(get_form_field_label('new_password'),
|
||||
new_password = PasswordField(
|
||||
get_form_field_label('new_password'),
|
||||
validators=[password_required, password_length])
|
||||
|
||||
new_password_confirm = PasswordField(get_form_field_label('retype_password'),
|
||||
new_password_confirm = PasswordField(
|
||||
get_form_field_label('retype_password'),
|
||||
validators=[EqualTo('new_password', message='RETYPE_PASSWORD_MISMATCH')])
|
||||
|
||||
submit = SubmitField(get_form_field_label('change_password'))
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
:license: MIT, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
from flask import request, current_app as app
|
||||
from flask import current_app as app
|
||||
from werkzeug.local import LocalProxy
|
||||
|
||||
from .signals import login_instructions_sent
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
:license: MIT, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
from flask import current_app as app, request
|
||||
from flask import current_app as app
|
||||
from werkzeug.local import LocalProxy
|
||||
|
||||
from .signals import password_reset, reset_password_instructions_sent
|
||||
@@ -67,6 +67,7 @@ def reset_password_token_status(token):
|
||||
"""
|
||||
return get_token_status(token, 'reset', 'RESET_PASSWORD')
|
||||
|
||||
|
||||
def update_password(user, password):
|
||||
"""Update the specified user's password
|
||||
|
||||
|
||||
@@ -38,6 +38,6 @@ def register_user(**kwargs):
|
||||
|
||||
if config_value('SEND_REGISTER_EMAIL'):
|
||||
send_mail(config_value('EMAIL_SUBJECT_REGISTER'), user.email, 'welcome',
|
||||
user=user, confirmation_link=confirmation_link)
|
||||
user=user, confirmation_link=confirmation_link)
|
||||
|
||||
return user
|
||||
|
||||
@@ -78,8 +78,9 @@ def get_hmac(password):
|
||||
return password
|
||||
|
||||
if _security.password_salt is None:
|
||||
raise RuntimeError('The configuration value `SECURITY_PASSWORD_SALT` '
|
||||
'must not be None when the value of `SECURITY_PASSWORD_HASH` is '
|
||||
raise RuntimeError(
|
||||
'The configuration value `SECURITY_PASSWORD_SALT` must '
|
||||
'not be None when the value of `SECURITY_PASSWORD_HASH` is '
|
||||
'set to "%s"' % _security.password_hash)
|
||||
|
||||
h = hmac.new(_security.password_salt, password.encode('utf-8'), hashlib.sha512)
|
||||
@@ -386,5 +387,3 @@ def capture_signals():
|
||||
confirm_instructions_sent, login_instructions_sent,
|
||||
password_reset, password_changed,
|
||||
reset_password_instructions_sent])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user