Skip to content
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

Login via Google and api restriction decorator added #3

Merged
merged 6 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@ dist

## Server files
**/__pycache__
server/flask
server/flask
server/export_env.sh
61 changes: 59 additions & 2 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"axios": "^0.21.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-google-login": "^5.2.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.2",
"styled-components": "^5.2.1",
Expand Down
37 changes: 36 additions & 1 deletion client/src/components/signUp/SignUp.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
import React from "react";
import styled from "styled-components";
import img from "../../imgs/signup-background.png";
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
import GoogleLogin from "react-google-login";

const SignUp = () => {
return <div></div>;
const onSuccess = (res) => {
console.log("[Login Success] currentUser:", res.profileObj);
};
const onFailure = (res) => {
console.log("[Login Failed] res:", res);
};

return (
<Page>
<div>
<Router>
<Link to="/login" exact>
<GoogleLogin
client_id={process.env.GOOGLE_CLIENT_ID}
onSuccess={onSuccess}
onFailure={onFailure}
/>
</Link>
<Switch>
<Route path="/login" exact></Route>
</Switch>
</Router>
</div>
</Page>
);
};

export default SignUp;

const Page = styled.div`
border: 1px solid #000;
background-image: url(${img});
width: 2000px;
height: 900px;
`;
Binary file added client/src/imgs/signup-background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 57 additions & 2 deletions server/app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,68 @@
import flask
<<<<<<< HEAD
from mongo import *
from flask import Flask, render_template, request, send_from_directory
=======
from flask import Flask
>>>>>>> 208e19ba944c3e9e7758e72b75c6e2f11cf3acf1
from flask_restful import Api
import config
import os
# Import API endpoints here:
from resources.demo import Demo
# Auth imports
from auth import oauth, auth_routes

<<<<<<< HEAD
app = Flask(__name__, static_url_path="",
static_folder='../client/build',
template_folder='../client/build')
=======
app = Flask(__name__)
>>>>>>> 208e19ba944c3e9e7758e72b75c6e2f11cf3acf1
# Adding secret key to app
app.secret_key = '!secret'
# Configuring flask app
app.config.from_object(config)

# Blueprints
app.register_blueprint(auth_routes)

# Configuring OAuth object
oauth.init_app(app)
CONF_URL = 'https://accounts.google.com/.well-known/openid-configuration'
oauth.register(
name='google',
server_metadata_url=CONF_URL,
client_kwargs={
'scope': 'openid email profile'
}
)

app = flask.Flask(__name__)
api = Api(app)

# register endpoints from /resources folder here:
api.add_resource(Demo, '/demo')


@ app.route("/")
def hello():
return render_template("index.html")


@app.route("/<path:path>")
def static_proxy(path):
"""static folder serve"""
file_name = path.split("/")[-1]
dir_name = os.path.join(app.static_folder, "/".join(path.split("/")[:-1]))
return send_from_directory(dir_name, file_name)


@app.errorhandler(404)
def handle_404(e):
if request.path.startswith("/api/"):
return jsonify(message="Resource not found"), 404
return send_from_directory(app.static_folder, "index.html")


if __name__ == '__main__':
app.run(debug=True)
Loading