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 _
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 from forum.actions import UserJoinsAction
11 def register(request):
12 if request.method == 'POST':
13 form = ClassicRegisterForm(request.POST)
14 email_feeds_form = SimpleEmailSubscribeForm(request.POST)
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']
21 user_ = User(username=username, email=email)
22 user_.set_password(password)
24 if User.objects.all().count() == 0:
25 user_.is_superuser = True
28 UserJoinsAction(user=user_, ip=request.META['REMOTE_ADDR']).save()
30 send_validation_email(user_)
31 if email_feeds_form.cleaned_data['subscribe'] == 'n':
32 user_.subscription_settings.enable_notifications = False
33 user_.subscription_settings.save()
35 return login_and_forward(request, user_, None, _("A validation email has been sent to your email address. "))
37 form = ClassicRegisterForm(initial={'next':'/'})
38 email_feeds_form = SimpleEmailSubscribeForm()
40 return render_to_response('auth/complete.html', {
42 'email_feeds_form': email_feeds_form
43 }, context_instance=RequestContext(request))