From 6d93862fb2fa93889d56488f8595eca91ae5b437 Mon Sep 17 00:00:00 2001 From: okt Date: Thu, 26 Jun 2014 11:13:05 +0300 Subject: [PATCH] confirm email, no login without confirming --- project/customer/consts.py | 2 ++ project/customer/forms.py | 2 +- project/customer/models.py | 8 ++++++ project/customer/views/license.py | 13 ++++++---- project/myauth/forms.py | 2 ++ project/myauth/views.py | 25 ++++++++++++++++--- project/settings.py | 2 +- project/templates/customer/index.html | 2 +- .../customer/profile/license_list.html | 3 +++ .../templates/customer/profile/paid_list.html | 3 +++ 10 files changed, 50 insertions(+), 12 deletions(-) diff --git a/project/customer/consts.py b/project/customer/consts.py index aec1308..3dde2f5 100644 --- a/project/customer/consts.py +++ b/project/customer/consts.py @@ -9,6 +9,7 @@ PROFILE_TYPES = ( ) LICENSE_STATUSES = ( + (-1, u'Пробный период'), (0, u'Не оплачен'), (1, u'Оплачен'), (2, u'Активирован'), @@ -16,6 +17,7 @@ LICENSE_STATUSES = ( ) PAYFORMS = ( + (-1, u'Бесплатно'), (0, u'Безналичный расчёт'), (1, u'Робокасса'), (2, u'Квитанция Сбербанка'), diff --git a/project/customer/forms.py b/project/customer/forms.py index 2b95571..5c06a8f 100644 --- a/project/customer/forms.py +++ b/project/customer/forms.py @@ -417,6 +417,6 @@ class LicenseForm(forms.Form): """ term = forms.ModelChoiceField(queryset=models.LicensePrice.objects.all(), widget=forms.RadioSelect, label='срок оплаты', empty_label = None) - payform = forms.ChoiceField(choices=consts.PAYFORMS, widget=forms.RadioSelect, + payform = forms.ChoiceField(choices=consts.PAYFORMS[1:], widget=forms.RadioSelect, label='форма оплаты') diff --git a/project/customer/models.py b/project/customer/models.py index 2273b9a..5c82640 100644 --- a/project/customer/models.py +++ b/project/customer/models.py @@ -138,6 +138,14 @@ class UserProfile(models.Model): def is_org(self): return self.profile_type == consts.ORG_PROFILE + def check_name_not_filled(self): + """`ИП ФИО` или `Название Организации`.""" + if self.is_ip(): + return self.get_boss_full_fio().strip() == '' + elif self.is_org(): + return self.name.strip() == '' + return False + def get_company_name(self): """`ИП ФИО` или `Название Организации`.""" if self.profile_type == consts.IP_PROFILE: diff --git a/project/customer/views/license.py b/project/customer/views/license.py index 638c729..fa8a4d5 100644 --- a/project/customer/views/license.py +++ b/project/customer/views/license.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- -from django.shortcuts import render +from django.shortcuts import render, redirect from django.contrib.auth.decorators import login_required +from django.core.urlresolvers import reverse from django.views.decorators.csrf import csrf_protect from ..models import License, LicensePrice @@ -23,9 +24,11 @@ def order_license(request): new_license = License(user=request.user, term=form.cleaned_data['term'].term, payform=form.cleaned_data['payform'], - pay_sum=form.cleaned_data['term'].price + pay_sum=form.cleaned_data['term'].price, + paid_date=form.cleaned_data['term'].price, ) new_license.save() + return redirect(reverse('customer_license_list')) return render(request, template_name, dictionary) @@ -34,7 +37,7 @@ def license_list(request): """Список счетов на лицензии """ template_name = 'customer/profile/license_list.html' - licenses = License.objects.filter(user=request.user) + licenses = License.objects.filter(user=request.user).order_by('-id') dictionary = { 'licenses': licenses, } @@ -42,10 +45,10 @@ def license_list(request): def paid_list(request): - """Список счетов на лицензии + """Оплаченные лицензии """ template_name = 'customer/profile/paid_list.html' - licenses = License.objects.filter(user=request.user, status__in=[1, 2, 3]) + licenses = License.objects.filter(user=request.user, status__in=[-1, 1, 2, 3]).order_by('-id') dictionary = { 'licenses': licenses, } diff --git a/project/myauth/forms.py b/project/myauth/forms.py index 81f6f10..66a0588 100644 --- a/project/myauth/forms.py +++ b/project/myauth/forms.py @@ -155,6 +155,8 @@ class LoginForm(forms.Form): if self.user_cache: if not self.user_cache.is_active: set_field_error(self, 'email', u'Пользователь заблокирован.') + if not self.user_cache.profile.active: + set_field_error(self, 'email', u'E-mail не подтверждён.') else: set_field_error(self, 'password', u'Неверное сочетание e-mail / пароль.') except User.DoesNotExist: diff --git a/project/myauth/views.py b/project/myauth/views.py index 83fd08d..18d167e 100644 --- a/project/myauth/views.py +++ b/project/myauth/views.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- import hashlib +from datetime import datetime +from dateutil.relativedelta import relativedelta from random import random from django.shortcuts import render, redirect, get_object_or_404 @@ -12,7 +14,7 @@ from django.contrib.auth.decorators import login_required from django.contrib import messages from django.conf import settings -from project.customer.models import UserProfile, UserProfileFilters +from project.customer.models import UserProfile, UserProfileFilters, License from . import forms, models, emails @@ -36,7 +38,7 @@ def _create_user(request, **kwargs): models.ConfirmEmail.objects.unconfirm(user) # аутентифицировать и залогинить new_user = auth.authenticate(username=username, password=password) - auth.login(request, new_user) + #auth.login(request, new_user) return new_user @@ -59,7 +61,8 @@ def register(request): form_class = forms.RegistrationForm form_prefix = 'register' template_name = 'myauth/register.html' - success_url = 'customer_profile_edit' + success_url = 'myauth_login' + success_msg = u'Дождитесь письма на указанный Вами адрес и перейдите по ссылке в письме.' registration_closed_url = 'myauth_registration_closed' if not REGISTRATION_OPEN: @@ -71,6 +74,7 @@ def register(request): new_user = _create_user(request, **form.cleaned_data) confirm_url = reverse('myauth_confirm_email', args=[new_user.username,]) emails.send_registration_email(new_user.email, confirm_url) + messages.add_message(request, messages.INFO, success_msg) return redirect(success_url) else: form = form_class(prefix=form_prefix) @@ -81,12 +85,22 @@ def register(request): @sensitive_variables() def confirm_registered_email(request, key): """Подтверждение зарегистрированного email.""" - success_url = 'customer_profile_view' + success_url = 'customer_profile_edit' success_msg = u'E-mail подтверждён.' user = get_object_or_404(User, username__iexact = key) # ключ = имя пользователя models.ConfirmEmail.objects.confirm(user) messages.add_message(request, messages.INFO, success_msg) + licenses = License.objects.filter(user=user) + if not licenses: + license = License(user=user, date_from=datetime.today(), + date_to=datetime.today() + relativedelta(days=44), + pay_sum=0, + term=0, + status=-1, payform=-1) + license.save() + user.profile.active = True + user.profile.save() return redirect(success_url) @@ -199,6 +213,9 @@ def login(request): form = form_class(data=request.POST, prefix=form_prefix) if form.is_valid(): auth.login(request, form.get_user()) + print request.user.profile.check_name_not_filled() + if request.user.profile.check_name_not_filled(): + success_url = 'customer_profile_edit' return redirect(success_url) else: form = form_class(prefix=form_prefix) diff --git a/project/settings.py b/project/settings.py index cc80756..39c6126 100644 --- a/project/settings.py +++ b/project/settings.py @@ -214,7 +214,7 @@ REGISTRATION_OPEN = True LOGIN_URL = '/user/login/' SUPPORT_EMAIL = 'help@dokumentor.ru' - +EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' PDF_FONTS_ROOT = path('pdf_fonts') XLS_ROOT = path('xls_templates') diff --git a/project/templates/customer/index.html b/project/templates/customer/index.html index 17bad2f..001515c 100644 --- a/project/templates/customer/index.html +++ b/project/templates/customer/index.html @@ -8,7 +8,7 @@ Реквизиты

Расчётные счета

Контрагенты

- Лицензии

+ Лицензии

diff --git a/project/templates/customer/profile/license_list.html b/project/templates/customer/profile/license_list.html index 242cf6e..23d1a94 100644 --- a/project/templates/customer/profile/license_list.html +++ b/project/templates/customer/profile/license_list.html @@ -3,6 +3,9 @@ {% block title %}Купить лицензию{% endblock %} {% block content %} +Купить лицензию

+Оплаченные лицензии

+

Выписанные счета

{% for license in licenses %}
{{ license.id }}
diff --git a/project/templates/customer/profile/paid_list.html b/project/templates/customer/profile/paid_list.html index 5027330..9d58da1 100644 --- a/project/templates/customer/profile/paid_list.html +++ b/project/templates/customer/profile/paid_list.html @@ -3,6 +3,9 @@ {% block title %}Купить лицензию{% endblock %} {% block content %} +Купить лицензию

+Все счета

+

История оплат

{% for license in licenses %}
{{ license.paid_date }}