Skip to content

Commit

Permalink
Merge pull request #577 from jtakayama/password-case-warning
Browse files Browse the repository at this point in the history
Partial fix for mixed-case username bug [GH-564].
  • Loading branch information
jtakayama committed Nov 14, 2013
2 parents 2ca4e09 + 1f083e0 commit 7508b8b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion makahiki/apps/managers/player_mgr/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class MakahikiUserAdmin(UserAdmin):
page_text = "Click on the name in the Username column to edit a player's " + \
"password, personal information, roles, and site administration groups. " + \
"Click on the name in the Profile column to edit a player's display name, " + \
"team, badges, etc."
"team, badges, etc. " + \
"<span style=\"font-weight:bold\">A player's username cannot contain uppercase letters.</span>"

def set_active(self, request, queryset):
"""set the active flag priority."""
Expand Down
19 changes: 19 additions & 0 deletions makahiki/apps/managers/player_mgr/player_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ def points_leaders(num_results=None, round_name=None):
results = results[:num_results]
return results

def username_is_lowercase(username):
"""Check that user names do not include uppercase letter characters."""
username_input = username
username_lower = username.lower()
username_lowercase = False
if username_input == username_lower:
username_lowercase = True
else:
username_lowercase = False
return username_lowercase

def create_player(username, password, email, firstname, lastname, team_name, is_ra):
"""Create a player with the assigned team"""
Expand All @@ -61,6 +71,15 @@ def create_player(username, password, email, firstname, lastname, team_name, is_
except ObjectDoesNotExist:
pass

# Change uppercase letters to lowercase
username_input = username
username_lower = username.lower()
invalid_username_message = "Username \"%s\" is invalid: usernames must not use uppercase letters. User will be created with username \"%s\" instead." % (username_input, username_lower)
if username_is_lowercase(username_input) == False:
username = username_lower
# Print warning message to console (not visible to the web UI)
print invalid_username_message
# Create user
user = User.objects.create_user(username, email, password)
user.first_name = firstname
user.last_name = lastname
Expand Down
9 changes: 9 additions & 0 deletions makahiki/templates/admin/auth/user/bulk_upload_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ <h4 class="no-top">Upload a CSV file.</h4>
<p>
Click the Choose File button to select the CSV file that contains user information.
</p>
<p>
The information of each user in the CSV must be formatted as follows:
<pre>team,firstname,lastname,email,username,password</pre>
<span style="font-weight:bold">Warning:</span>
<ul>
<li>Usernames must not contain uppercase letters.</li>
<li>Uppercase letters will be converted to lowercase when the username is saved.</li>
</ul>
</p>
<form enctype="multipart/form-data" method="POST" action="{% url 'bulk_create' %}">
{% csrf_token %}
{% if file_error %}
Expand Down

0 comments on commit 7508b8b

Please sign in to comment.