Skip to content

Commit

Permalink
Strip le pseudo avec ajout/update mais coté form (plus propre)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eskimon committed Jul 27, 2014
1 parent 6a70269 commit 1ee9c3f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions zds/member/forms.py
Expand Up @@ -151,9 +151,8 @@ def clean(self):

# Check that the user doesn't exist yet
username = cleaned_data.get('username')
username = username.strip();

if username == '':
if username.strip() == '':
msg = u'Le nom d\'utilisateur ne peut-être vide'
self._errors['username'] = self.error_class([msg])
elif User.objects.filter(username=username).count() > 0:
Expand All @@ -163,6 +162,9 @@ def clean(self):
elif username is not None and "," in username:
msg = u'Le nom d\'utilisateur ne peut contenir de virgules'
self._errors['username'] = self.error_class([msg])
elif username != username.strip():
msg = u'Le nom d\'utilisateur ne peut commencer/finir par des espaces'
self._errors['username'] = self.error_class([msg])

# Check that password != username
if password == username:
Expand Down Expand Up @@ -360,15 +362,17 @@ def clean(self):
username_new = cleaned_data.get('username_new')
email_new = cleaned_data.get('email_new')

username_new = username_new.strip()
if username_new is not None:
if username_new != '':
if User.objects.filter(username=username_new).count() >= 1:
if username_new.strip() != '':
if User.objects.filter(username=username_new.strip()).count() >= 1:
self._errors['username_new'] = self.error_class(
[u'Ce nom d\'utilisateur est déjà utilisé'])
else:
self._errors['username_new'] = self.error_class(
[u'Le nom d\'utilisateur ne peut-être vide'])
if username_new != username_new.strip():
msg = u'Le nom d\'utilisateur ne peut commencer/finir par des espaces'
self._errors['username_new'] = self.error_class([msg])

if email_new is not None:
if email_new.strip() != '':
Expand Down
4 changes: 2 additions & 2 deletions zds/member/views.py
Expand Up @@ -496,7 +496,7 @@ def settings_user(request):
if form.is_valid():
old = User.objects.filter(pk=request.user.pk).all()[0]
if form.data["username_new"]:
old.username = form.data["username_new"].strip()
old.username = form.data["username_new"]
elif form.data["email_new"]:
if form.data["email_new"].strip() != "":
old.email = form.data["email_new"]
Expand Down Expand Up @@ -587,7 +587,7 @@ def register_view(request):
form = RegisterForm(request.POST)
if form.is_valid():
data = form.data
user = User.objects.create_user(data["username"].strip(), data["email"],
user = User.objects.create_user(data["username"], data["email"],
data["password"])
user.is_active = False
user.save()
Expand Down

0 comments on commit 1ee9c3f

Please sign in to comment.