Commit f7d8a68d authored by Wanigasinghe N.T. | IT18229912's avatar Wanigasinghe N.T. | IT18229912

Merge branch 'it18229912' into 'develop'

feat: Login/Signup/File upload updated

See merge request !2
parents 52697190 c389f485
# from .controller import connector
from .db_connector import get_mysql_conn
from .controller import signup, signin
from controller.db_connector import get_mysql_conn
import pandas as pd
def signup(userdata):
with get_mysql_conn() as conn:
mycursor = conn.cursor()
sql = "INSERT INTO user (user_name, email, password) VALUES (%s, %s, %s)"
val = (userdata.user_name, userdata.email, userdata.password)
mycursor.execute(sql, val)
conn.commit()
df = pd.read_sql('SELECT * FROM user', conn)
print(df)
return("Record inserted")
def signin(email,password):
with get_mysql_conn() as conn:
mycursor = conn.cursor()
sql = "SELECT password FROM user WHERE email = %s"
val = (email,)
mycursor.execute(sql, val)
myresult = mycursor.fetchall()
print(myresult[0][0])
if myresult[0][0] == password:
print("Logged sucessfully")
else:
print("Incorrect password")
return("hi")
import contextlib
import mysql.connector
@contextlib.contextmanager
def get_mysql_conn():
conn = mysql.connector.connect(host="localhost",
user="root",
password="",
database="presently-cdap")
try:
yield conn
finally:
conn.close()
\ No newline at end of file
from typing import Optional
from fastapi import FastAPI, File, UploadFile
from pydantic import BaseModel
from models.user_model import Signup, Signin
import controller
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
return {"item_id": item_id, "q": q}
@app.post("/signup")
def read_root_post(signup:Signup):
return controller.signup(signup)
@app.post("/signin")
def read_root_post(signin:Signin):
return controller.signin(signin.email, signin.password)
@app.post("/fileupload")
def read_root_post(file: UploadFile = File(...)):
return file.filename
\ No newline at end of file
from pydantic import BaseModel
class Signup(BaseModel):
user_name: str
email: str
password: str
class Signin(BaseModel):
email: str
password: str
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment