def registration(req): if req.user.is_authenticated(): return HttpResponseRedirect(req.user.get_absolute_url()) elif 'POST'==req.method: regForm = RegForm(req.POST) if regForm.is_valid(): newUser = User.objects.create_user(regForm.cleaned_data['username'], regForm.cleaned_data['email']) newUser.first_name, newUser.last_name = regForm.cleaned_data['first_name'], regForm.cleaned_data['last_name'] newUser.is_active = False validator = Validator(user=newUser) validator.save() newUser.email_user(_('New account email confirmation'), render_to_string('registration/checkemail.eml', {'newUser': newUser, 'newUser_email': newUser.email, 'valCode': validator.code, 'validation_url': reverse('validate'), 'site': Site.objects.get_current()}, context_instance=RequestContext(req))) newUser.set_password(validator.code) newUser.save() return HttpResponseRedirect('/accounts/validation/') else: regForm = RegForm() return render_to_response('registration/signup.html', {'regForm': regForm}, context_instance=RequestContext(req))
def clean(self): self.hash = Validator.get_hash(self.cleaned_data['username'], self.cleaned_data['code']) try: Validator.objects.get(hash=self.hash) return self.cleaned_data except Validator.DoesNotExist: raise forms.ValidationError(_('Wrong validation code for this username or user email already validated.'))