Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
webomagic-auth
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Pratik Shrivastava
webomagic-auth
Commits
ad0bc218
Commit
ad0bc218
authored
Jul 23, 2024
by
deepdey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: fix otp-send service
parent
51fc02b7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
102 deletions
+92
-102
app/__init__.py
app/__init__.py
+3
-3
app/app_config/config.py
app/app_config/config.py
+2
-0
app/routes/user/__init__.py
app/routes/user/__init__.py
+2
-2
app/utils/mail_service.py
app/utils/mail_service.py
+7
-97
html_templates/otp-login-template.html
html_templates/otp-login-template.html
+78
-0
No files found.
app/__init__.py
View file @
ad0bc218
...
...
@@ -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
)
...
...
app/app_config/config.py
View file @
ad0bc218
...
...
@@ -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/'
)
...
...
app/routes/user/__init__.py
View file @
ad0bc218
...
...
@@ -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
)
...
...
app/utils/mail_service.py
View file @
ad0bc218
...
...
@@ -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'
...
...
html_templates/otp-login-template.html
0 → 100644
View file @
ad0bc218
<!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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment