Commit ad0bc218 authored by deepdey's avatar deepdey

chore: fix otp-send service

parent 51fc02b7
......@@ -3,7 +3,7 @@ from flask_cors import CORS
from flask_bcrypt import Bcrypt
from flask_mail import Mail
from flask_sqlalchemy import SQLAlchemy
from app.app_config.config import DB_URI, MAIL_DEFAULT_SENDER, MAIL_PASSWORD, MAIL_PORT, MAIL_SERVER, MAIL_USERNAME
from app.app_config.config import *
db: SQLAlchemy = SQLAlchemy()
bcrypt: Bcrypt = Bcrypt()
......@@ -18,8 +18,8 @@ def create_app():
# mail configuration
app.config['MAIL_SERVER'] = MAIL_SERVER
app.config['MAIL_PORT'] = MAIL_PORT
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USE_SSL'] = False
app.config['MAIL_USE_TLS'] = MAIL_USE_TLS
app.config['MAIL_USE_SSL'] = MAIL_USE_SSL
app.config['MAIL_USERNAME'] = MAIL_USERNAME
app.config['MAIL_PASSWORD'] = MAIL_PASSWORD
app.config['MAIL_DEFAULT_SENDER'] = (MAIL_DEFAULT_SENDER, MAIL_USERNAME)
......
......@@ -30,6 +30,8 @@ MAIL_PORT: int = os.environ.get('MAIL_PORT', 587)
MAIL_USERNAME = os.environ.get('MAIL_USERNAME', 'deep.websofttechs@gmail.com')
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD', 'xtzsnezbtawrsbwn')
MAIL_DEFAULT_SENDER = os.environ.get('MAIL_DEFAULT_SENDER', 'Webomagic Admin')
MAIL_USE_TLS: bool = os.environ.get('MAIL_USE_TLS', 'True') == 'True'
MAIL_USE_SSL: bool = os.environ.get('MAIL_USE_SSL', 'False') == 'True'
LOGGER_PATH: str = os.environ.get('LOGGER_PATH', '/etc/webomagic_user/logs/')
......
......@@ -5,7 +5,7 @@ import secrets
from flask import request
from flask_restx import Resource
from marshmallow import ValidationError
from app.app_config.config import get_logger
from app.app_config.config import MAIL_DEFAULT_SENDER, get_logger
from app.app_config.constant import ALPHANUMARIC_STRING
from app.app_config.response_code import *
from app.app_config.response_message import *
......@@ -102,7 +102,7 @@ class LoginOTP(Resource):
otp: int = self.generate_otp()
send_otp('shadowtitan3003@gmail.com', [email], otp)
send_otp(MAIL_DEFAULT_SENDER, email, otp)
redis_key: str = str(user_info.id) + '_' + 'otp' + str(otp)
set_value(redis_key, 1, 60 * 5)
......
......@@ -3,106 +3,16 @@ from flask_mail import Message
from app import mail
def send_otp(sender: str, receiver: list, otp: int) -> None:
def send_otp(sender: str, receiver: str, otp: int) -> None:
email_title = 'OTP for Login'
msg = Message(email_title, sender=sender, recipients=receiver)
msg = Message(email_title, sender=sender, recipients=[receiver])
# Define the OTP template
email_html = '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>OTP Template</title>
<link
href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap"
rel="stylesheet"
/>
</head>
<body
style="
margin: 0;
font-family: 'Poppins', sans-serif;
background: #ffffff;
font-size: 14px;
"
>
<div
style="
max-width: 680px;
margin: 0 auto;
padding: 45px 30px 60px;
background: #f4f7ff;
font-size: 14px;
color: #434343;
"
>
<main>
<div
style="
margin: 0;
margin-top: 70px;
padding: 92px 30px 115px;
background: #ffffff;
border-radius: 30px;
text-align: center;
"
>
<div style="width: 100%; max-width: 489px; margin: 0 auto;">
<h1
style="
margin: 0;
font-size: 24px;
font-weight: 500;
color: #1f1f1f;
"
>
OTP Verification
</h1>
<p
style="
margin: 0;
margin-top: 17px;
font-size: 16px;
font-weight: 500;
"
>
Hey {{ user }},
</p>
<p
style="
margin: 0;
margin-top: 17px;
font-weight: 500;
letter-spacing: 0.56px;
"
>
Use the following OTP to login. OTP is valid for
<span style="font-weight: 600; color: #1f1f1f;">5 minutes</span>.
Do not share this code with others.
</p>
<p
style="
margin: 0;
margin-top: 60px;
font-size: 40px;
font-weight: 600;
letter-spacing: 25px;
color: #ba3d4f;
"
>
{{ otp }}
</p>
</div>
</div>
</main>
</div>
</body>
</html>
'''
email_html_rendered = render_template_string(email_html, user=receiver[0], otp=otp)
html_content: str = ''
with open('html_templates/otp-login-template.html', 'r') as file:
html_content = file.read()
email_html_rendered = render_template_string(html_content, user=receiver, otp=otp)
msg.html = email_html_rendered
msg.subject = 'OTP Verification for Login'
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>OTP Template</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap" rel="stylesheet" />
</head>
<body style="
margin: 0;
font-family: 'Poppins', sans-serif;
background: #ffffff;
font-size: 14px;
">
<div style="
max-width: 680px;
margin: 0 auto;
padding: 45px 30px 60px;
background: #f4f7ff;
font-size: 14px;
color: #434343;
">
<main>
<div style="
margin: 0;
margin-top: 70px;
padding: 92px 30px 115px;
background: #ffffff;
border-radius: 30px;
text-align: center;
">
<div style="width: 100%; max-width: 489px; margin: 0 auto;">
<h1 style="
margin: 0;
font-size: 24px;
font-weight: 500;
color: #1f1f1f;
">
OTP Verification
</h1>
<p style="
margin: 0;
margin-top: 17px;
font-size: 16px;
font-weight: 500;
">
Hey {{ user }},
</p>
<p style="
margin: 0;
margin-top: 17px;
font-weight: 500;
letter-spacing: 0.56px;
">
Use the following OTP to login. OTP is valid for
<span style="font-weight: 600; color: #1f1f1f;">5 minutes</span>.
Do not share this code with others.
</p>
<p style="
margin: 0;
margin-top: 60px;
font-size: 40px;
font-weight: 600;
letter-spacing: 25px;
color: #ba3d4f;
">
{{ otp }}
</p>
</div>
</div>
</main>
</div>
</body>
</html>
\ 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