-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8aee2d7
Showing
38 changed files
with
371 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
env | ||
**/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Django==2.2.5 | ||
pytz==2019.2 | ||
sqlparse==0.3.0 |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AccountsConfig(AppConfig): | ||
name = 'accounts' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django import forms | ||
from django.contrib.auth.forms import UserCreationForm | ||
from django.contrib.auth.models import User | ||
|
||
|
||
class SignUpForm(UserCreationForm): | ||
email = forms.EmailField(max_length=200, help_text='Required') | ||
|
||
class Meta: | ||
model = User | ||
fields = ('username', 'email', 'password1', 'password2') |
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% autoescape off %} | ||
Hi {{ user.username }}, | ||
Please click on the link to confirm your registration, | ||
http://{{ domain }}{% url 'activate' uidb64=uid token=token %} | ||
{% endautoescape %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<div class="content-section"> | ||
<form class="login-form" method="post"> | ||
{% csrf_token %} | ||
<fieldset> | ||
<legend class="border-bottom mb-4">Login</legend> | ||
{{ form }} | ||
</fieldset> | ||
<div class="form-group"> | ||
<button class="btn btn-outline-info" type="submit" name="submit">Login</button> | ||
</div> | ||
</form> | ||
<div class="border-top pt-3"> | ||
<small> | ||
Need An Account? <a class="ml-2" href="{% url 'signup' %}">Signup</a> | ||
</small> | ||
</div> | ||
</div> |
3 changes: 3 additions & 0 deletions
3
website/accounts/templates/accounts/password-reset-complete.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="alert alert-info"> | ||
your password is reset. | ||
</div> |
17 changes: 17 additions & 0 deletions
17
website/accounts/templates/accounts/password-reset-confirm.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<div class="content-section"> | ||
<form class="password_reset-form" method="post"> | ||
{% csrf_token %} | ||
<fieldset> | ||
<legend class="border-bottom mb-4">Reset Password</legend> | ||
{{ form }} | ||
</fieldset> | ||
<div class="form-group"> | ||
<button class="btn btn-outline-info" type="submit" name="submit">Reset Password</button> | ||
</div> | ||
</form> | ||
<div class="border-top pt-3"> | ||
<small> | ||
Need An Account? <a class="ml-2" href="#" | ||
</small> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="alert alert-info"> | ||
An email has been sent. Please click on the link to reset your password | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<div class="content-section"> | ||
<form class="password_reset-form" method="post"> | ||
{% csrf_token %} | ||
<fieldset> | ||
<legend class="border-bottom mb-4">Reset Password</legend> | ||
{{ form }} | ||
</fieldset> | ||
<div class="form-group"> | ||
<button class="btn btn-outline-info" type="submit" name="submit">Reset Password</button> | ||
</div> | ||
</form> | ||
<div class="border-top pt-3"> | ||
<small> | ||
Need An Account? <a class="ml-2" href="#" | ||
</small> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{% block content %} | ||
<h2>Sign up</h2> | ||
<form method="post"> | ||
{% csrf_token %} | ||
{% for field in form %} | ||
<p> | ||
{{ field.label_tag }}<br> | ||
{{ field }} | ||
{% if field.help_text %} | ||
<small style="display: none">{{ field.help_text }}</small> | ||
{% endif %} | ||
{% for error in field.errors %} | ||
<p style="color: red">{{ error }}</p> | ||
{% endfor %} | ||
</p> | ||
{% endfor %} | ||
<button type="submit">Sign up</button> | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.contrib.auth.tokens import PasswordResetTokenGenerator | ||
from django.utils import six | ||
|
||
|
||
class TokenGenerator(PasswordResetTokenGenerator): | ||
def _make_hash_value(self, user, timestamp): | ||
return( | ||
six.text_type(user.pk) + six.text_type(timestamp) + | ||
six.text_type(user.is_active) | ||
) | ||
|
||
|
||
account_activation_token = TokenGenerator() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from django.urls import path | ||
from django.conf.urls import url | ||
from django.contrib.auth.views import ( | ||
LoginView, PasswordResetView, PasswordResetDoneView, | ||
PasswordResetConfirmView, PasswordResetCompleteView | ||
) | ||
from . import views | ||
|
||
|
||
urlpatterns = [ | ||
url(r'^signup/$', views.signup, name='signup'), | ||
url(r'^activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', | ||
views.activate, name='activate'), | ||
path('login/', LoginView.as_view(template_name='accounts/login.html'), name='login'), | ||
path( | ||
'password-reset/', | ||
PasswordResetView.as_view(template_name='accounts/password-reset.html'), | ||
name='password_reset' | ||
), | ||
path( | ||
'password-reset/done/', | ||
PasswordResetDoneView.as_view(template_name='accounts/password-reset-done.html'), | ||
name='password_reset_done' | ||
), | ||
path( | ||
'password-reset-confirm/<uidb64>/<token>/', | ||
PasswordResetConfirmView.as_view(template_name='accounts/password-reset-confirm.html'), | ||
name='password_reset_confirm' | ||
), | ||
path( | ||
'password-reset-complete', | ||
PasswordResetCompleteView.as_view(template_name='accounts/password-reset-complete.html'), | ||
name='password_reset_complete' | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from django.http import HttpResponse | ||
from django.shortcuts import render, redirect | ||
from .forms import SignUpForm | ||
from django.contrib.sites.shortcuts import get_current_site | ||
from django.utils.encoding import force_bytes, force_text | ||
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode | ||
from django.template.loader import render_to_string | ||
from .tokens import account_activation_token | ||
from django.contrib.auth.models import User | ||
from django.core.mail import EmailMessage | ||
|
||
|
||
def signup(request): | ||
if request.method == 'POST': | ||
form = SignUpForm(request.POST) | ||
if form.is_valid(): | ||
user = form.save(commit=False) | ||
user.is_active = False | ||
user.save() | ||
current_site = get_current_site(request) | ||
mail_subject = 'Activate your blog account' | ||
message = render_to_string( | ||
'accounts/acc_active_email.html', { | ||
'user': user, | ||
'domain': current_site.domain, | ||
'uid': urlsafe_base64_encode(force_bytes(user.pk)), | ||
'token': account_activation_token.make_token(user), | ||
}) | ||
to_email = form.cleaned_data.get('email') | ||
email = EmailMessage( | ||
mail_subject, message, to=[to_email] | ||
) | ||
email.send() | ||
return HttpResponse('Please confirm your email address to complete teh registration') | ||
else: | ||
form = SignUpForm() | ||
return render(request, 'accounts/signup.html', {'form':form}) | ||
|
||
|
||
def activate(request, uidb64, token): | ||
try: | ||
uid = force_text(urlsafe_base64_decode(uidb64)) | ||
user = User.objects.get(pk=uid) | ||
except(TypeError, ValueError, OverflowError, User.DoesNotExist): | ||
user = None | ||
if user is not None and account_activation_token.check_token(user, token): | ||
user.is_active = True | ||
user.save() | ||
login(request, user) | ||
return HttpResponse('Thank you for your email confirmation. Now you can login your account.') | ||
else: | ||
return HttpResponse('Activation link is invalid!') |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python | ||
"""Django's command-line utility for administrative tasks.""" | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website.settings') | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) from exc | ||
execute_from_command_line(sys.argv) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import os | ||
|
||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = '@mphmw*9dq_z+lth)k5+z1hen4)&o%0(9dsiy5w(aes@_^1n_=' | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = True | ||
|
||
ALLOWED_HOSTS = [] | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = [ | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
'accounts.apps.AccountsConfig', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
'django.middleware.security.SecurityMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
] | ||
|
||
ROOT_URLCONF = 'website.urls' | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': ['templates'], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
WSGI_APPLICATION = 'website.wsgi.application' | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | ||
} | ||
} | ||
|
||
|
||
# Password validation | ||
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators | ||
|
||
AUTH_PASSWORD_VALIDATORS = [ | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', | ||
}, | ||
] | ||
|
||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/2.2/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/2.2/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' | ||
|
||
EMAIL_USE_TLS = True | ||
EMAIL_HOST = 'smtp.gmail.com' | ||
EMAIL_HOST_USER = '[email protected]' | ||
EMAIL_HOST_PASSWORD = 'your_password_or_app_password' | ||
EMAIL_PORT = 587 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.contrib import admin | ||
from django.urls import include, path | ||
|
||
urlpatterns = [ | ||
path('accounts/', include('accounts.urls')), | ||
path('admin/', admin.site.urls), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
WSGI config for website project. | ||
It exposes the WSGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website.settings') | ||
|
||
application = get_wsgi_application() |