Skip to content

Commit 10cb362

Browse files
Adding SignIn With Google
1 parent 68c76ee commit 10cb362

File tree

7 files changed

+83
-3
lines changed

7 files changed

+83
-3
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ COPY ./requirements.txt /var/www/app/requirements.txt
1515
RUN pip install -r /var/www/app/requirements.txt
1616
RUN pip install gunicorn
1717
COPY . /var/www/app
18-
ENV PORT 8080
18+
ENV PORT 8000
1919
EXPOSE $PORT
2020
# to be equal to the cores available.
2121
CMD exec gunicorn --bind :$PORT run:app --workers 2 --threads 8 --timeout 3600

requirements.txt

1.46 KB
Binary file not shown.

src/config/config.py

+14
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,23 @@ class Config:
7777
env_file_encoding = 'utf-8'
7878

7979

80+
class GoogleSettings(BaseSettings):
81+
GOOGLE_ANALYTICS_ID: str = Field(..., env="GOOGLE_ANALYTICS_ID")
82+
GOOGLE_ANALYTICS_DOMAIN: str = Field(..., env="GOOGLE_ANALYTICS_DOMAIN")
83+
GOOGLE_CLIENT_ID: str = Field(..., env="GOOGLE_CLIENT_ID")
84+
GOOGLE_CLIENT_SECRET: str = Field(..., env="GOOGLE_CLIENT_SECRET")
85+
86+
class Config:
87+
case_sensitive = True
88+
env_file = '.env.development'
89+
env_file_encoding = 'utf-8'
90+
91+
8092
class Settings(BaseSettings):
8193
EMAIL_SETTINGS: EmailSettings = EmailSettings()
8294
CELERY_SETTINGS = CelerySettings()
8395
SECRET_KEY: str = Field(..., env="SECRET_TOKEN")
96+
8497
DATABASE_SETTINGS: DatabaseSettings = DatabaseSettings()
8598
DEVELOPMENT_SERVER_NAME: str = Field(default="DESKTOP-T9V7F59")
8699
LOGGING: Logging = Logging()
@@ -89,6 +102,7 @@ class Settings(BaseSettings):
89102
SERVER_NAME: str = Field(default_factory=get_server_name)
90103
APPLICATION_ROOT: str = Field(default="/")
91104
PREFERRED_URL_SCHEME: str = Field(default="https://")
105+
GOOGLE_SETTINGS: GoogleSettings = GoogleSettings()
92106
GITHUB_SETTINGS: GithubSettings = GithubSettings()
93107
SEARCH_CONSOLE_API_KEY: str = Field(..., env="SEARCH_CONSOLE_API_KEY")
94108
EOD_STOCK_API_KEY: str = Field(..., env="EOD_STOCK_API_KEY")

src/main.py

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from src.config import config_instance
77
from src.exceptions import UnAuthenticatedError
88
from src.logger import init_logger
9+
from src.routes.authentication.dance import google_dance
910
from src.routes.blog.github import GithubBlog
1011

1112
user_session = {}
@@ -62,6 +63,7 @@ def create_app(config=config_instance()) -> Flask:
6263
app.register_blueprint(plan_routes)
6364
app.register_blueprint(sitemap_bp)
6465
app.register_blueprint(github_blog_route)
66+
app.register_blueprint(google_dance)
6567

6668
# Handle API Errors, all errors are re raised as HTTPException
6769
from src.exceptions import (InvalidSignatureError, ServerInternalError, UnresponsiveServer)

src/routes/authentication/dance.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from flask import Flask, redirect, url_for
2+
from flask_dance.contrib.google import make_google_blueprint, google
3+
4+
from src.config import config_instance
5+
6+
app = Flask(__name__)
7+
app.secret_key = config_instance().SECRET_KEY
8+
9+
google_dance = make_google_blueprint(client_id=config_instance().GOOGLE_SETTINGS.GOOGLE_CLIENT_ID,
10+
client_secret=config_instance().GOOGLE_SETTINGS.GOOGLE_CLIENT_SECRET,
11+
scope=["profile", "email"])
12+
13+
14+
@google_dance.route("/login/google")
15+
def login_google():
16+
if not google.authorized:
17+
return redirect(url_for("google.login"))
18+
resp = google.get("/oauth2/v2/userinfo")
19+
assert resp.ok, resp.text
20+
return "You are {email} on Google".format(email=resp.json()["email"])

src/static/build/css/custom.min.css

+41
Original file line numberDiff line numberDiff line change
@@ -6020,3 +6020,44 @@ ul.notifications {
60206020
#slash {
60216021
display: none;
60226022
}
6023+
6024+
.btn-google {
6025+
background-color: #00243F;
6026+
border: none;
6027+
color: floralwhite;
6028+
padding: 10px 20px;
6029+
text-align: center;
6030+
text-decoration: none;
6031+
display: inline-block;
6032+
font-size: 16px;
6033+
border-radius: 50px;
6034+
}
6035+
6036+
.btn-google:hover {
6037+
background-color: #357AE8;
6038+
}
6039+
6040+
.btn-google i {
6041+
margin-right: 10px;
6042+
}
6043+
6044+
.btn-email {
6045+
background-color: #88000F;
6046+
border: none;
6047+
color: floralwhite;
6048+
padding: 10px 20px;
6049+
text-align: center;
6050+
text-decoration: none;
6051+
display: inline-block;
6052+
font-size: 16px;
6053+
border-radius: 50px;
6054+
}
6055+
6056+
.btn-email:hover {
6057+
background-color: #8a4182;
6058+
}
6059+
6060+
.btn-email i {
6061+
margin-right: 10px;
6062+
}
6063+

src/template/layouts/authlayout.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ <h1 class="title"> Login</h1>
5353
<input type="password" id="password" class="form-control" placeholder="Enter Password" required="" />
5454
</div>
5555
<div>
56-
<a class="btn btn-default submit" type="submit" href="{{ url_for('auth.login') }}" id="submit_login">Log in</a>
57-
<a class="btn btn-default" href="#signup">Create Account?</a>
56+
<a class="btn btn-email submit" type="submit" href="{{ url_for('auth.login') }}" id="submit_login"><i class="fa fa-envelope"> </i> Sign in (Email)</a>
57+
<a class="btn btn-google" href="{{ url_for('google.login') }}"> <i class="fa fa-google"></i> Sign in with Google </a>
58+
59+
<a class="btn btn-dark" href="#signup"><i class="fa fa-user-plus"> </i> Create Account</a>
60+
5861
<div class="clearfix"></div>
5962
<span class="title" id="message"></span>
6063
</div>

0 commit comments

Comments
 (0)