Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions geekshop/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions geekshop/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified geekshop/adminapp/__pycache__/views.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file modified geekshop/authapp/__pycache__/forms.cpython-37.pyc
Binary file not shown.
Binary file modified geekshop/authapp/__pycache__/models.cpython-37.pyc
Binary file not shown.
Binary file modified geekshop/authapp/__pycache__/urls.cpython-37.pyc
Binary file not shown.
Binary file modified geekshop/authapp/__pycache__/views.cpython-37.pyc
Binary file not shown.
14 changes: 13 additions & 1 deletion geekshop/authapp/forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import hashlib, random

from django import forms
from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
from .models import ShopUser
Expand Down Expand Up @@ -34,6 +36,15 @@ def clean_age(self):

return data

def save(self):
user = super(ShopUserRegisterForm, self).save()

user.is_active = False
salt = hashlib.sha1(str(random.random()).encode('utf8')).hexdigest()[:6]
user.activation_key = hashlib.sha1((user.email + salt).encode('utf8')).hexdigest()
user.save()

return user

class ShopUserEditForm(UserChangeForm):
class Meta:
Expand All @@ -53,4 +64,5 @@ def clean_age(self):
if data < 18:
raise forms.ValidationError("Вы слишком молоды!")

return data
return data

30 changes: 30 additions & 0 deletions geekshop/authapp/migrations/0002_auto_20200507_1500.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 2.2 on 2020-05-07 12:00

import datetime
from django.db import migrations, models
from django.utils.timezone import utc


class Migration(migrations.Migration):

dependencies = [
('authapp', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='shopuser',
name='activation_key',
field=models.CharField(blank=True, max_length=128),
),
migrations.AddField(
model_name='shopuser',
name='activation_key_expires',
field=models.DateTimeField(default=datetime.datetime(2020, 5, 9, 12, 0, 34, 568962, tzinfo=utc)),
),
migrations.AlterField(
model_name='shopuser',
name='last_name',
field=models.CharField(blank=True, max_length=150, verbose_name='last name'),
),
]
Binary file not shown.
14 changes: 13 additions & 1 deletion geekshop/authapp/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
from datetime import timedelta

from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils.timezone import now


class ShopUser(AbstractUser):
avatar = models.ImageField(upload_to='users_avatars', blank=True)
age = models.PositiveIntegerField(verbose_name = 'возраст')
age = models.PositiveIntegerField(verbose_name = 'возраст')
activation_key = models.CharField(max_length=128, blank=True)
activation_key_expires = models.DateTimeField( default=(now() + timedelta(hours=48)))


def is_activation_key_expired(self):
if now() <= self.activation_key_expires:
return False
else:
return True
18 changes: 18 additions & 0 deletions geekshop/authapp/templates/authapp/verification.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends 'authapp/base.html' %}
{% load staticfiles %}

{% block content %}

{% if user %}
<h3>Поздравляем!</h3>
<br>
<h4>Пользователь {{user.username}} подтвержден.</h4>
{% else %}
<h3>Верификация не пройдена.</h3>
{% endif %}
<br>
<button class="btn btn-round form-control">
<a href="{% url 'main' %}" class="">на главную</a>
</button>

{% endblock %}
11 changes: 6 additions & 5 deletions geekshop/authapp/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from django.urls import path
from django.urls import path, re_path

import authapp.views as authapp

app_name = 'authapp'

urlpatterns = [
path('login/', authapp.login, name='login'),
path('logout/', authapp.logout, name='logout'),
path('register/', authapp.register, name='register'),
path('edit/', authapp.edit, name='edit'),
re_path('login/', authapp.login, name='login'),
re_path('logout/', authapp.logout, name='logout'),
re_path('register/', authapp.register, name='register'),
re_path('edit/', authapp.edit, name='edit'),
re_path(r'^verify/(?P<email>.+)/(?P<activation_key>\w+)/$', authapp.verify, name='verify'),
]
50 changes: 49 additions & 1 deletion geekshop/authapp/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from django.conf import settings
from django.core.mail import send_mail
from django.shortcuts import render, HttpResponseRedirect
from authapp.forms import ShopUserLoginForm, ShopUserRegisterForm
from django.contrib import auth
from django.urls import reverse

from authapp.forms import ShopUserEditForm
from authapp.models import ShopUser


def login(request):
title = 'вход'
Expand Down Expand Up @@ -70,4 +74,48 @@ def edit(request):

content = {'title': title, 'edit_form': edit_form}

return render(request, 'authapp/edit.html', content)
return render(request, 'authapp/edit.html', content)


def send_verify_mail(user):
verify_link = reverse('auth:verify', args=[user.email, user.activation_key])

title = f'Подтверждение учетной записи {user.username}'

message = f'Для подтверждения учетной записи {user.username} на портале \
{settings.DOMAIN_NAME} перейдите по ссылке: \n{settings.DOMAIN_NAME}{verify_link}'

return send_mail(title, message, settings.EMAIL_HOST_USER, [user.email], fail_silently=False)

def register(request):
title = 'регистрация'

if request.method == 'POST':
register_form = ShopUserRegisterForm(request.POST, request.FILES)
if register_form.is_valid():
user = register_form.save()
if send_verify_mail(user):
print('сообщение подтверждения отправлено')
return HttpResponseRedirect(reverse('auth:login'))
else:
print('ошибка отправки сообщения')
return HttpResponseRedirect(reverse('auth:login'))
else:
register_form = ShopUserRegisterForm()
content = {'title': title, 'register_form': register_form}
return render(request, 'authapp/register.html', content)

def verify(request, email, activation_key):
try:
user = ShopUser.objects.get(email=email)
if user.activation_key == activation_key and not user.is_activation_key_expired():
user.is_active = True
user.save()
auth.login(request, user)
return render(request, 'authapp/verification.html')
else:
print(f'error activation user: {user}')
return render(request, 'authapp/verification.html')
except Exception as e:
print(f'error activation user : {e.args}')
return HttpResponseRedirect(reverse('main'))
Binary file modified geekshop/basketapp/__pycache__/urls.cpython-37.pyc
Binary file not shown.
Binary file modified geekshop/db.sqlite3
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UNKNOWN


Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) Django Software Foundation and individual contributors.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of Django nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Metadata-Version: 2.0
Name: Django
Version: 2.0
Summary: A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
Home-page: https://www.djangoproject.com/
Author: Django Software Foundation
Author-email: [email protected]
License: BSD
Description-Content-Type: UNKNOWN
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: pytz
Provides-Extra: argon2
Requires-Dist: argon2-cffi (>=16.1.0); extra == 'argon2'
Provides-Extra: bcrypt
Requires-Dist: bcrypt; extra == 'bcrypt'

UNKNOWN


Loading