diff --git a/AlgoPhantomBackend/AlgoPhantomBackend/settings.py b/AlgoPhantomBackend/AlgoPhantomBackend/settings.py index 8063054..4c18b95 100644 --- a/AlgoPhantomBackend/AlgoPhantomBackend/settings.py +++ b/AlgoPhantomBackend/AlgoPhantomBackend/settings.py @@ -16,19 +16,9 @@ # 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/3.0/howto/deployment/checklist/ -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '*qh6y)st__^hvam8a@6ln5vz4+#_9qu$xl80oz%h9e71+-iutd' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [] - - # Application definition INSTALLED_APPS = [ @@ -38,15 +28,18 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'core.apps.CoreConfig', - 'rest_framework', - 'rest_framework.authtoken', - 'rest_auth', 'django.contrib.sites', + 'allauth', 'allauth.account', 'allauth.socialaccount', + + 'rest_framework', + 'rest_framework.authtoken', 'rest_auth.registration', + 'rest_auth', + + 'core.apps.CoreConfig', 'quiz', ] @@ -86,13 +79,6 @@ # Database # https://docs.djangoproject.com/en/3.0/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/3.0/ref/settings/#auth-password-validators @@ -132,15 +118,6 @@ STATIC_URL = '/static/' -ACCOUNT_UNIQUE_EMAIL = True -ACCOUNT_EMAIL_REQUIRED = True -ACCOUNT_AUTHENTICATION_METHOD = 'username' -ACCOUNT_USERNAME_REQUIRED = True -ACCOUNT_EMAIL_VERIFICATION = 'mandatory' -#ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS = False -#AUTH_USER_MODEL = 'core.User' - - REST_AUTH_SERIALIZERS = { 'TOKEN_SERIALIZER': 'core.serializers.TokenSerializer', 'USER_DETAILS_SERIALIZER': 'core.serializers.UserSerializer', @@ -158,10 +135,12 @@ ], } -EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' -EMAIL_HOST = 'smtp.gmail.com' -EMAIL_USE_TLS = True -EMAIL_PORT = 587 -EMAIL_HOST_USER = EMAIL_HOST_USER -EMAIL_HOST_PASSWORD = EMAIL_HOST_PASSWORD -DATA_UPLOAD_MAX_NUMBER_FIELDS = 10240 \ No newline at end of file +ACCOUNT_UNIQUE_EMAIL = True +ACCOUNT_EMAIL_REQUIRED = True +ACCOUNT_AUTHENTICATION_METHOD = 'username' +ACCOUNT_USERNAME_REQUIRED = True +ACCOUNT_EMAIL_VERIFICATION = 'mandatory' +#ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS = False +#AUTH_USER_MODEL = 'core.User' + +DATA_UPLOAD_MAX_NUMBER_FIELDS = 10240 diff --git a/AlgoPhantomBackend/AlgoPhantomBackend/urls.py b/AlgoPhantomBackend/AlgoPhantomBackend/urls.py index c45af91..acdd93a 100644 --- a/AlgoPhantomBackend/AlgoPhantomBackend/urls.py +++ b/AlgoPhantomBackend/AlgoPhantomBackend/urls.py @@ -15,8 +15,8 @@ """ from django.contrib import admin from django.urls import path, include -from rest_auth.registration.views import VerifyEmailView, RegisterView, LoginView from django.conf.urls import url +from rest_auth.registration.views import VerifyEmailView, RegisterView, LoginView urlpatterns = [ path('admin/', admin.site.urls), @@ -31,5 +31,4 @@ path('rest-auth/registration/', RegisterView.as_view(), name='account_signup'), path('rest-auth/account-confirm-email/', VerifyEmailView.as_view(),name='account_email_verification_sent'), url('rest-auth/account-confirm-email/(?P[-:\w]+)/$', VerifyEmailView.as_view(),name='account_confirm_email'), - ] diff --git a/AlgoPhantomBackend/core/views.py b/AlgoPhantomBackend/core/views.py index f5e93ca..ed7c1d6 100644 --- a/AlgoPhantomBackend/core/views.py +++ b/AlgoPhantomBackend/core/views.py @@ -1,9 +1,8 @@ from django.shortcuts import render, redirect, HttpResponse, get_object_or_404 from django.http import HttpResponseBadRequest, JsonResponse,HttpResponseRedirect from django.contrib.auth.models import User -# Create your views here. -def home(request): +def home(request): return HttpResponse('Hello') diff --git a/AlgoPhantomBackend/quiz/models.py b/AlgoPhantomBackend/quiz/models.py index 102c7d2..b3dbf61 100644 --- a/AlgoPhantomBackend/quiz/models.py +++ b/AlgoPhantomBackend/quiz/models.py @@ -1,24 +1,23 @@ from django.db import models -# Create your models here. + QUESTION_LEVEL = ( - ("Easy","Easy"), - ("Medium","Medium"), - ("Hard","Hard"), + ("Easy", "Easy"), + ("Medium", "Medium"), + ("Hard", "Hard"), ) - class Category(models.Model): - name=models.CharField(max_length=255) + name = models.CharField(max_length=255) def __str__(self): return self.name class Meta: - verbose_name= "Category" - verbose_name_plural= "Categories" - ordering=['id'] + verbose_name = "Category" + verbose_name_plural = "Categories" + ordering = ['id'] class Quizzes(models.Model): @@ -66,5 +65,3 @@ class Meta: verbose_name_plural= "Answers" ordering=['id'] - - diff --git a/README.md b/README.md index 5f6e710..60d236c 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,8 @@ 🚀 Give your DSA journey a proper guide using pathways in our application. ## 🛠 Tech Used -- Python -- Django -- Django REST Framework + +Python Django Django Rest Framework ## 💫 Quick Start @@ -55,6 +54,69 @@ python3 -m pip install -r requirements.txt ``` cd AlgoPhantomBackend ``` + +- *STEPS TO CREATE YOUR OWN local_settings.py file* + +local_settings.py is not present in github repo as it contains important credentials regarding project which should not be shared publicly. + + +1. Create new file named as local_settings.py just beside settings.py file in +same folder. +Now your project structure will look like + + +``` +ALGO-PHANTOMS-BACKEND # Project Name +| +├───AlgoPhantomBackend # Project Directory +| | +| . +| . +| ├──local_settings.py # [Created] +. . +. . +. +. +. +``` + +2. Copy paste this in local_settings.py file and change it accordingly. + +``` +import os + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +SECRET_KEY = 'any 50 digits long unique key with numbers alphabets symbols. anything' + +DEBUG = True + +ALLOWED_HOSTS = ['*'] + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + +EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' +EMAIL_HOST = 'smtp.gmail.com' +EMAIL_USE_TLS = True +EMAIL_PORT = 587 +EMAIL_HOST_USER = "Put your email id here" +EMAIL_HOST_PASSWORD = "put your email app password generated here." +``` + +3. Dont know how to generate app password for email. check out this blog and set it up accordingly. DO NOT SHARE IT WITH ANYONE. +#### https://support.google.com/accounts/answer/185833?hl=en + +4. If you are not able to setup this EMAIL_HOST_PASSWORD you can comment that for +testing purpose. But knowing how to do this is very useful in order to send +automated emails via contact form or for accont creation and all related stuff + +*Any sensitive settings which you dont want to share can be put in local_settings.py file* + - Make migrations using- ``` python manage.py makemigrations @@ -68,7 +130,7 @@ python3 manage.py makemigrations ``` python manage.py migrate ``` -- Create a superuser- +- Create a superuser and put relevant details when prompted- ``` python manage.py createsuperuser ```