Skip to content

Backend production #27

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

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
feefb3f
Initialized django project in backend folder.
Akshath-Mahajan Jan 31, 2021
dca6004
Merge pull request #4 from Akshath-Mahajan/backend
havanoor Jan 31, 2021
a2e71fa
User model created
Jinay01 Feb 1, 2021
db738ff
Merge pull request #6 from Jinay01/backend
Thakur-Govind Feb 2, 2021
129c6bd
Authentication Api Created and also add ApiList.txt file
Chriscorr27 Feb 8, 2021
07a34ed
requirements.txt file updated
Chriscorr27 Feb 8, 2021
476cbde
Merge pull request #8 from Chriscorr27/backend
havanoor Feb 13, 2021
1007691
Added custom contexts for all djoser emails
Akshath-Mahajan Feb 14, 2021
b53f6bb
Merge pull request #9 from Akshath-Mahajan/backend
Thakur-Govind Feb 14, 2021
9ae65bd
Merge pull request #1 from djunicode/backend
Chriscorr27 Feb 15, 2021
e046fbe
Added profile creation to user registration
Akshath-Mahajan Feb 15, 2021
9b2f245
Merge branch 'backend' of https://github.com/djunicode/Transcript-web…
Akshath-Mahajan Feb 15, 2021
4a5ff46
Merge pull request #10 from Akshath-Mahajan/backend
Thakur-Govind Feb 15, 2021
a923794
Merge pull request #2 from djunicode/backend
Chriscorr27 Feb 16, 2021
bc2dde0
update profile
Jinay01 Feb 18, 2021
2628bd7
Application Model Created
Chriscorr27 Feb 18, 2021
c809131
Merge branch 'backend' of https://github.com/Chriscorr27/Transcript-w…
Chriscorr27 Feb 18, 2021
0abc4b2
Made Model changes
Chriscorr27 Feb 18, 2021
a2d7ec9
Merge pull request #11 from Jinay01/backend
havanoor Feb 19, 2021
e4c95b2
Merge pull request #3 from djunicode/backend
Chriscorr27 Feb 22, 2021
256e33a
removed demo app
Chriscorr27 Feb 22, 2021
b1bdb84
Added management dashboard endpoints
Akshath-Mahajan Feb 22, 2021
bae6074
Merge pull request #14 from Akshath-Mahajan/backend
Thakur-Govind Feb 22, 2021
3c16bcd
added media_url and Media_root
Chriscorr27 Feb 22, 2021
d8a61ed
Created Student Dashboard Apis
Chriscorr27 Feb 23, 2021
109fca8
Merge branch 'backend' of https://github.com/Chriscorr27/Transcript-w…
Chriscorr27 Feb 23, 2021
5e7c6cd
swagger setup
Jinay01 Mar 2, 2021
02bdaff
Merge pull request #15 from Chriscorr27/backend
havanoor Mar 2, 2021
ed9863b
changed student urls and add get request to marks
Chriscorr27 Mar 2, 2021
cdfa71d
Merge pull request #17 from Chriscorr27/backend
havanoor Mar 2, 2021
350c91c
swagger setup
Jinay01 Mar 2, 2021
2abb837
swagger
Jinay01 Mar 2, 2021
bf4d4af
Merge pull request #18 from Jinay01/backend
havanoor Mar 3, 2021
1be9ef2
heroku settings
Jinay01 Apr 11, 2021
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,6 @@ venv.bak/
.pyre/
# VS Code settings
.vscode

# Backend gitignore
/backend/.gitignore
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn Transcripts.wsgi --log-file -
66 changes: 66 additions & 0 deletions backend/ApiList.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
1) User creation
request :- http://127.0.0.1:8000/account/auth/users/
type :- POST
inputs :- {
"email":"",
"is_management":,
"password":"",
"re_password":""
}
output :- {
"is_management": ,
"email": "",
"id":
}

2) User Activation
request :- http://127.0.0.1:8000/account/auth/users/activation/
type :- POST
Send a mail on given email
http://127.0.0.1:8000/activate/(uid)/{token}
inputs :- {
"uid":"",
"token":""
}

3) User Login using JWT
request :- http://127.0.0.1:8000/account/auth/jwt/create/
type :- POST
inputs :- {
"email":"",
"password":""
}
output :- {
"refresh": "",
"access": ""
}

4) User info
request :- http://127.0.0.1:8000/account/auth/me/
type :- Get
output :- {
"email": "",
"is_management": ,
"profile_created":
}

5) User Reset password
request :- http://127.0.0.1:8000/account/auth/users/reset_password/
type :- POST
inputs :- {
"email":""
}
output :- send a mail on given email
http://127.0.0.1:8000/password/reset/confirm/{uid}/{token}


6) Confirm Reset Password
request :- http://127.0.0.1:8000/account/auth/users/reset_password_confirm/
type :- POST
inputs :- {
"uid":"",
"token":"",
"new_password":"",
"re_new_password":""
}

Empty file added backend/Transcripts/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions backend/Transcripts/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for Transcripts 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', 'Transcripts.settings')

application = get_asgi_application()
201 changes: 201 additions & 0 deletions backend/Transcripts/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
"""
Django settings for Transcripts 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
from decouple import config
import os

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

config.encoding = "cp1251"
# 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 = config("SECRET_KEY")


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

ALLOWED_HOSTS = []
if DEBUG:
ALLOWED_HOSTS = ["*"]

# Application definition

INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
# apps
"rest_framework",
"djoser",
"accounts",
"core",
# swagger
"corsheaders",
"drf_yasg",
]

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 = "Transcripts.urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"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 = "Transcripts.wsgi.application"

# Email Setup

EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_PORT = 587
EMAIL_HOST_USER = config("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = config("EMAIL_HOST_PASSWORD")
EMAIL_USE_TLS = True

# 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_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = "/static/"

MEDIA_URL = "/"
MEDIA_ROOT = os.path.join(BASE_DIR, "Images")


AUTH_USER_MODEL = "accounts.AppUser"
# to check if user has profile
# AUTH_PROFILE_MODEL = 'accounts.modelname'

# simple jwt setup

SIMPLE_JWT = {
"AUTH_HEADER_TYPES": ("Bearer",),
}


# REST FRAMEWORK SETUP

REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework_simplejwt.authentication.JWTAuthentication",
),
}

FRONTEND_DOMAIN = "www.abc.com"
# DJOSER SETUP
DJOSER = {
"LOGIN_FIELD": "email",
"PASSWORD_RESET_CONFIRM_URL": "password/reset/confirm/{uid}/{token}",
"ACTIVATION_URL": "activate/{uid}/{token}",
"SEND_ACTIVATION_EMAIL": True,
"SEND_CONFIRMATION_EMAIL": True,
"PASSWORD_CHANGED_EMAIL_CONFIRMATION": True,
"PASSWORD_RESET_CONFIRM_RETYPE": True,
"SEND_CONFIRMATION_EMAIL": True,
"USER_CREATE_PASSWORD_RETYPE": True,
"SET_PASSWORD_RETYPE": True,
"SERIALIZERS": {
"user_create": "accounts.serializers.UserCreateSerializer",
"user": "accounts.serializers.UserCreateSerializer",
"user_delete": "djoser.serializers.UserDeleteSerializer",
},
"EMAIL": {
"activation": "accounts.email.ActivationEmail",
"confirmation": "accounts.email.ConfirmationEmail",
"password_reset": "accounts.email.PasswordResetEmail",
"password_changed_confirmation": "accounts.email.PasswordChangedConfirmationEmail",
"username_changed_confirmation": "accounts.email.UsernameChangedConfirmationEmail",
"username_reset": "accounts.email.UsernameResetEmail",
},
}

# swagger
SWAGGER_SETTINGS = {
"SECURITY_DEFINITIONS": {
"Bearer": {"type": "apiKey", "name": "Authorization", "in": "header"}
},
"REFETCH_SCHEMA_WITH_AUTH": True,
}

STATICFILES_STORAGE = "whitenoise.django.GzipManifestStaticFilesStorage"
60 changes: 60 additions & 0 deletions backend/Transcripts/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Transcripts URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.conf.urls.static import static
from django.conf import settings
from django.contrib import admin
from django.urls import path, include

# swagger
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi

schema_view = get_schema_view(
openapi.Info(
title="APP API",
default_version="v1",
description="Test description",
terms_of_service="https://www.ourapp.com/policies/terms/",
contact=openapi.Contact(email="[email protected]"),
license=openapi.License(name="Test License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
)


urlpatterns = [
path("admin/", admin.site.urls),
path("api/", include("accounts.urls")),
path("api/", include("core.urls")),
# swagger
path("", schema_view.with_ui("swagger", cache_timeout=0),
name="schema-swagger-ui"),
path(
"api/api.json/",
schema_view.without_ui(cache_timeout=0),
name="schema-swagger-ui",
),
path("redoc/", schema_view.with_ui("redoc",
cache_timeout=0), name="schema-redoc"),
]
urlpatterns = urlpatterns + static(
settings.MEDIA_URL, document_root=settings.MEDIA_ROOT
)

# urlpatterns += [re_path(r'^(?!api/).*', TemplateView.as_view(template_name="index.html"))] for react in prod if deploying on same server
18 changes: 18 additions & 0 deletions backend/Transcripts/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
WSGI config for Transcripts 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/3.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise

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

application = get_wsgi_application()
application = DjangoWhiteNoise(application)
Empty file added backend/accounts/__init__.py
Empty file.
Loading