X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/a9eef437702d5df7a2f97010e6798c689371808c..4bbb2156110a75e84ef95ee28ba31490d986b870:/forum_modules/localauth/views.py?ds=sidebyside diff --git a/forum_modules/localauth/views.py b/forum_modules/localauth/views.py old mode 100755 new mode 100644 index acad16c..2fcee22 --- a/forum_modules/localauth/views.py +++ b/forum_modules/localauth/views.py @@ -1,30 +1,35 @@ -from django.contrib.auth.models import User -from django.shortcuts import render_to_response -from django.template import RequestContext - -from forms import ClassicRegisterForm -from forum.authentication.forms import SimpleEmailSubscribeForm -from forum.views.auth import login_and_forward - -def register(request): - if request.method == 'POST': - form = ClassicRegisterForm(request.POST) - email_feeds_form = SimpleEmailSubscribeForm(request.POST) - - if form.is_valid() and email_feeds_form.is_valid(): - username = form.cleaned_data['username'] - password = form.cleaned_data['password1'] - email = form.cleaned_data['email'] - - user_ = User.objects.create_user( username,email,password ) - email_feeds_form.save(user_) - #todo: email validation - return login_and_forward(request, user_) - else: - form = ClassicRegisterForm(initial={'next':'/'}) - email_feeds_form = SimpleEmailSubscribeForm() - - return render_to_response('auth/signup.html', { - 'form': form, - 'email_feeds_form': email_feeds_form - }, context_instance=RequestContext(request)) \ No newline at end of file +from forum.models import User +from django.shortcuts import render_to_response +from django.template import RequestContext +from django.utils.translation import ugettext as _ + +from forms import ClassicRegisterForm +from forum.views.auth import login_and_forward +from forum.actions import UserJoinsAction + +def register(request): + if request.method == 'POST': + form = ClassicRegisterForm(request.POST) + + if form.is_valid(): + username = form.cleaned_data['username'] + password = form.cleaned_data['password1'] + email = form.cleaned_data['email'] + + user_ = User(username=username, email=email) + user_.set_password(password) + + if User.objects.all().count() == 0: + user_.is_superuser = True + user_.is_staff = True + + user_.save() + UserJoinsAction(user=user_, ip=request.META['REMOTE_ADDR']).save() + + return login_and_forward(request, user_, None, _("A welcome email has been sent to your email address. ")) + else: + form = ClassicRegisterForm(initial={'next':'/'}) + + return render_to_response('auth/complete.html', { + 'form1': form + }, context_instance=RequestContext(request))