Commit 661fd0a4 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

User state fixes

- Never reset activation_sent date
- Check for inactive users too for email/username uniqueness
- Check both email/username uniquness in user creation process
- Activated users should have both email_verified/activation_sent fields
  set
parent 8f2951ef
......@@ -359,8 +359,7 @@ class LoginForm(AuthenticationForm):
'recaptcha_response_field', ])
def clean_username(self):
if 'username' in self.cleaned_data:
return self.cleaned_data['username'].lower()
return self.cleaned_data['username'].lower()
def clean_recaptcha_response_field(self):
if 'recaptcha_challenge_field' in self.cleaned_data:
......@@ -475,7 +474,7 @@ class ExtendedPasswordResetForm(PasswordResetForm):
def clean_email(self):
email = super(ExtendedPasswordResetForm, self).clean_email()
try:
user = AstakosUser.objects.get(email__iexact=email, is_active=True)
user = AstakosUser.objects.get(email__iexact=email)
if not user.has_usable_password():
raise forms.ValidationError(_(astakos_messages.UNUSABLE_PASSWORD))
......
......@@ -287,8 +287,7 @@ def activate(
Raises SendGreetingError, ValidationError
"""
user.is_active = True
if verify_email:
user.email_verified = True
user.email_verified = True
user.save()
send_helpdesk_notification(user, helpdesk_email_template_name)
send_greeting(user, email_template_name)
......
......@@ -47,11 +47,11 @@ class Command(BaseCommand):
raise CommandError("No user was given")
for email_or_id in args:
user = get_user(email_or_id, is_active=False)
user = get_user(email_or_id)
if not user:
self.stderr.write("Unknown user '%s'\n" % (email_or_id,))
continue
if user.is_active:
if user.email_verified and user.is_active:
self.stderr.write(
"Already active user '%s'\n" % (email_or_id,))
continue
......
......@@ -125,6 +125,10 @@ class Command(BaseCommand):
if options.get('active'):
user.is_active = True
if not user.email_verified:
user.email_verified = True
if not user.activation_sent:
user.activation_sent = True
elif options.get('inactive'):
user.is_active = False
......
......@@ -504,9 +504,6 @@ class AstakosUser(User):
self.username = self.email
self.validate_unique_email_isactive()
if self.is_active and self.activation_sent:
# reset the activation sent
self.activation_sent = None
super(AstakosUser, self).save(**kwargs)
......@@ -556,7 +553,6 @@ class AstakosUser(User):
"""
q = AstakosUser.objects.all()
q = q.filter(email = self.email)
q = q.filter(is_active = self.is_active)
if self.id:
q = q.filter(~Q(id = self.id))
if q.count() != 0:
......
......@@ -209,7 +209,8 @@ def reverse_lazy(*args, **kwargs):
def reserved_email(email):
return AstakosUser.objects.filter(email__iexact=email).count() != 0
return AstakosUser.objects.filter(email__iexact=email).count() > 0 or \
AstakosUser.objects.filter(username__iexact=email).count() > 0
def get_query(request):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment