Package madrona :: Package common :: Package registration_backend
[hide private]

Source Code for Package madrona.common.registration_backend

 1  from registration.backends.default import DefaultBackend 
 2  from django.db import transaction 
 3  from django import forms 
 4  from django.contrib.sites.models import Site, RequestSite 
 5  from django.contrib.auth.models import User, Group 
 6  from registration.models import RegistrationManager, RegistrationProfile 
 7  from registration.forms import RegistrationForm 
 8  from registration import signals 
 9  from django.conf import settings 
10   
11 -class CustomRegistrationForm(RegistrationForm):
12 first_name = forms.CharField(label="First Name") 13 last_name = forms.CharField(label="Last Name")
14
15 -class LingcodBackend(DefaultBackend):
16 - def get_form_class(self, request):
18
19 - def register(self, request, **kwargs):
20 """ 21 Given a username, firstname, lastname, email address and password, 22 register a new user account, which will initially be inactive. 23 24 See django-registration docs for more info 25 """ 26 username, email, password, first, last = kwargs['username'], kwargs['email'], kwargs['password1'], \ 27 kwargs['first_name'], kwargs['last_name'] 28 if Site._meta.installed: 29 site = Site.objects.get_current() 30 else: 31 site = RequestSite(request) 32 new_user = RegistrationProfile.objects.create_inactive_user(username, email, password, site) 33 new_user.first_name = first 34 new_user.last_name = last 35 new_user.is_active = False 36 webreg_group = Group.objects.get(name=settings.GROUP_REGISTERED_BY_WEB) 37 new_user.groups.add(webreg_group) 38 new_user.save() 39 signals.user_registered.send(sender=self.__class__, user=new_user, request=request) 40 return new_user
41