summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFraser Gutteridge <blue@udel.edu>2012-02-17 19:21:23 (GMT)
committerFraser Gutteridge <blue@udel.edu>2012-02-17 19:21:23 (GMT)
commitb457800c0fedb29a55d46e39d4e1e9cc7a69a8a9 (patch)
treed6a31a5d5577d8b484adc16b3155df1e0996f35d
parentce0e786f38e54a4f0a55baf6f903b1cd20e4f79c (diff)
downloadfas-b457800c0fedb29a55d46e39d4e1e9cc7a69a8a9.zip
fas-b457800c0fedb29a55d46e39d4e1e9cc7a69a8a9.tar.gz
fas-b457800c0fedb29a55d46e39d4e1e9cc7a69a8a9.tar.xz
Updated to 0.8.12 - added human name checks requested in ticket 654.
See NEWS for more information.
-rw-r--r--NEWS12
-rw-r--r--fas/templates/user/new.html4
-rw-r--r--fas/user.py14
-rw-r--r--fas/validators.py55
4 files changed, 39 insertions, 46 deletions
diff --git a/NEWS b/NEWS
index 1885442..c9ecc62 100644
--- a/NEWS
+++ b/NEWS
@@ -3,8 +3,16 @@ NEWS
====
:Authors: Ricky Zhou, Mike McGrath, Toshio Kuratomi
-:Date: 24 Jan 2011
-:Version: 0.8.11
+:Date: 16 Feb 2012
+:Version: 0.8.12
+
+------
+0.8.12
+------
+* Added human name check requested in ticket #654. Modified regular expression
+ to not only check for missing section of full name (last or first), but avoid
+ potential false positives from users entering a middle initial.
+ (Fraser S. Gutteridge)
------
0.8.11
diff --git a/fas/templates/user/new.html b/fas/templates/user/new.html
index 1f3c4e6..bb64212 100644
--- a/fas/templates/user/new.html
+++ b/fas/templates/user/new.html
@@ -20,6 +20,10 @@
<script type="text/javascript">var hb1 = new HelpBalloon({dataURL: '${tg.url('/help/get_help/user_human_name')}'});</script>
</div>
<div class="field">
+ <label for="human_name">${_('Name check override:')}</label>
+ <input type="checkbox" id="human_name_override" name="human_name_override" />
+ </div>
+ <div class="field">
<label for="email">${_('Email:')}</label>
<input type="text" id="email" name="email" />
<script type="text/javascript">var hb1 = new HelpBalloon({dataURL: '${tg.url('/help/get_help/user_email')}'});</script>
diff --git a/fas/user.py b/fas/user.py
index 380e675..7aa84d5 100644
--- a/fas/user.py
+++ b/fas/user.py
@@ -70,7 +70,8 @@ from fas import openssl_fas
from fas.auth import is_admin, cla_done, undeprecated_cla_done, can_edit_user
from fas.util import available_languages
from fas.validators import KnownUser, PasswordStrength, ValidSSHKey, \
- NonFedoraEmail, ValidLanguage, UnknownUser, ValidUsername
+ NonFedoraEmail, ValidLanguage, UnknownUser, ValidUsername, \
+ ValidHumanWithOverride
from fas import _
#ADMIN_GROUP = config.get('admingroup', 'accounts')
@@ -87,8 +88,9 @@ class UserCreate(validators.Schema):
validators.String(max=32, min=3),
)
human_name = validators.All(
- validators.String(not_empty=True, max=42),
- validators.Regex(regex='^[^\n:<>]+$'),
+ validators.String(not_empty=True),
+ )
+ human_name_override = validators.All(
)
email = validators.All(
validators.Email(not_empty=True, strip=True),
@@ -101,7 +103,8 @@ class UserCreate(validators.Schema):
#fedoraPersonBugzillaMail = validators.Email(strip=True)
postal_address = validators.String(max=512)
captcha = CaptchaFieldValidator()
- chained_validators = [ validators.FieldsMatch('email', 'verify_email') ]
+ chained_validators = [ validators.FieldsMatch('email', 'verify_email'),
+ ValidHumanWithOverride('human_name', 'human_name_override') ]
class UserSetPassword(validators.Schema):
''' Validate new and old passwords '''
@@ -795,11 +798,12 @@ If the above information is incorrect, please log in and fix it:
@validate(validators=UserCreate())
@error_handler(error) # pylint: disable-msg=E0602
def create(self, username, human_name, email, verify_email, telephone=None,
- postal_address=None, age_check=False, captcha=None):
+ postal_address=None, age_check=False, captcha=None, human_name_override=False):
''' Parse arguments from the UI and make sure everything is in order.
:arg username: requested username
:arg human_name: full name of new user
+ :arg human_name_override: override check of user's full name
:arg email: email address of the new user
:arg verify_email: double check of users email
:arg telephone: telephone number of new user
diff --git a/fas/validators.py b/fas/validators.py
index 2974e90..6036eba 100644
--- a/fas/validators.py
+++ b/fas/validators.py
@@ -279,54 +279,31 @@ class PasswordStrength(validators.UnicodeString):
raise validators.Invalid(self.message('strength', state), value, state)
-class ValidHumanWithOverride(validators.FormValidator):
- '''Perform some simple heuristics on the person's human name.
+class ValidHumanWithOverride(validators.FancyValidator):
- We need a legally valid name. We need to try to screen out names that are
- possibly bad here. This should be used with an override switch that lets
- a user tell us that his legal name really matches the heuristics we
- establish.
-
- Present heuristics are that the name must be multiple words and that the
- last name cannot be a single letter or a letter followed by a period.
-
- This validator is meant to be used as a chained validator with a text
- input field for the human name and a boolean checkbox field for the
- override. Here's a n example of using it from within
- a :class:`formencode.Schema`::
-
- class TestSchema(Schema):
- human_name = validators.UnicodeString(not_empty=True)
- name_override = validators.StringBool(if_missing=False)
- chained_validators = [ValidHumanWithOverride('human_name', 'name_override')]
- '''
-
- messages = {'noname': _('You must enter your legal name'),
- 'lastfirst': _('You must include both your last name and first name. If your name really only consists of a single letter, you may check the override checkbox to submit this name.'),
- 'initial': _('You must include the full form of your names, not just initials. If your fullname really has one letter portions, you may check the override checkbox to submit this name.')}
+ messages = { 'initial': _('You must include the full form of your names, not just initials. If your fullname really has one letter portions, you may check the override checkbox to submit this name.')}
def __init__(self, name_field, override_field):
- super(validators.FormValidator, self).__init__()
+ super(validators.FancyValidator, self).__init__()
self.name_field = name_field
self.override = override_field
def validate_python(self, values, state):
- # Check that a name was entered
- name = values.get(self.name_field)
- if not name:
- raise validators.Invalid(self.message('noname', state), values, state)
+ errors = {}
# If override is set, then we skip the rest of testing
if values.get(self.override, False):
return
- # Check that the name is more than one word
- split_name = name.split(u' ')
- if len(split_name) < 2:
- raise validators.Invalid(self.message('lastfirst', state), values, state)
-
- # Check for initials
- for name_part in split_name:
- if len(name_part.rstrip(u'.')) <= 1:
- raise validators.Invalid(self.message('initial', state), values, state)
-
+ # Check for initials, only first or last name etc.
+ name = values.get(self.name_field)
+ name_regex = re.compile ( '^([A-Z]|[a-z])+\s(([A-Z]|[a-z])\.\s)*([A-Z]|[a-z])+$' )
+ if not name_regex.match ( name ):
+ errors[self.name_field] = self.message('initial', state)
+
+ # raise errors
+ if errors:
+ error_list = errors.items()
+ error_list.sort()
+ error_message = '<br>\n'.join(['%s: %s' % (name, values) for name, values in error_list])
+ raise validators.Invalid(error_message, values, state, error_dict=errors)