def clean_switched_username(self): username = self.cleaned_data['switched_username'] to_user = get_user_by_username_or_email(username) if not to_user: raise forms.ValidationError(_("Invalid username")) elif to_user.is_superuser: raise forms.ValidationError(_("Switching to a superuser account is not permitted.")) return username
def authenticate(self, username=None, password=None): user = get_user_by_username_or_email(username) if user and user.check_password(password): return user return None