update emails and verifing
This commit is contained in:
+26
-10
@@ -1,12 +1,12 @@
|
||||
from database import execute, fetch_one
|
||||
import bcrypt
|
||||
from jose import jwt, JWTError
|
||||
from jose import jwt
|
||||
from datetime import datetime, timedelta
|
||||
from fastapi import Header, HTTPException
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
from fastapi import Depends, HTTPException
|
||||
import os
|
||||
from fastapi import Depends
|
||||
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
||||
from email_service import create_verification, send_verification_email
|
||||
|
||||
security = HTTPBearer()
|
||||
load_dotenv()
|
||||
@@ -30,7 +30,7 @@ def create_token(user_id):
|
||||
return token
|
||||
|
||||
|
||||
def create_user(username, password):
|
||||
def create_user(username, password, email):
|
||||
|
||||
password_hash = bcrypt.hashpw(
|
||||
password.encode(),
|
||||
@@ -39,15 +39,30 @@ def create_user(username, password):
|
||||
|
||||
user_id = execute(
|
||||
"""
|
||||
INSERT INTO users (username, password_hash)
|
||||
VALUES (?, ?)
|
||||
INSERT INTO users (
|
||||
username,
|
||||
password_hash,
|
||||
email,
|
||||
email_verified
|
||||
)
|
||||
VALUES (?, ?, ?, 0)
|
||||
""",
|
||||
(username, password_hash)
|
||||
(
|
||||
username,
|
||||
password_hash,
|
||||
email,
|
||||
)
|
||||
)
|
||||
|
||||
token = create_verification(user_id)
|
||||
|
||||
send_verification_email(
|
||||
email,
|
||||
token,
|
||||
)
|
||||
|
||||
return user_id
|
||||
|
||||
|
||||
def verify_user(username, password):
|
||||
|
||||
user = fetch_one(
|
||||
@@ -80,10 +95,11 @@ def get_current_user(
|
||||
|
||||
return payload["user_id"]
|
||||
|
||||
|
||||
def get_user(user_id):
|
||||
return fetch_one(
|
||||
"""
|
||||
SELECT id, username
|
||||
SELECT id, username, email, email_verified
|
||||
FROM users
|
||||
WHERE id = ?
|
||||
""",
|
||||
|
||||
Reference in New Issue
Block a user