Merge branch 'main' of https://github.com/john-david3/cs3305-team11
This commit is contained in:
@@ -8,6 +8,7 @@ import NotFoundPage from "./pages/NotFoundPage";
|
|||||||
import UserPage from "./pages/UserPage";
|
import UserPage from "./pages/UserPage";
|
||||||
import ResetPasswordPage from "./pages/ResetPasswordPage";
|
import ResetPasswordPage from "./pages/ResetPasswordPage";
|
||||||
import CategoryPage from "./pages/CategoryPage";
|
import CategoryPage from "./pages/CategoryPage";
|
||||||
|
import CategoriesPage from "./pages/CategoriesPage";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
||||||
@@ -44,6 +45,7 @@ function App() {
|
|||||||
<Route path="/user/:username" element={<UserPage />} />
|
<Route path="/user/:username" element={<UserPage />} />
|
||||||
<Route path="/reset_password/:token" element={<ResetPasswordPage />}></Route>
|
<Route path="/reset_password/:token" element={<ResetPasswordPage />}></Route>
|
||||||
<Route path="/category/:category_name" element={<CategoryPage />}></Route>
|
<Route path="/category/:category_name" element={<CategoryPage />}></Route>
|
||||||
|
<Route path="/category" element={<CategoriesPage />}></Route>
|
||||||
|
|
||||||
<Route path="/404" element={<NotFoundPage />} />
|
<Route path="/404" element={<NotFoundPage />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ import { useEffect } from "react";
|
|||||||
export default function GoogleLogin() {
|
export default function GoogleLogin() {
|
||||||
const handleLoginClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
const handleLoginClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
window.location.href = "/api/login/google";
|
const nextUrl = encodeURIComponent(window.location.href);
|
||||||
|
window.location.href = `/api/login/google?next=${nextUrl}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
11
frontend/src/pages/CategoriesPage.tsx
Normal file
11
frontend/src/pages/CategoriesPage.tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
const CategoriesPage: React.FC = () => {
|
||||||
|
return (
|
||||||
|
<div className="categories-page">
|
||||||
|
<h1>Categories Page</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CategoriesPage;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
from authlib.integrations.flask_client import OAuth, OAuthError
|
from authlib.integrations.flask_client import OAuth, OAuthError
|
||||||
from flask import Blueprint, jsonify, session, redirect
|
from flask import Blueprint, jsonify, session, redirect, request
|
||||||
from blueprints.user import get_session_info_email
|
from blueprints.user import get_session_info_email
|
||||||
from database.database import Database
|
from database.database import Database
|
||||||
from secrets import token_hex, token_urlsafe
|
from secrets import token_hex, token_urlsafe
|
||||||
@@ -31,6 +31,8 @@ def login_google():
|
|||||||
"""
|
"""
|
||||||
# Creates nonce to be sent
|
# Creates nonce to be sent
|
||||||
session["nonce"] = token_urlsafe(16)
|
session["nonce"] = token_urlsafe(16)
|
||||||
|
session["origin"] = request.args.get("next")
|
||||||
|
|
||||||
return google.authorize_redirect(
|
return google.authorize_redirect(
|
||||||
'http://127.0.0.1:8080/api/google_auth',
|
'http://127.0.0.1:8080/api/google_auth',
|
||||||
nonce=session['nonce']
|
nonce=session['nonce']
|
||||||
@@ -82,12 +84,12 @@ def google_auth():
|
|||||||
)
|
)
|
||||||
user_data = get_session_info_email(user_email)
|
user_data = get_session_info_email(user_email)
|
||||||
|
|
||||||
|
origin = session.pop("origin", "http://127.0.0.1:8080/")
|
||||||
session.clear()
|
session.clear()
|
||||||
session["username"] = user_data["username"]
|
session["username"] = user_data["username"]
|
||||||
session["user_id"] = user_data["user_id"]
|
session["user_id"] = user_data["user_id"]
|
||||||
|
|
||||||
# TODO: redirect back to original page user started on, or other pages based on success failure of login
|
return redirect(origin)
|
||||||
return redirect("http://127.0.0.1:8080/")
|
|
||||||
|
|
||||||
except OAuthError as e:
|
except OAuthError as e:
|
||||||
return jsonify({
|
return jsonify({
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user