Пример #1
0
 def test_1_invalid_form(self):
     """
     Testing invalid registration
     """
     self.data['password'] = '******'
     form = RegistrationForm(data=self.data)
     self.assertFalse(form.is_valid())
Пример #2
0
 def test_1_invalid_form(self):
     """
     Testing invalid registration
     """
     self.data['password'] = '******'
     form = RegistrationForm(data=self.data)
     self.assertFalse(form.is_valid())
Пример #3
0
def registration(request):
    user = request.user
    if (user.is_authenticated() and user.is_active):
        return HttpResponseRedirect(reverse(DEFAULT_REDIRECT))
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            auth_key = md5(str(datetime.datetime.now())).hexdigest()
            send_data = form.cleaned_data
            ### Отправка письма
            data = {
                'domain':request.META['HTTP_HOST'],
                'auth_key':auth_key,
            }
            t = loader.get_template('account_registration_mail.html')
            c = RequestContext(request, data)
            html = t.render(c)
            msg = EmailMessage(_(u'Регистрация на сайте - Studiogen'), html, EMAIL_FROM, [send_data['email']])
            msg.content_subtype = "html"
            msg.send()
            new_user = User.objects.create_user(
                username = send_data['email'],
                email = send_data['email'],
                password = send_data['password']
            )
            new_user.is_active = False
            new_user.save()
            UserProfile.objects.filter(user=new_user.id).update(
                auth_key=auth_key,
                name=send_data['name'],
                address=send_data['address'],
                phone=send_data['phone']
            )
            messages.success(request, _(u'На указанный email выслано письмо с кодом подтверждения регистрации'))
            return HttpResponseRedirect(reverse(DEFAULT_REDIRECT))
    else:
        initial = {
            'name': request.session.get('name', ''),
            'address': request.session.get('address', ''),
            'phone': request.session.get('phone', ''),
        }
        form = RegistrationForm(initial=initial)
    data = {
        'form': form,
    }
    return render(request, 'account_registration_form.html', data)
Пример #4
0
def registration_view(request):
    context = {}
    if request.POST:
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            email = form.cleaned_data.get('email')
            raw_password = form.cleaned_data.get('password1')
            account = authenticate(email=email, password=raw_password)
            login(request, account)
            return redirect('home')
        else:
            context['registration_form'] = form
    else:
        form = RegistrationForm()
        context['registration_form'] = form
    return render(request, 'account/register.html', context)
Пример #5
0
 def test_0_valid_form(self):
     """
     Testing valid registration
     """
     form = RegistrationForm(data=self.data)
     self.assertTrue(form.is_valid())
Пример #6
0
 def test_0_valid_form(self):
     """
     Testing valid registration
     """
     form = RegistrationForm(data=self.data)
     self.assertTrue(form.is_valid())