Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

WIP: forms: initial password validation support #524

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion demo/demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@
# Make this unique, and don't share it with anybody.
SECRET_KEY = '_g-js)o8z#8=9pr1&05h^1_#)91sbo-)g^(*=-+epxmt4kc9m#'


# example password validation
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'OPTIONS': {'min_length': 8}
}
]


# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
Expand Down Expand Up @@ -118,8 +131,8 @@
'django.contrib.admin',
'django.contrib.admindocs',
'guardian',
'south',
'userena',
'easy_thumbnails',
'userena.contrib.umessages',
'profiles',
)
Expand Down
7 changes: 7 additions & 0 deletions demo/demo/static/css/master.css
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,13 @@ div#lang_form input[type=submit] {
}


form p + ul {
margin-top: 1em;
font-size: 0.7em;
font-family: 'Droid Sans', helvetica, arial, Geneva, sans-serif;
color: #999;
text-shadow: #ffffff 1px 1px 0;
}
/* notifications
................................... */

Expand Down
15 changes: 15 additions & 0 deletions userena/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,18 @@ def make_options(options):
else:
def make_options(options):
return ()


try:
from django.contrib.auth.password_validation import (
validate_password,
password_validators_help_text_html,
)

except (ImportError, AttributeError):
# Password validation is not available for Django < 1.9.3
def get_password_validators(value):
return None

def password_validators_help_text_html():
return None
10 changes: 8 additions & 2 deletions userena/forms.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#encoding:utf-8
from __future__ import unicode_literals

from django import forms
from django.contrib.auth import get_user_model
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth import authenticate

from userena import settings as userena_settings
from userena.models import UserenaSignup
from userena.utils import get_profile_model
from userena.compat import (
validate_password,
password_validators_help_text_html
)

from hashlib import sha1
import random
Expand Down Expand Up @@ -40,7 +44,9 @@ class SignupForm(forms.Form):
label=_("Email"))
password1 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict,
render_value=False),
label=_("Create password"))
label=_("Create password"),
validators=[validate_password],
help_text=mark_safe(password_validators_help_text_html()))
password2 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict,
render_value=False),
label=_("Repeat password"))
Expand Down
3 changes: 2 additions & 1 deletion userena/templates/userena/signup_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
</p>
{% else %}
<p>
{{ field.label_tag }}
{{ field.label_tag }}
{{ field }}
{{ field.help_text }}
</p>
{% endif %}
{% endfor %}
Expand Down