Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Extra validations when setting username.

  • Loading branch information...
commit 83f490629f1e063152e775ffb9be387673797cf3 1 parent 5589c5f
Alex Vidal authored

Showing 2 changed files with 21 additions and 3 deletions. Show diff stats Hide diff stats

  1. +18 1 wotmad/users/forms.py
  2. +3 2 wotmad/users/views.py
19 wotmad/users/forms.py
... ... @@ -1,9 +1,26 @@
  1 +from flask import g
  2 +
1 3 from flaskext import wtf
2 4
  5 +from wotmad.users.models import User
  6 +
3 7
4 8 class LoginForm(wtf.Form):
5 9 assertion = wtf.HiddenField(validators=[wtf.Required()])
6 10
7 11
  12 +USERNAME_REGEX_ERROR = ("Username must begin with a letter and can only "
  13 + "contain letters and numbers.")
  14 +
  15 +
8 16 class SetupForm(wtf.Form):
9   - username = wtf.TextField('Username', [wtf.Required()])
  17 + username = wtf.TextField('Username',
  18 + [wtf.Required(), wtf.Length(5, 30),
  19 + wtf.Regexp(r'^[a-zA-Z][a-zA-Z0-9]+$',
  20 + message=USERNAME_REGEX_ERROR)])
  21 +
  22 + def validate_username(self, field):
  23 + """Ensures the username is not already taken"""
  24 + matches = User.objects(username__iexact=field.data, id__ne=g.user.id)
  25 + if matches:
  26 + raise wtf.ValidationError("Username already taken.")
5 wotmad/users/views.py
@@ -39,8 +39,9 @@ def do_user_setup():
39 39 @login_required
40 40 def setup_account():
41 41 if g.user.is_active:
42   - flash('Already setup!', 'error')
43   - return redirect(url_for('index'))
  42 + #flash('Already setup!', 'error')
  43 + #return redirect(url_for('index'))
  44 + pass
44 45
45 46 # If the user isn't active, they need to set their username
46 47 form = SetupForm(obj=g.user)

0 comments on commit 83f4906

Please sign in to comment.
Something went wrong with that request. Please try again.