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
10 def register(request):
11 if request.method == 'POST':
12 form = ClassicRegisterForm(request.POST)
13 email_feeds_form = SimpleEmailSubscribeForm(request.POST)
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']
20 user_ = User(username=username, email=email)
21 user_.set_password(password)
23 if User.objects.all().count() == 0:
24 user_.is_superuser = True
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()
33 return login_and_forward(request, user_, None, _("A validation email has been sent to your email address. "))
35 form = ClassicRegisterForm(initial={'next':'/'})
36 email_feeds_form = SimpleEmailSubscribeForm()
38 return render_to_response('auth/signup.html', {
40 'email_feeds_form': email_feeds_form
41 }, context_instance=RequestContext(request))