confirm email, no login without confirming

remotes/origin/yandex
okt 12 years ago
parent 86a6333495
commit 6d93862fb2
  1. 2
      project/customer/consts.py
  2. 2
      project/customer/forms.py
  3. 8
      project/customer/models.py
  4. 13
      project/customer/views/license.py
  5. 2
      project/myauth/forms.py
  6. 25
      project/myauth/views.py
  7. 2
      project/settings.py
  8. 2
      project/templates/customer/index.html
  9. 3
      project/templates/customer/profile/license_list.html
  10. 3
      project/templates/customer/profile/paid_list.html

@ -9,6 +9,7 @@ PROFILE_TYPES = (
) )
LICENSE_STATUSES = ( LICENSE_STATUSES = (
(-1, u'Пробный период'),
(0, u'Не оплачен'), (0, u'Не оплачен'),
(1, u'Оплачен'), (1, u'Оплачен'),
(2, u'Активирован'), (2, u'Активирован'),
@ -16,6 +17,7 @@ LICENSE_STATUSES = (
) )
PAYFORMS = ( PAYFORMS = (
(-1, u'Бесплатно'),
(0, u'Безналичный расчёт'), (0, u'Безналичный расчёт'),
(1, u'Робокасса'), (1, u'Робокасса'),
(2, u'Квитанция Сбербанка'), (2, u'Квитанция Сбербанка'),

@ -417,6 +417,6 @@ class LicenseForm(forms.Form):
""" """
term = forms.ModelChoiceField(queryset=models.LicensePrice.objects.all(), term = forms.ModelChoiceField(queryset=models.LicensePrice.objects.all(),
widget=forms.RadioSelect, label='срок оплаты', empty_label = None) 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='форма оплаты') label='форма оплаты')

@ -138,6 +138,14 @@ class UserProfile(models.Model):
def is_org(self): def is_org(self):
return self.profile_type == consts.ORG_PROFILE 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): def get_company_name(self):
"""`ИП ФИО` или `Название Организации`.""" """`ИП ФИО` или `Название Организации`."""
if self.profile_type == consts.IP_PROFILE: if self.profile_type == consts.IP_PROFILE:

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.shortcuts import render from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.views.decorators.csrf import csrf_protect from django.views.decorators.csrf import csrf_protect
from ..models import License, LicensePrice from ..models import License, LicensePrice
@ -23,9 +24,11 @@ def order_license(request):
new_license = License(user=request.user, new_license = License(user=request.user,
term=form.cleaned_data['term'].term, term=form.cleaned_data['term'].term,
payform=form.cleaned_data['payform'], 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() new_license.save()
return redirect(reverse('customer_license_list'))
return render(request, template_name, dictionary) return render(request, template_name, dictionary)
@ -34,7 +37,7 @@ def license_list(request):
"""Список счетов на лицензии """Список счетов на лицензии
""" """
template_name = 'customer/profile/license_list.html' 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 = { dictionary = {
'licenses': licenses, 'licenses': licenses,
} }
@ -42,10 +45,10 @@ def license_list(request):
def paid_list(request): def paid_list(request):
"""Список счетов на лицензии """Оплаченные лицензии
""" """
template_name = 'customer/profile/paid_list.html' 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 = { dictionary = {
'licenses': licenses, 'licenses': licenses,
} }

@ -155,6 +155,8 @@ class LoginForm(forms.Form):
if self.user_cache: if self.user_cache:
if not self.user_cache.is_active: if not self.user_cache.is_active:
set_field_error(self, 'email', u'Пользователь заблокирован.') set_field_error(self, 'email', u'Пользователь заблокирован.')
if not self.user_cache.profile.active:
set_field_error(self, 'email', u'E-mail не подтверждён.')
else: else:
set_field_error(self, 'password', u'Неверное сочетание e-mail / пароль.') set_field_error(self, 'password', u'Неверное сочетание e-mail / пароль.')
except User.DoesNotExist: except User.DoesNotExist:

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import hashlib import hashlib
from datetime import datetime
from dateutil.relativedelta import relativedelta
from random import random from random import random
from django.shortcuts import render, redirect, get_object_or_404 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.contrib import messages
from django.conf import settings 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 from . import forms, models, emails
@ -36,7 +38,7 @@ def _create_user(request, **kwargs):
models.ConfirmEmail.objects.unconfirm(user) models.ConfirmEmail.objects.unconfirm(user)
# аутентифицировать и залогинить # аутентифицировать и залогинить
new_user = auth.authenticate(username=username, password=password) new_user = auth.authenticate(username=username, password=password)
auth.login(request, new_user) #auth.login(request, new_user)
return new_user return new_user
@ -59,7 +61,8 @@ def register(request):
form_class = forms.RegistrationForm form_class = forms.RegistrationForm
form_prefix = 'register' form_prefix = 'register'
template_name = 'myauth/register.html' template_name = 'myauth/register.html'
success_url = 'customer_profile_edit' success_url = 'myauth_login'
success_msg = u'Дождитесь письма на указанный Вами адрес и перейдите по ссылке в письме.'
registration_closed_url = 'myauth_registration_closed' registration_closed_url = 'myauth_registration_closed'
if not REGISTRATION_OPEN: if not REGISTRATION_OPEN:
@ -71,6 +74,7 @@ def register(request):
new_user = _create_user(request, **form.cleaned_data) new_user = _create_user(request, **form.cleaned_data)
confirm_url = reverse('myauth_confirm_email', args=[new_user.username,]) confirm_url = reverse('myauth_confirm_email', args=[new_user.username,])
emails.send_registration_email(new_user.email, confirm_url) emails.send_registration_email(new_user.email, confirm_url)
messages.add_message(request, messages.INFO, success_msg)
return redirect(success_url) return redirect(success_url)
else: else:
form = form_class(prefix=form_prefix) form = form_class(prefix=form_prefix)
@ -81,12 +85,22 @@ def register(request):
@sensitive_variables() @sensitive_variables()
def confirm_registered_email(request, key): def confirm_registered_email(request, key):
"""Подтверждение зарегистрированного email.""" """Подтверждение зарегистрированного email."""
success_url = 'customer_profile_view' success_url = 'customer_profile_edit'
success_msg = u'E-mail подтверждён.' success_msg = u'E-mail подтверждён.'
user = get_object_or_404(User, username__iexact = key) # ключ = имя пользователя user = get_object_or_404(User, username__iexact = key) # ключ = имя пользователя
models.ConfirmEmail.objects.confirm(user) models.ConfirmEmail.objects.confirm(user)
messages.add_message(request, messages.INFO, success_msg) 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) return redirect(success_url)
@ -199,6 +213,9 @@ def login(request):
form = form_class(data=request.POST, prefix=form_prefix) form = form_class(data=request.POST, prefix=form_prefix)
if form.is_valid(): if form.is_valid():
auth.login(request, form.get_user()) 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) return redirect(success_url)
else: else:
form = form_class(prefix=form_prefix) form = form_class(prefix=form_prefix)

@ -214,7 +214,7 @@ REGISTRATION_OPEN = True
LOGIN_URL = '/user/login/' LOGIN_URL = '/user/login/'
SUPPORT_EMAIL = 'help@dokumentor.ru' SUPPORT_EMAIL = 'help@dokumentor.ru'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
PDF_FONTS_ROOT = path('pdf_fonts') PDF_FONTS_ROOT = path('pdf_fonts')
XLS_ROOT = path('xls_templates') XLS_ROOT = path('xls_templates')

@ -8,7 +8,7 @@
<a href="{% url 'customer_profile_view' %}">Реквизиты</a><br /><br /> <a href="{% url 'customer_profile_view' %}">Реквизиты</a><br /><br />
<a href="{% url 'customer_bank_accounts_list' %}">Расчётные счета</a><br /><br /> <a href="{% url 'customer_bank_accounts_list' %}">Расчётные счета</a><br /><br />
<a href="{% url 'customer_clients_list' %}">Контрагенты</a><br /><br /> <a href="{% url 'customer_clients_list' %}">Контрагенты</a><br /><br />
<a href="{% url 'customer_order_license' %}">Лицензии</a><br /><br /> <a href="{% url 'customer_license_list' %}">Лицензии</a><br /><br />
</div> </div>
<div style="float:left; margin-left: 40px; border-left: 1px solid; padding-left: 20px;"> <div style="float:left; margin-left: 40px; border-left: 1px solid; padding-left: 20px;">

@ -3,6 +3,9 @@
{% block title %}Купить лицензию{% endblock %} {% block title %}Купить лицензию{% endblock %}
{% block content %} {% block content %}
<a href="{% url 'customer_order_license' %}">Купить лицензию</a><br /><br />
<a href="{% url 'customer_paid_list' %}">Оплаченные лицензии</a><br /><br />
<h1>Выписанные счета</h1>
{% for license in licenses %} {% for license in licenses %}
<div> <div>
<div class='w100 left'>{{ license.id }}</div> <div class='w100 left'>{{ license.id }}</div>

@ -3,6 +3,9 @@
{% block title %}Купить лицензию{% endblock %} {% block title %}Купить лицензию{% endblock %}
{% block content %} {% block content %}
<a href="{% url 'customer_order_license' %}">Купить лицензию</a><br /><br />
<a href="{% url 'customer_license_list' %}">Все счета</a><br /><br />
<h1>История оплат</h1>
{% for license in licenses %} {% for license in licenses %}
<div> <div>
<div class='w100 left'>{{ license.paid_date }}</div> <div class='w100 left'>{{ license.paid_date }}</div>

Loading…
Cancel
Save