]> git.openstreetmap.org Git - osqa.git/blob - forum_modules/localauth/views.py
f0b4438a3fafa6d2939e5404986de9b18f818492
[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.authentication.forms import SimpleEmailSubscribeForm
8 from forum.views.auth import login_and_forward, send_validation_email
9
10 def register(request):
11     if request.method == 'POST':
12         form = ClassicRegisterForm(request.POST)
13         email_feeds_form = SimpleEmailSubscribeForm(request.POST)
14
15         if form.is_valid() and email_feeds_form.is_valid():
16             username = form.cleaned_data['username']
17             password = form.cleaned_data['password1']
18             email = form.cleaned_data['email']
19
20             user_ = User(username=username, email=email)
21             user_.set_password(password)
22
23             if User.objects.all().count() == 0:
24                 user_.is_superuser = True
25
26             user_.save()
27             
28             send_validation_email(user_)
29             if email_feeds_form.cleaned_data['subscribe'] == 'n':
30                 user_.subscription_settings.enable_notifications = False
31                 user_.subscription_settings.save()
32
33             return login_and_forward(request, user_, None, _("A validation email has been sent to your email address. "))
34     else:
35         form = ClassicRegisterForm(initial={'next':'/'})
36         email_feeds_form = SimpleEmailSubscribeForm()
37
38     return render_to_response('auth/signup.html', {
39         'form': form,
40         'email_feeds_form': email_feeds_form
41         }, context_instance=RequestContext(request))