mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-10 09:06:21 +01:00
Logging everywhere.
Corrected corp model updating logic to handle owning corp. Corrected typecasting during api access mask comparison. Removed error protection during user TS3 group updating to propogate errors. Relevent issues: Sorry for the spam.
This commit is contained in:
@@ -2,6 +2,9 @@ from django import forms
|
||||
from django.contrib.auth.models import User
|
||||
import re
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class RegistrationForm(forms.Form):
|
||||
username = forms.CharField(max_length=30, required=True)
|
||||
@@ -12,24 +15,29 @@ class RegistrationForm(forms.Form):
|
||||
|
||||
def clean(self):
|
||||
if ' ' in self.cleaned_data['username']:
|
||||
logger.error("RegistrationForm username contains spaces. Raising ValidationError. Username: %s" % self.cleaned_data['username'])
|
||||
raise forms.ValidationError(u'Username cannot contain a space')
|
||||
|
||||
# We attempt to get the user object if we succeed we know email as been used
|
||||
try:
|
||||
User.objects.get(email=self.cleaned_data['email'])
|
||||
logger.error("RegistrationForm email already registered. Raising ValidationError")
|
||||
raise forms.ValidationError(u'Email as already been used')
|
||||
except:
|
||||
pass
|
||||
|
||||
if not re.match("^\w+$", self.cleaned_data['username']):
|
||||
logger.error("RegistrationForm username contains non-alphanumeric characters. Raising ValueError. Username: %s" % self.cleaned_data['username'])
|
||||
raise forms.ValidationError(u'Username contains illegal characters')
|
||||
|
||||
if 'password' in self.cleaned_data and 'password_again' in self.cleaned_data:
|
||||
if self.cleaned_data['password'] != self.cleaned_data['password_again']:
|
||||
logger.error("RegistrationForm password mismatch. Raising ValueError")
|
||||
raise forms.ValidationError(u'Passwords do not match')
|
||||
|
||||
if 'email' in self.cleaned_data and 'email_again' in self.cleaned_data:
|
||||
if self.cleaned_data['email'] != self.cleaned_data['email_again']:
|
||||
logger.error("RegistrationForm email mismatch. Raising ValidationError")
|
||||
raise forms.ValidationError(u'Emails do not match')
|
||||
|
||||
return self.cleaned_data
|
||||
|
||||
@@ -5,11 +5,15 @@ from django.template import RequestContext
|
||||
|
||||
from forms import RegistrationForm
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def register_user_view(request):
|
||||
logger.debug("register_user_view called by user %s" % request.user)
|
||||
if request.method == 'POST':
|
||||
form = RegistrationForm(request.POST)
|
||||
|
||||
logger.debug("Request type POST contains form valid: %s" % form.is_valid())
|
||||
if form.is_valid():
|
||||
|
||||
if not User.objects.filter(username=form.cleaned_data['username']).exists():
|
||||
@@ -17,14 +21,19 @@ def register_user_view(request):
|
||||
form.cleaned_data['email'], form.cleaned_data['password'])
|
||||
|
||||
user.save()
|
||||
logger.info("Created new user %s" % user)
|
||||
|
||||
return HttpResponseRedirect("/dashboard")
|
||||
|
||||
else:
|
||||
logger.error("Unable to register new user: username %s already exists." % form.cleaned_data['username'])
|
||||
return render_to_response('public/register.html', {'form': form, 'error': True}
|
||||
, context_instance=RequestContext(request))
|
||||
else:
|
||||
logger.debug("Registration form invalid. Returning for user %s to make corrections." % request.user)
|
||||
|
||||
else:
|
||||
logger.debug("Returning blank registration form.")
|
||||
form = RegistrationForm()
|
||||
|
||||
return render_to_response('public/register.html', {'form': form}, context_instance=RequestContext(request))
|
||||
return render_to_response('public/register.html', {'form': form}, context_instance=RequestContext(request))
|
||||
|
||||
Reference in New Issue
Block a user