Skip to content

Commit

Permalink
Fixed for pre-commit check
Browse files Browse the repository at this point in the history
  • Loading branch information
Jwdegames committed Nov 27, 2023
1 parent bc33e40 commit 5b0784c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 40 deletions.
34 changes: 19 additions & 15 deletions backend/app/api/endpoints/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from dotenv import load_dotenv
from fastapi import APIRouter, Depends, HTTPException, status
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from google.auth.transport import requests
from google.oauth2 import id_token
from jose import JWTError, jwt
from pydantic import BaseModel
from sqlalchemy.orm import Session
Expand All @@ -14,9 +16,6 @@
from backend.app.database import engine
from backend.app.models import User as UserModel

from google.oauth2 import id_token
from google.auth.transport import requests

from ..deps import get_db

load_dotenv()
Expand All @@ -25,7 +24,7 @@
ACCESS_TOKEN_EXPIRE_MINUTES = 30

# Google Client ID
CLIENT_ID = '710734565405-3nkf5plf0m4p460osals94rnksheoh93.apps.googleusercontent.com'
CLIENT_ID = "710734565405-3nkf5plf0m4p460osals94rnksheoh93.apps.googleusercontent.com"

users_db = get_db()

Expand All @@ -45,7 +44,7 @@ def hash_password(password: str):

class User(BaseModel):
username: str
google_id: str | None = None
google_id: str | None = None
made_password: bool | None = None
email: str | None = None
full_name: str | None = None
Expand Down Expand Up @@ -119,7 +118,10 @@ def authenticate_user(username: str, password: str, db: Session = Depends(get_db
if not user:
raise HTTPException(status_code=400, detail="Incorrect username or password")
if not user.made_password:
raise HTTPException(status_code=400, detail="This account didn't make a password. Please login via Google.")
raise HTTPException(
status_code=400,
detail="This account didn't make a password. Please login via Google.",
)
encoded_password = password.encode("utf-8")
if not bcrypt.checkpw(encoded_password, user.password.encode("utf-8")):
raise HTTPException(status_code=400, detail="Incorrect username or password")
Expand Down Expand Up @@ -190,14 +192,16 @@ async def delete_user(


@router.post("/users/google-login")
async def google_login(
token: str,
db: Session = Depends(get_db)
):
async def google_login(token: str, db: Session = Depends(get_db)):
try:
# Specify the CLIENT_ID of the app that accesses the backend:
print("testing:", token)
idinfo = id_token.verify_oauth2_token(token, requests.Request(), CLIENT_ID, clock_skew_in_seconds=1000000,)
idinfo = id_token.verify_oauth2_token(
token,
requests.Request(),
CLIENT_ID,
clock_skew_in_seconds=1000000,
)
print("Success")
# print("ID_info:", idinfo)
# Or, if multiple clients access the backend server:
Expand All @@ -211,10 +215,10 @@ async def google_login(

# ID token is valid. Get the user's Google Account ID from the decoded token.
# print("Getting user info")
userid = idinfo['sub']
name = idinfo['name']
userid = idinfo["sub"]
name = idinfo["name"]
# print(userid)
email = idinfo['email']
email = idinfo["email"]
# print(email)
user = crud.search_users_by_google_id(db, userid)
if user is None or len(user) == 0:
Expand Down Expand Up @@ -246,4 +250,4 @@ async def google_login(
# Invalid token
print("Invalid token:", token)
print(e)
return {"Error!"}
return {"Error!"}
5 changes: 4 additions & 1 deletion backend/app/crud/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ def search_users(db: Session, username: str, skip: int = 0, limit: int = 1000):
)
return convert_users(*results)

def search_users_by_google_id(db: Session, field_val: str, skip: int = 0, limit: int = 1000):

def search_users_by_google_id(
db: Session, field_val: str, skip: int = 0, limit: int = 1000
):
"""Searches for users by a given field value in a field"""
results = (
db.query(UserModel)
Expand Down
3 changes: 1 addition & 2 deletions backend/app/models/user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlalchemy import Column, Integer, String, Boolean
from sqlalchemy import Boolean, Column, Integer, String

from backend.app.database import DatabaseModel

Expand All @@ -14,7 +14,6 @@ class User(DatabaseModel):
full_name = Column(String)
email = Column(String)
disabled = Column(String)


def __str__(self):
return str(
Expand Down
16 changes: 8 additions & 8 deletions debugdump.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
0010: Host: www.example.com
0027: User-Agent: curl/7.81.0
0040: Accept: */*
004d:
004d:
== Info: Mark bundle as not supporting multiuse
<= Recv header, 17 bytes (0x11)
0000: HTTP/1.1 200 OK
Expand All @@ -32,26 +32,26 @@
<= Recv header, 22 bytes (0x16)
0000: Content-Length: 1256
<= Recv header, 2 bytes (0x2)
0000:
0000:
<= Recv data, 1256 bytes (0x4e8)
0000: <!doctype html>.<html>.<head>. <title>Example Domain</title>.
0040: . <meta charset="utf-8" />. <meta http-equiv="Content-type
0080: " content="text/html; charset=utf-8" />. <meta name="viewport
00c0: " content="width=device-width, initial-scale=1" />. <style ty
0100: pe="text/css">. body {. background-color: #f0f0f2;.
0100: pe="text/css">. body {. background-color: #f0f0f2;.
0140: margin: 0;. padding: 0;. font-family: -apple-
0180: system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans",
01c0: "Helvetica Neue", Helvetica, Arial, sans-serif;. . }.
0200: div {. width: 600px;. margin: 5em auto;.
0180: system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans",
01c0: "Helvetica Neue", Helvetica, Arial, sans-serif;. . }.
0200: div {. width: 600px;. margin: 5em auto;.
0240: padding: 2em;. background-color: #fdfdff;. border
0280: -radius: 0.5em;. box-shadow: 2px 3px 7px 2px rgba(0,0,0,0
02c0: .02);. }. a:link, a:visited {. color: #38488f;.
02c0: .02);. }. a:link, a:visited {. color: #38488f;.
0300: text-decoration: none;. }. @media (max-width: 700px) {
0340: . div {. margin: 0 auto;. width: au
0380: to;. }. }. </style> .</head>..<body>.<div>. <
03c0: h1>Example Domain</h1>. <p>This domain is for use in illustra
0400: tive examples in documents. You may use this. domain in liter
0440: ature without prior coordination or asking for permission.</p>.
0440: ature without prior coordination or asking for permission.</p>.
0480: <p><a href="https://www.iana.org/domains/example">More inform
04c0: ation...</a></p>.</div>.</body>.</html>.
== Info: Connection #0 to host www.example.com left intact
2 changes: 1 addition & 1 deletion frontend/src/app/pages/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class LoginComponent {
constructor(
private authService: AuthService,
public router: Router
) { }
) {}

incorrectLogin: boolean = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { LoginComponent } from 'src/app/pages/login/login.component';
})
export class GoogleSignInComponent implements OnInit {
@Input() loginRef!: LoginComponent;
constructor(private zone: NgZone) { }
constructor(private zone: NgZone) {}

ngOnInit(): void {
// @ts-ignore
Expand All @@ -33,27 +33,22 @@ export class GoogleSignInComponent implements OnInit {
// google.accounts.id.prompt((notification: PromptMomentNotification) => {});
}


async handleCredentialResponse(googleUser: any) {
console.log(googleUser);
var token: string = googleUser.credential
var token: string = googleUser.credential;

LoginService.googleLogin(token).then(
() => {
// login
console.log("Resetting");
this.loginRef.form.reset()
console.log("Navigating");
console.log('Resetting');
this.loginRef.form.reset();
console.log('Navigating');
this.zone.run(() => this.loginRef.router.navigate(['/jobs']));
},
() => {
// Do nothing since we failed
console.log("Failed");
console.log('Failed');
}
);
};

}
}



2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
bcrypt==4.0.1
celery[redis]
fastapi==0.95.2
google-api-python-client
nltk==3.8.1
passlib[bcrypt]==1.7.4
pre-commit==3.5.0
Expand All @@ -13,4 +14,3 @@ selenium==4.15.2
sqlalchemy==1.4.42
undetected-chromedriver==3.5.4
uvicorn==0.19.0
google-api-python-client

0 comments on commit 5b0784c

Please sign in to comment.