Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aayush_20bce7393(Second submission)-full #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions django-auth/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# Profile page with Authentication system

This is a Profile page with complete authentication in django including a homepage
signin/signup form with a profile page of user.



## Features

- Sing in /Sign up
- Welcome email on sign-in
- Track user by creating superuser for django administration
- Seperate profile page for each user.


## Installation

Install my-project

```bash
cd aayush_20bce7393
python manage.py migrate
python manage.py runserver
```

## Screenshots
## Main Home page
![App Screenshot](https://user-images.githubusercontent.com/41218074/131065643-9ec825e9-c87b-411f-953b-8f2d078dc5bd.png)
##
## Sign Up form
![App Screenshot](https://user-images.githubusercontent.com/41218074/131065889-178bb958-adb8-4df2-bd93-91bd75b8fb47.png)

##
## Sign In form
![App Screenshot](https://user-images.githubusercontent.com/41218074/131065981-b2af401a-9c0e-4dea-889e-2e16545a4920.png)

##
## Profile page for authenticated user
![App Screenshot](https://user-images.githubusercontent.com/41218074/131066068-5ade10cb-4637-4fee-9193-bd50ed77b7b6.png)


Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions django-auth/authentication/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions django-auth/authentication/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AuthenticationConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'authentication'
Empty file.
3 changes: 3 additions & 0 deletions django-auth/authentication/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions django-auth/authentication/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
14 changes: 14 additions & 0 deletions django-auth/authentication/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.contrib import admin
from django.urls import path,include
from . import views
from django.contrib.auth import views as auth_views

urlpatterns = [

path('',views.home,name="home"),
path('profile',views.profile,name="profile"),
path('signup',views.signup,name="signup"),
path('signin',views.signin,name="signin"),
path('signout',views.signout,name="signout"),

]
119 changes: 119 additions & 0 deletions django-auth/authentication/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
from django.contrib.auth import authenticate,login, logout
from django.http.response import HttpResponse
from django.shortcuts import redirect, render
from django.http import HttpResponse
from django.core.mail import send_mail
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib import messages
# Create your views here.


def home(request):
return render(request, "authentication/index.html")


def profile(request):
return redirect(profile)


def signup(request):



if request.method =='POST':
username = request.POST['username']
# fname = request.POST['fname']
# lname = request.POST['lname']
email = request.POST['email']
pass1 = request.POST['pass1']
pass2 = request.POST['pass2']

if User.objects.filter(username=username):
messages.error(request, "Username already exist! Please try some other username.")
return redirect('signup')

if User.objects.filter(email=email).exists():
messages.error(request, "Email Already Registered!!")
return redirect('signup')

if len(username)>20:
messages.error(request, "Username must be under 20 charcters!!")
return redirect('signup')

if pass1 != pass2:
messages.error(request, "Passwords didn't matched!!")
return redirect('signup')

if not username.isalnum():
messages.error(request, "Username must be Alpha-Numeric!!")
return redirect('signup')

myuser=User.objects.create_user(username,email,pass1)

# myuser.first_name=fname;
# myuser.last_name=lname;
messages.success(request,"Your account has been successfully created!")
myuser.save();


#! Welcome email

subject = "Welcome to Club Vit!!"
message = "Hello " + myuser.username + "!! \n" + "Welcome to Club Vit!! \nThank you for visiting and joining\n. We have also sent you a confirmation email, please confirm your email address. \n\nThanking You\nAayush Anand"
from_email = settings.EMAIL_HOST_USER
to_list = [myuser.email]
send_mail(subject, message, from_email, to_list, fail_silently=True)

return redirect('signin')


return render(request,"authentication/signup.html")


# # username = request.POST.get('username')
# username = request.POST['username']
# fname = request.POST['fname']
# lname = request.POST['lname']
# email = request.POST['email']
# pass1 = request.POST.get('pass1')
# pass2 = request.POST.get('pass2')
# #pass2 = request.POST['pass2']

# myuser = User.objects.create_user(username,email,pass1)
# myuser.first_name=fname;
# myuser.last_name=lname;

# myuser.save()
# messages.success(request,"Your account has been successfully created")

# return redirect('signin')



def signin(request):

if request.method=='POST':
username = request.POST['username']
pass1 = request.POST['pass1']

user = authenticate(username=username,password=pass1)

if user is not None:
login(request,user)
user_name = user.username
return render(request,"authentication/profile.html",{'username':user_name})

else:
messages.error(request,"Bad Credentials")
return redirect('signin')

return render(request,"authentication/signin.html")

def signout(request):
logout(request)
# messages.success(request,"logout:")
return redirect(home)



Binary file added django-auth/db.sqlite3
Binary file not shown.
22 changes: 22 additions & 0 deletions django-auth/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.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 added django-auth/mysite/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
Binary file added django-auth/mysite/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file added django-auth/mysite/__pycache__/wsgi.cpython-38.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions django-auth/mysite/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for mysite 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.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')

application = get_asgi_application()
138 changes: 138 additions & 0 deletions django-auth/mysite/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
"""
Django settings for mysite project.

Generated by 'django-admin startproject' using Django 3.2.6.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-!f1n*_ex6ste9&-b)@nzv$u#0zwppiqr(e)j&p(97@ncl)*c5!'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

STATICFILES_DIRS=["C:\WSOC-2021\python-web\static",]


# Application definition

INSTALLED_APPS = [
'mysite',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

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 = 'mysite.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 = 'mysite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/3.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/3.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/3.2/howto/static-files/

STATIC_URL = '/static/'

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = '************'
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
Loading