]> git.openstreetmap.org Git - osqa.git/blob - forum_modules/localauth/views.py
merge notification-config -> trunk, previous commits 694, 695, 702
[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.views.auth import login_and_forward
8 from forum.actions import UserJoinsAction
9
10 def register(request):
11     if request.method == 'POST':
12         form = ClassicRegisterForm(request.POST)
13
14         if form.is_valid():
15             username = form.cleaned_data['username']
16             password = form.cleaned_data['password1']
17             email = form.cleaned_data['email']
18
19             user_ = User(username=username, email=email)
20             user_.set_password(password)
21
22             if User.objects.all().count() == 0:
23                 user_.is_superuser = True
24                 user_.is_staff = True
25
26             user_.save()
27             UserJoinsAction(user=user_, ip=request.META['REMOTE_ADDR']).save()
28
29             return login_and_forward(request, user_, None, _("A welcome email has been sent to your email address. "))
30     else:
31         form = ClassicRegisterForm(initial={'next':'/'})
32
33     return render_to_response('auth/complete.html', {
34         'form1': form
35         }, context_instance=RequestContext(request))