(20241213) SMS Auth reworked.
This commit is contained in:
@@ -63,8 +63,8 @@ from utils_v2.api.async_quart import (
|
||||
from shared import constants
|
||||
|
||||
# Data Models:
|
||||
from models.data.api.sms.auth import SMSAuthRequestHeaders, SMSAuthRequestData
|
||||
from models.data.core.auth_token import CoreAuthTokenModel
|
||||
from models.api.sms.auth import SMSAuthRequestHeaders, SMSAuthRequestData
|
||||
from models.core.auth_token import CoreAuthTokenModel
|
||||
|
||||
# For asynchronous activities:
|
||||
import asyncio
|
||||
@@ -158,7 +158,7 @@ async def authorize_sms_client(
|
||||
)
|
||||
|
||||
# Start by assuming failure:
|
||||
token_id = None
|
||||
success = False
|
||||
|
||||
# ┏┓ ┳┓• ┓ ┏┓┳┳┓┏┓ ┳ ┓•
|
||||
# ┣ ┏┓┏┓ ┃┃┓┏┳┓┣┓┓┏┏ ┗┓┃┃┃┗┓ ┃┏┓┏┫┓┏┓
|
||||
@@ -166,7 +166,7 @@ async def authorize_sms_client(
|
||||
|
||||
if inbound_data.smsClient == "nimbusSmsIndia":
|
||||
|
||||
token_id = await current_app.sms_auth_model.set(
|
||||
success = await current_app.sms_controller.set_token(
|
||||
db_conn = current_app.sql_writer,
|
||||
mongo_conn = current_app.data_mongo,
|
||||
auth_token = CoreAuthTokenModel(
|
||||
@@ -183,17 +183,6 @@ async def authorize_sms_client(
|
||||
status = "active",
|
||||
syncFreq = 60
|
||||
),
|
||||
# user_info = kwargs["session_info"],
|
||||
# client_user_id = {
|
||||
# "userId": inbound_data.auth.userId,
|
||||
# "senderId": inbound_data.auth.senderId,
|
||||
# "entityId": inbound_data.auth.entityId
|
||||
# },
|
||||
# auth = inbound_data.auth.model_dump(),
|
||||
# token = None,
|
||||
# service_client = inbound_data.smsClient,
|
||||
# auth_type = "auth",
|
||||
# sync_freq = 300,
|
||||
session_token = inbound_headers["X-Session-Token"]
|
||||
)
|
||||
|
||||
@@ -204,10 +193,10 @@ async def authorize_sms_client(
|
||||
|
||||
elif inbound_data.smsClient == "savvyBulkSmsKenya":
|
||||
|
||||
token_id = await current_app.sms_auth_model.set(
|
||||
success = await current_app.sms_controller.set_token(
|
||||
db_conn = current_app.sql_writer,
|
||||
mongo_conn = current_app.data_mongo,
|
||||
auth_token=CoreAuthTokenModel(
|
||||
auth_token = CoreAuthTokenModel(
|
||||
serviceType = "sms",
|
||||
client = inbound_data.smsClient,
|
||||
authType = "auth",
|
||||
@@ -220,16 +209,6 @@ async def authorize_sms_client(
|
||||
status = "active",
|
||||
syncFreq = 60
|
||||
),
|
||||
# user_info = kwargs["session_info"],
|
||||
# client_user_id = {
|
||||
# "partnerId": inbound_data.auth.partnerId,
|
||||
# "shortCode": inbound_data.auth.shortCode
|
||||
# },
|
||||
# auth = inbound_data.auth.model_dump(),
|
||||
# token = None,
|
||||
# service_client = inbound_data.smsClient,
|
||||
# auth_type = "auth",
|
||||
# sync_freq = 300,
|
||||
session_token = inbound_headers["X-Session-Token"]
|
||||
)
|
||||
|
||||
@@ -240,11 +219,11 @@ async def authorize_sms_client(
|
||||
|
||||
# Done here:
|
||||
return ResponseModel(
|
||||
status_code = StatusCodes.OK if token_id else StatusCodes.FAILED,
|
||||
http_code = HttpCodes.SUCCESS if token_id else HttpCodes.INTERNAL_SERVER_ERROR,
|
||||
status_code = StatusCodes.OK if success else StatusCodes.FAILED,
|
||||
http_code = HttpCodes.SUCCESS if success else HttpCodes.INTERNAL_SERVER_ERROR,
|
||||
data = {
|
||||
"client": inbound_data.smsClient,
|
||||
"authorized": True
|
||||
"authorized": success
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -60,8 +60,8 @@ from utils_v2.api.async_quart import (
|
||||
)
|
||||
|
||||
# Data Models:
|
||||
from models.data.api.sms.send import SMSSendRequestHeaders, SMSSendRequestData
|
||||
from models.data.core.auth_token import CoreAuthTokenModel
|
||||
from models.core.auth_token import CoreAuthTokenModel
|
||||
from models.api.sms.send import SMSSendRequestHeaders, SMSSendRequestData
|
||||
|
||||
# Common:
|
||||
from shared import constants
|
||||
@@ -174,13 +174,13 @@ async def send_sms(
|
||||
# ┗┓┏┓┏┓┏┫ ┃ ┣┓┏┓ ┗┓┃┃┃┗┓
|
||||
# ┗┛┗ ┛┗┗┻ ┻ ┛┗┗ ┗┛┛ ┗┗┛
|
||||
|
||||
client_response = await current_app.sms_send_model.send_sms(
|
||||
mongo_conn = current_app.data_mongo,
|
||||
token_id = inbound_data.tokenId,
|
||||
auth_token = auth_token,
|
||||
inbound_data = inbound_data,
|
||||
session_token = inbound_headers["X-Session-Token"]
|
||||
)
|
||||
# client_response = await current_app.sms_send_model.send_sms(
|
||||
# mongo_conn = current_app.data_mongo,
|
||||
# token_id = inbound_data.tokenId,
|
||||
# auth_token = auth_token,
|
||||
# inbound_data = inbound_data,
|
||||
# session_token = inbound_headers["X-Session-Token"]
|
||||
# )
|
||||
|
||||
# ┳┓
|
||||
# ┣┫┏┓┏┏┓┏┓┏┓┏┏┓
|
||||
|
||||
@@ -208,7 +208,7 @@ async def authorize_software_client(
|
||||
http_code = HttpCodes.SUCCESS if success else HttpCodes.INTERNAL_SERVER_ERROR,
|
||||
data = {
|
||||
"client": inbound_data.softwareClient,
|
||||
"authorized": True if success else False
|
||||
"authorized": success
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
+4
-2
@@ -69,6 +69,7 @@ from controllers.core.ai.llm import LLMController
|
||||
|
||||
# API Controller Models:
|
||||
from controllers.api.mail import MailController
|
||||
from controllers.api.sms import SMSController
|
||||
|
||||
# # Old Behaviour Models:
|
||||
# from controllers.mail.oauth_v3 import MailOAuthModel
|
||||
@@ -90,7 +91,7 @@ from api.blueprints.mail.sync.sync_v2 import mail_sync_bp
|
||||
from api.blueprints.mail.retrieve.list import mail_list_bp
|
||||
from api.blueprints.mail.retrieve.get import mail_get_bp
|
||||
from api.blueprints.mail.tags.update import mail_tags_update_bp
|
||||
# from api.blueprints.sms.auth import sms_auth_bp
|
||||
from api.blueprints.sms.auth import sms_auth_bp
|
||||
# from api.blueprints.sms.send import sms_send_bp
|
||||
# from api.blueprints.chat.auth import chat_auth_bp
|
||||
# from api.blueprints.chat.webhook import chat_webhook_bp
|
||||
@@ -131,7 +132,7 @@ app.register_blueprint(mail_sync_bp, url_prefix = f"/{MODULE_BASE}/mail")
|
||||
app.register_blueprint(mail_list_bp, url_prefix = f"/{MODULE_BASE}/mail")
|
||||
app.register_blueprint(mail_get_bp, url_prefix = f"/{MODULE_BASE}/mail")
|
||||
app.register_blueprint(mail_tags_update_bp, url_prefix = f"/{MODULE_BASE}/mail")
|
||||
# app.register_blueprint(sms_auth_bp, url_prefix = f"/{MODULE_BASE}/sms")
|
||||
app.register_blueprint(sms_auth_bp, url_prefix = f"/{MODULE_BASE}/sms")
|
||||
# app.register_blueprint(sms_send_bp, url_prefix = f"/{MODULE_BASE}/sms")
|
||||
# app.register_blueprint(chat_auth_bp, url_prefix = f"/{MODULE_BASE}/chat")
|
||||
# app.register_blueprint(chat_webhook_bp, url_prefix = f"/{MODULE_BASE}/chat")
|
||||
@@ -347,6 +348,7 @@ async def app_startup(**kwargs):
|
||||
# ┛┗┣┛┻ ┗┛┗┛┛┗┗┛ ┗┛┗┗┗ ┛ ┛
|
||||
|
||||
current_app.mail_controller = MailController()
|
||||
current_app.sms_controller = SMSController()
|
||||
|
||||
# ┏┓ ┓ ┏┓┓•
|
||||
# ┃ ┏┓┏┓┏┓┏┓┏╋┏┓┏┓┏ ┏┓┏┓┏┫ ┃ ┃┓┏┓┏┓╋┏
|
||||
|
||||
Reference in New Issue
Block a user