-
Notifications
You must be signed in to change notification settings - Fork 1
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
Piyush Dive
committed
Jan 7, 2022
0 parents
commit f23b22f
Showing
98 changed files
with
5,036 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,5 @@ | ||
Pending Things: | ||
|
||
FB Login | ||
full-name in signup view | ||
signup fb login button |
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.
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 AuthenticationConfig(AppConfig): | ||
name = 'authentication' |
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,83 @@ | ||
from django import forms | ||
from django.contrib.auth.models import User | ||
from django.forms import fields, widgets | ||
from django.utils.translation import gettext_lazy as _ | ||
from django.contrib.auth import password_validation | ||
from django.core.exceptions import ValidationError | ||
from django.contrib.auth.forms import (AuthenticationForm, UsernameField, | ||
UserCreationForm, PasswordResetForm, SetPasswordForm) | ||
|
||
|
||
def ForbiddenUsers(value): | ||
forbidden_users = ['admin', 'css', 'js', 'authenticate', 'login', 'logout', 'administrator', 'root', | ||
'email', 'user', 'join', 'sql', 'static', 'python', 'delete'] | ||
if value.lower() in forbidden_users: | ||
raise ValidationError('Invalid name for user, this is a reserverd word.') | ||
|
||
def InvalidUser(value): | ||
if '@' in value or '+' in value or '-' in value: | ||
raise ValidationError('This is an Invalid username, Username may contain only letters, numbers, and ./_ characters.') | ||
|
||
def UniqueEmail(value): | ||
if User.objects.filter(email__iexact=value).exists(): | ||
raise ValidationError('User with this email already exists.') | ||
|
||
def UniqueUser(value): | ||
if User.objects.filter(username__iexact=value).exists(): | ||
raise ValidationError('User with this username already exists.') | ||
|
||
|
||
class SignUpForm(UserCreationForm): | ||
email = forms.CharField(widget=forms.EmailInput(attrs= | ||
{'class':'form-control shadow-none', 'autofocus':True, 'placeholder':'Email Address'})) | ||
|
||
full_name = forms.CharField(widget=forms.TextInput(attrs= | ||
{'class':'form-control shadow-none', 'placeholder':'Full Name'})) | ||
|
||
password1 = forms.CharField(widget=forms.PasswordInput(attrs= | ||
{'class':'form-control shadow-none', 'placeholder':'Password', | ||
'autocomplete':'current-password'})) | ||
|
||
password2 = forms.CharField(widget=forms.PasswordInput(attrs= | ||
{'class':'form-control shadow-none', 'placeholder':'Confirm Password', | ||
'autocomplete':'current-password'})) | ||
|
||
class Meta(): | ||
model = User | ||
fields = ['email','full_name', 'username', 'password1', 'password2'] | ||
widgets = {'username': forms.TextInput(attrs= | ||
{'class':'form-control shadow-none', | ||
'autofocus':False, 'placeholder':'Username'})} | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(SignUpForm, self).__init__(*args, **kwargs) | ||
self.fields['username'].validators.append(ForbiddenUsers) | ||
self.fields['username'].validators.append(InvalidUser) | ||
self.fields['username'].validators.append(UniqueUser) | ||
self.fields['email'].validators.append(UniqueEmail) | ||
|
||
|
||
class LoginForm(AuthenticationForm): | ||
username = UsernameField(widget=forms.TextInput(attrs= | ||
{'class':'form-control shadow-none', 'placeholder':'Username'})) | ||
|
||
password = forms.CharField(label=_("Password"), strip=False, | ||
widget=forms.PasswordInput(attrs={'autocomplete':'current-password', | ||
'class':'form-control shadow-none', 'placeholder':'Password'})) | ||
|
||
|
||
class PassResetForm(PasswordResetForm): | ||
email = forms.CharField(widget=forms.EmailInput(attrs= | ||
{'autofocus':True,'class':'form-control shadow-none', | ||
'autocomplete':'email', 'placeholder':'Email'})) | ||
|
||
|
||
class SetPassForm(SetPasswordForm): | ||
new_password1 = forms.CharField(strip=False, widget=forms.PasswordInput | ||
(attrs={'autocomplete':'new-password', | ||
'placeholder':'New Password', 'class':'form-control shadow-none pass-confirm'}), | ||
help_text=password_validation.password_validators_help_text_html()) | ||
|
||
new_password2 = forms.CharField(strip=False, widget=forms.PasswordInput | ||
(attrs={'autocomplete':'new-password', | ||
'placeholder':'Confirm New Password', 'class':'form-control shadow-none pass-confirm'})) |
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,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,30 @@ | ||
from django.contrib import auth | ||
from django.urls import path | ||
from . import views | ||
from .forms import LoginForm, PassResetForm, SetPassForm | ||
from django.contrib.auth import views as auth_views | ||
|
||
urlpatterns = [ | ||
path('signup/', views.signup_view, name='signup'), | ||
|
||
path('login/', auth_views.LoginView.as_view | ||
(template_name= 'auth/login.html', authentication_form=LoginForm), | ||
name='login'), | ||
|
||
path('password_reset/', auth_views.PasswordResetView.as_view | ||
(template_name='auth/pass_reset.html', form_class=PassResetForm), | ||
name='password_reset'), | ||
|
||
path('password_reset/done/', auth_views.PasswordResetDoneView.as_view | ||
(template_name='auth/pass_reset_done.html'), | ||
name='password_reset_done'), | ||
|
||
path('password_reset/confirm/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view | ||
(template_name='auth/pass_reset_confirm.html', form_class=SetPassForm), | ||
name='password_reset_confirm'), | ||
|
||
path('password_reset/complete/', auth_views.PasswordResetCompleteView.as_view | ||
(template_name='auth/pass_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,29 @@ | ||
from django.shortcuts import redirect, render | ||
from . import models | ||
from . import forms | ||
from django.contrib import messages | ||
from django.views.decorators.csrf import csrf_exempt | ||
|
||
@csrf_exempt | ||
def signup_view(request): | ||
if request.method == 'POST': | ||
form = forms.SignUpForm(request.POST) | ||
if form.is_valid(): | ||
user = form.save() | ||
full_name = form.cleaned_data['full_name'].split() | ||
|
||
if len(full_name) <= 1: | ||
empt_str ='' | ||
user.first_name = empt_str.join(full_name) | ||
|
||
else: | ||
fname = full_name[0] | ||
lname = full_name[1] | ||
user.first_name = fname | ||
user.last_name = lname | ||
user.save() | ||
messages.success(request, 'Successfully Signed in!') | ||
return redirect('login') | ||
else: | ||
form = forms.SignUpForm() | ||
return render(request, 'auth/signup.html', {'form':form}) |
Binary file not shown.
Empty file.
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 HomeConfig(AppConfig): | ||
name = 'home' |
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,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,7 @@ | ||
from django.urls import path, include | ||
from . import views | ||
from django.contrib.auth import views as auth_views | ||
|
||
urlpatterns = [ | ||
path('', views.home, name='home'), | ||
] |
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,4 @@ | ||
from django.shortcuts import render | ||
|
||
def home(request): | ||
return render(request, 'home/home.html') |
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,16 @@ | ||
""" | ||
ASGI config for insta_clone project. | ||
It exposes the ASGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'insta_clone.settings') | ||
|
||
application = get_asgi_application() |
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,133 @@ | ||
""" | ||
Django settings for insta_clone project. | ||
Generated by 'django-admin startproject' using Django 3.1.5. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/3.1/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/3.1/ref/settings/ | ||
""" | ||
|
||
from pathlib import Path | ||
import os | ||
|
||
# Build paths inside the project like this: BASE_DIR / 'subdir'. | ||
BASE_DIR = Path(__file__).resolve().parent.parent | ||
TEMPLATES_DIR = os.path.join(BASE_DIR, 'insta_clone/templates') | ||
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') | ||
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'insta_clone/static')] | ||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') | ||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = '%xt(h6j+00v_53-$xm=d%y-=bm%vq+_zt@@7@qks_6b+t=+yd0' | ||
|
||
# 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.staticfiles', | ||
'django.contrib.sites', | ||
'django.contrib.messages', | ||
'django.contrib.humanize', | ||
'authentication', | ||
'post', | ||
'home', | ||
] | ||
|
||
SITE_ID = 1 | ||
|
||
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 = 'insta_clone.urls' | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [TEMPLATES_DIR, MEDIA_ROOT], | ||
'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 = 'insta_clone.wsgi.application' | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': BASE_DIR / 'db.sqlite3', | ||
} | ||
} | ||
|
||
|
||
# Password validation | ||
# https://docs.djangoproject.com/en/3.1/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/3.1/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/3.1/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' | ||
MEDIA_URL = '/media/' | ||
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.