-from django.contrib.auth.models import User\r
-from django.shortcuts import render_to_response\r
-from django.template import RequestContext\r
-\r
-from forms import ClassicRegisterForm\r
-from forum.authentication.forms import SimpleEmailSubscribeForm\r
-from forum.views.auth import login_and_forward\r
-\r
-def register(request):\r
- if request.method == 'POST':\r
- form = ClassicRegisterForm(request.POST)\r
- email_feeds_form = SimpleEmailSubscribeForm(request.POST)\r
-\r
- if form.is_valid() and email_feeds_form.is_valid():\r
- username = form.cleaned_data['username']\r
- password = form.cleaned_data['password1']\r
- email = form.cleaned_data['email']\r
-\r
- user_ = User.objects.create_user( username,email,password )\r
- email_feeds_form.save(user_)\r
- #todo: email validation\r
- return login_and_forward(request, user_)\r
- else:\r
- form = ClassicRegisterForm(initial={'next':'/'})\r
- email_feeds_form = SimpleEmailSubscribeForm()\r
-\r
- return render_to_response('auth/signup.html', {\r
- 'form': form,\r
- 'email_feeds_form': email_feeds_form\r
- }, context_instance=RequestContext(request))
\ No newline at end of file
+from forum.models import User
+from django.shortcuts import render_to_response
+from django.template import RequestContext
+from django.utils.translation import ugettext as _
+
+from forms import ClassicRegisterForm
+from forum.views.auth import login_and_forward
+from forum.actions import UserJoinsAction
+
+def register(request):
+ if request.method == 'POST':
+ form = ClassicRegisterForm(request.POST)
+
+ if form.is_valid():
+ username = form.cleaned_data['username']
+ password = form.cleaned_data['password1']
+ email = form.cleaned_data['email']
+
+ user_ = User(username=username, email=email)
+ user_.set_password(password)
+
+ if User.objects.all().count() == 0:
+ user_.is_superuser = True
+ user_.is_staff = True
+
+ user_.save()
+ UserJoinsAction(user=user_, ip=request.META['REMOTE_ADDR']).save()
+
+ return login_and_forward(request, user_, None, _("A welcome email has been sent to your email address. "))
+ else:
+ form = ClassicRegisterForm(initial={'next':'/'})
+
+ return render_to_response('auth/complete.html', {
+ 'form1': form
+ }, context_instance=RequestContext(request))