]> git.openstreetmap.org Git - osqa.git/blob - forum_modules/localauth/views.py
Shows user diamonds in some missing spots, and adds some improvements to module decor...
[osqa.git] / forum_modules / localauth / views.py
1 from forum.models import User
2 from django.shortcuts import render_to_response
3 from django.template import RequestContext
4 from django.utils.translation import ugettext as _
5
6 from forms import ClassicRegisterForm
7 from forum.forms import SimpleEmailSubscribeForm
8 from forum.views.auth import login_and_forward
9 from forum.actions import UserJoinsAction
10
11 def register(request):
12     if request.method == 'POST':
13         form = ClassicRegisterForm(request.POST)
14         email_feeds_form = SimpleEmailSubscribeForm(request.POST)
15
16         if form.is_valid() and email_feeds_form.is_valid():
17             username = form.cleaned_data['username']
18             password = form.cleaned_data['password1']
19             email = form.cleaned_data['email']
20
21             user_ = User(username=username, email=email)
22             user_.set_password(password)
23
24             if User.objects.all().count() == 0:
25                 user_.is_superuser = True
26                 user_.is_staff = True
27
28             user_.save()
29             UserJoinsAction(user=user_, ip=request.META['REMOTE_ADDR']).save()
30
31             if email_feeds_form.cleaned_data['subscribe'] == 'n':
32                 user_.subscription_settings.enable_notifications = False
33                 user_.subscription_settings.save()
34
35             return login_and_forward(request, user_, None, _("A welcome email has been sent to your email address. "))
36     else:
37         form = ClassicRegisterForm(initial={'next':'/'})
38         email_feeds_form = SimpleEmailSubscribeForm()
39
40     return render_to_response('auth/complete.html', {
41         'form1': form,
42         'email_feeds_form': email_feeds_form
43         }, context_instance=RequestContext(request))