Skip to content

Commit

Permalink
Merge pull request #70 from HungrySlugs-CSE115A/revert-69-login
Browse files Browse the repository at this point in the history
Revert "Login"
  • Loading branch information
anyazhang17 authored May 10, 2024
2 parents 0dcbff1 + d96b7b1 commit 4ed160a
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 262 deletions.
5 changes: 0 additions & 5 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Metadata } from "next";
import { Montserrat } from "next/font/google";
import "./globals.css";
//import Link from "next/link";

import Navbar from "@/components/navbar";
import Testbar from "@/components/testbar";
Expand All @@ -13,8 +12,6 @@ export const metadata: Metadata = {
description: "Generated by create next app",
};



// This is the height of the navbar which will also be used to set the padding-top of the main content
// NOTE: you should modify this value to match the height of the navbar
const navbarHeight: string = "60px";
Expand All @@ -32,9 +29,7 @@ export default function RootLayout({

{children}
</div>

</body>

</html>
);
}
82 changes: 0 additions & 82 deletions app/loginPage/page.tsx

This file was deleted.

61 changes: 57 additions & 4 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
import { useState, useEffect } from "react";
import axios from "axios";
import Link from "next/link";
import {
GoogleOAuthProvider,
GoogleLogin,
googleLogout,
} from "@react-oauth/google";
import { jwtDecode } from "jwt-decode";

interface Food {
name: string;
Expand All @@ -14,7 +20,6 @@ interface subCategory {
}

interface Category {
forEach(arg0: (category: any) => void): unknown;
name: string;
sub_categories: Array<subCategory>;
}
Expand Down Expand Up @@ -46,7 +51,7 @@ function ButtonLink(props: any) {
);
}

export default function Home() {
function Home() {
const [dhs, setDhs] = useState<DiningHall[]>([]);
const [dhs_names, set_dhs_names] = useState([""]);
const [searchInput, setSearchInput] = useState("");
Expand Down Expand Up @@ -79,7 +84,7 @@ export default function Home() {
const allFoods: { food: Food; dhName: string; categoryName: string }[] = [];
dhs.forEach((dh) => {
dh.categories.forEach((category) => {
category.sub_categories.forEach((subCategory: { foods: any[]; }) => {
category.sub_categories.forEach((subCategory) => {
subCategory.foods.forEach((food) => {
allFoods.push({
food,
Expand Down Expand Up @@ -154,7 +159,55 @@ export default function Home() {
</h3>

</div>
{/* Account Button */}
</main>
);
}

export default function Page() {
const [user, setUser] = useState<User | null>(null);

useEffect(() => {
console.log(
"Page component loaded and GoogleOAuthProvider should be active",
);
}, []);

const handleLogout = () => {
googleLogout();
setUser(null); // Clear user state on logout
console.log("Logout Successful");
};

const handleLoginSuccess = (credentialResponse: any) => {
console.log("Login Successful", credentialResponse);
const decoded: User = jwtDecode(credentialResponse.credential);
setUser({
name: decoded.name,
picture: decoded.picture,
});
};

return (
<GoogleOAuthProvider clientId="1040494859138-vji3ddfil5jancg23ifaginvmn71hktf.apps.googleusercontent.com">
<Home />
<GoogleLogin
onSuccess={handleLoginSuccess}
onError={() => {
console.log("Login Failed");
}}
/>
{user && (
<div>
<img src={user.picture} alt="User profile" />
<h2>{user.name}</h2>
</div>
)}
<button
onClick={handleLogout}
className="p-2 mt-2 text-white bg-red-600 rounded"
>
Logout
</button>
</GoogleOAuthProvider>
);
}
39 changes: 0 additions & 39 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
"corsheaders",
"rest_framework",
"myapi",
'oauth2_provider',
'drf_social_oauth2',
'social_django',
]

MIDDLEWARE = [
Expand All @@ -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
Expand All @@ -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',
],
},
},
Expand Down Expand Up @@ -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',
)
4 changes: 0 additions & 4 deletions backend/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),

]
41 changes: 0 additions & 41 deletions backend/myapi/migrations/0001_initial.py

This file was deleted.

18 changes: 0 additions & 18 deletions backend/myapi/migrations/0002_alter_userprofile_email.py

This file was deleted.

16 changes: 0 additions & 16 deletions backend/myapi/migrations/0003_delete_userprofile.py

This file was deleted.

2 changes: 1 addition & 1 deletion backend/myapi/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 1 addition & 4 deletions backend/myapi/urls.py
Original file line number Diff line number Diff line change
@@ -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/<str:backend>/', views.create_user, name='create_user'),
#path('getuser/', views.get_user, name='get_user'),
]
Loading

0 comments on commit 4ed160a

Please sign in to comment.