-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement user verification after registration
- Loading branch information
Showing
10 changed files
with
152 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
from sqlalchemy.orm import Session | ||
from app.models.users import User | ||
from app.models.users import User, AccountVerification | ||
from typing import Dict, Any | ||
|
||
|
||
def add_user(session: Session, user_info: Dict[str, Any]): | ||
user_item = User(**user_info) | ||
session.add(user_item) | ||
|
||
|
||
def add_account_verification(session: Session, verification_info: Dict[str, Any]): | ||
verification_item = AccountVerification(**verification_info) | ||
session.add(verification_item) | ||
|
||
|
||
def update_verified_status(session: Session, phone_number: str, status: bool): | ||
session.query(User).filter(User.phone_number == phone_number).update( | ||
{"is_verified": status} | ||
) | ||
|
||
|
||
def get_user_verification(session: Session, otp: str) -> AccountVerification: | ||
acc_verification = ( | ||
session.query(AccountVerification) | ||
.filter(AccountVerification.token == otp) | ||
.first() | ||
) | ||
return acc_verification |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
from twilio.rest import Client | ||
from app.core.settings import Settings, get_settings | ||
import random | ||
|
||
settings: Settings = get_settings() | ||
|
||
|
||
def get_twilio_client(): | ||
account_sid = settings.TWILIO_ACCOUNT_SID | ||
auth_token = settings.TWILIO_AUTH_TOKEN | ||
client = Client(account_sid, auth_token) | ||
return client | ||
|
||
|
||
def send_sms(phone_number: str, message: str, client: Client): | ||
message = client.messages.create( | ||
body=message, from_="+12543293270", to=phone_number | ||
) | ||
|
||
|
||
def generate_otp(): | ||
verification_code = random.randint(100000, 999999) | ||
return str(verification_code) | ||
|
||
|
||
def send_otp_sms(phone_number: str, otp: str): | ||
client = get_twilio_client() | ||
message = f"Your OTP is {otp}" | ||
send_sms(phone_number, message, client) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters