From b97492d692631d8b743d325854be99bd6e66d61f Mon Sep 17 00:00:00 2001 From: AkhilS2 <55607137+AkhilS2@users.noreply.github.com> Date: Thu, 9 May 2024 20:05:48 -0700 Subject: [PATCH 1/2] revert backend --- backend/backend/settings.py | 39 --------------- backend/backend/urls.py | 4 -- backend/myapi/migrations/0001_initial.py | 41 ---------------- .../0002_alter_userprofile_email.py | 18 ------- .../migrations/0003_delete_userprofile.py | 16 ------- backend/myapi/models.py | 2 +- backend/myapi/urls.py | 5 +- backend/myapi/views.py | 47 ------------------- 8 files changed, 2 insertions(+), 170 deletions(-) delete mode 100644 backend/myapi/migrations/0001_initial.py delete mode 100644 backend/myapi/migrations/0002_alter_userprofile_email.py delete mode 100644 backend/myapi/migrations/0003_delete_userprofile.py diff --git a/backend/backend/settings.py b/backend/backend/settings.py index febeef87..91fac86d 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -44,9 +44,6 @@ "corsheaders", "rest_framework", "myapi", - 'oauth2_provider', - 'drf_social_oauth2', - 'social_django', ] MIDDLEWARE = [ @@ -58,7 +55,6 @@ "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", "corsheaders.middleware.CorsMiddleware", - 'social_django.middleware.SocialAuthExceptionMiddleware', ] CORS_ORIGIN_ALLOW_ALL = True @@ -76,8 +72,6 @@ "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", - 'social_django.context_processors.backends', - 'social_django.context_processors.login_redirect', ], }, }, @@ -137,36 +131,3 @@ # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" - -LOGIN_URL = '/admin/login/' - -REST_FRAMEWORK = { - 'DEFAULT_AUTHENTICATION_CLASSES': ( - 'oauth2_provider.contrib.rest_framework.OAuth2Authentication', - 'drf_social_oauth2.authentication.SocialAuthentication', - ), -} - -AUTHENTICATION_BACKENDS = ( - 'social_core.backends.google.GoogleOAuth2', - 'django.contrib.auth.backends.ModelBackend', - 'drf_social_oauth2.backends.DjangoOAuth2', -) -SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '1040494859138-vji3ddfil5jancg23ifaginvmn71hktf.apps.googleusercontent.com' -SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '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' - -SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [ - 'https://www.googleapis.com/auth/userinfo.email', - 'https://www.googleapis.com/auth/userinfo.profile', -] - -SOCIAL_AUTH_PIPELINE = ( - 'social_core.pipeline.social_auth.social_details', - 'social_core.pipeline.social_auth.social_uid', - 'social_core.pipeline.social_auth.auth_allowed', - 'social_core.pipeline.social_auth.social_user', - 'social_core.pipeline.user.create_user', - 'social_core.pipeline.social_auth.associate_user', - 'social_core.pipeline.social_auth.load_extra_data', - 'social_core.pipeline.user.user_details', -) diff --git a/backend/backend/urls.py b/backend/backend/urls.py index 2a289d7f..f276300a 100644 --- a/backend/backend/urls.py +++ b/backend/backend/urls.py @@ -23,8 +23,4 @@ path("admin/", admin.site.urls), # For the api path("myapi/", include("myapi.urls")), - path('o/', include('oauth2_provider.urls', namespace='oauth2_provider')), - path('auth/',include('drf_social_oauth2.urls',namespace='drf')), - path('social-auth/', include('social_django.urls', namespace='social')), - ] diff --git a/backend/myapi/migrations/0001_initial.py b/backend/myapi/migrations/0001_initial.py deleted file mode 100644 index c1ac70c7..00000000 --- a/backend/myapi/migrations/0001_initial.py +++ /dev/null @@ -1,41 +0,0 @@ -# Generated by Django 5.0.4 on 2024-05-07 04:49 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ] - - operations = [ - migrations.CreateModel( - name="UserProfile", - fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("first_name", models.CharField(blank=True, max_length=50)), - ("last_name", models.CharField(blank=True, max_length=50)), - ("email", models.EmailField(blank=True, max_length=254)), - ( - "user", - models.OneToOneField( - on_delete=django.db.models.deletion.CASCADE, - to=settings.AUTH_USER_MODEL, - ), - ), - ], - ), - ] diff --git a/backend/myapi/migrations/0002_alter_userprofile_email.py b/backend/myapi/migrations/0002_alter_userprofile_email.py deleted file mode 100644 index 0cb77b87..00000000 --- a/backend/myapi/migrations/0002_alter_userprofile_email.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 5.0.4 on 2024-05-07 19:26 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("myapi", "0001_initial"), - ] - - operations = [ - migrations.AlterField( - model_name="userprofile", - name="email", - field=models.EmailField(max_length=254, unique=True), - ), - ] diff --git a/backend/myapi/migrations/0003_delete_userprofile.py b/backend/myapi/migrations/0003_delete_userprofile.py deleted file mode 100644 index e1114b2d..00000000 --- a/backend/myapi/migrations/0003_delete_userprofile.py +++ /dev/null @@ -1,16 +0,0 @@ -# Generated by Django 5.0.4 on 2024-05-08 04:25 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("myapi", "0002_alter_userprofile_email"), - ] - - operations = [ - migrations.DeleteModel( - name="UserProfile", - ), - ] diff --git a/backend/myapi/models.py b/backend/myapi/models.py index 99386b4a..a04bc1cf 100644 --- a/backend/myapi/models.py +++ b/backend/myapi/models.py @@ -1,6 +1,6 @@ from django.db import models from db_connection import db -from django.contrib.auth.models import User + # Create your models here. # locations Model diff --git a/backend/myapi/urls.py b/backend/myapi/urls.py index 6c3558e5..0e34851d 100644 --- a/backend/myapi/urls.py +++ b/backend/myapi/urls.py @@ -1,10 +1,7 @@ -from django.urls import path, re_path +from django.urls import path from . import views urlpatterns = [ path("hello-world/", views.hello_world, name="hello_world"), path("locations/", views.get_locations, name="locations"), - #path('users/', views.create_user, name='create_user'), - path('users//', views.create_user, name='create_user'), - #path('getuser/', views.get_user, name='get_user'), ] diff --git a/backend/myapi/views.py b/backend/myapi/views.py index e4a1cdb4..9575c9af 100644 --- a/backend/myapi/views.py +++ b/backend/myapi/views.py @@ -1,14 +1,3 @@ -from rest_framework.response import Response -from rest_framework import status -from rest_framework.decorators import api_view, permission_classes -from django.contrib.auth.models import User -from .webscraper.food_options import FoodOptions -from .db_functions.dining_halls import get_all_dining_halls_from_db -from rest_framework.authtoken.models import Token -from rest_framework.decorators import api_view, permission_classes -from rest_framework.permissions import AllowAny - -from social_django.utils import psa from django.conf.locale import fr from rest_framework.response import Response from rest_framework.decorators import api_view @@ -70,39 +59,3 @@ def get_locations(request): json_data = {"locations": locations} return Response(json_data) -#user information -@api_view(['POST']) -@permission_classes([AllowAny]) -@psa('social:complete') -def create_user(request,backend): - # Extract the token sent from the frontend - - token = request.data.get('access_token') - print(token) - - # `do_auth` method will try to authenticate the token with Google - try: - user = request.backend.do_auth(token) - except Exception as e: - # Log the exception to understand why authentication fails - print(f'Authentication failed: {str(e)}') - return Response( - {'errors': {'token': 'Authentication failed', 'detail': str(e)}}, - status=status.HTTP_403_FORBIDDEN, - ) - - - if user: - # If user is authenticated, get or create a token for your application - token, _ = Token.objects.get_or_create(user=user) - return Response({ - 'id': user.id, - 'name': user.username, - 'email': user.email, - 'token': token.key # Send the token key to the frontend - }) - else: - return Response( - {'errors': {'token': 'Invalid token'}}, - status=status.HTTP_400_BAD_REQUEST, - ) \ No newline at end of file From 056b0a34032e5090f0b10506e68456c02ab638ac Mon Sep 17 00:00:00 2001 From: AkhilS2 <55607137+AkhilS2@users.noreply.github.com> Date: Thu, 9 May 2024 20:29:40 -0700 Subject: [PATCH 2/2] frontend --- app/loginPage/page.tsx | 1 + app/page.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/app/loginPage/page.tsx b/app/loginPage/page.tsx index cdc66b26..1041c066 100644 --- a/app/loginPage/page.tsx +++ b/app/loginPage/page.tsx @@ -4,6 +4,7 @@ import { GoogleOAuthProvider, useGoogleLogin, googleLogout, TokenResponse} from import { jwtDecode } from "jwt-decode"; import axios from "axios"; + interface User { name: string; email: string; diff --git a/app/page.tsx b/app/page.tsx index cb2be774..62347716 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -8,6 +8,7 @@ interface Food { extra_data: Array; } + interface subCategory { name: string; foods: Array;