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
d1c917f5
Commit
d1c917f5
authored
Jul 20, 2024
by
Pratik Shrivastava
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: make generate_otp a generic function in utils
parent
7cdb26db
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
5 deletions
+8
-5
app/routes/user/__init__.py
app/routes/user/__init__.py
+2
-5
app/routes/user/user_util.py
app/routes/user/user_util.py
+6
-0
No files found.
app/routes/user/__init__.py
View file @
d1c917f5
...
@@ -18,7 +18,7 @@ from app import bcrypt
...
@@ -18,7 +18,7 @@ from app import bcrypt
from
app.routes.user.user_payload
import
*
from
app.routes.user.user_payload
import
*
from
app.routes.user.user_response
import
*
from
app.routes.user.user_response
import
*
from
app.routes.user.user_dao_service
import
*
from
app.routes.user.user_dao_service
import
*
from
app.routes.user.user_util
import
process_valid_loging
from
app.routes.user.user_util
import
process_valid_loging
,
generate_otp
from
app.routes.user.user_validator
import
*
from
app.routes.user.user_validator
import
*
from
app.utils.api_response
import
prepare_api_response
from
app.utils.api_response
import
prepare_api_response
from
app.utils.mail_service
import
send_otp
from
app.utils.mail_service
import
send_otp
...
@@ -84,9 +84,6 @@ class Login(Resource):
...
@@ -84,9 +84,6 @@ class Login(Resource):
@
ns
.
route
(
'/login-otp'
,
methods
=
[
'POST'
])
@
ns
.
route
(
'/login-otp'
,
methods
=
[
'POST'
])
class
LoginOTP
(
Resource
):
class
LoginOTP
(
Resource
):
def
generate_otp
(
self
)
->
str
:
return
''
.
join
(
secrets
.
choice
(
string
.
digits
)
for
_
in
range
(
6
))
@
ns
.
expect
(
*
otp_payload
())
@
ns
.
expect
(
*
otp_payload
())
@
ns
.
response
(
*
otp_response
())
@
ns
.
response
(
*
otp_response
())
@
sanitized
()
@
sanitized
()
...
@@ -102,7 +99,7 @@ class LoginOTP(Resource):
...
@@ -102,7 +99,7 @@ class LoginOTP(Resource):
if
(
not
user_info
):
if
(
not
user_info
):
return
prepare_api_response
(
401
,
'Invalid Email'
)
return
prepare_api_response
(
401
,
'Invalid Email'
)
otp
:
int
=
self
.
generate_otp
()
otp
:
int
=
generate_otp
()
send_otp
(
'shadowtitan3003@gmail.com'
,
[
email
],
otp
)
send_otp
(
'shadowtitan3003@gmail.com'
,
[
email
],
otp
)
...
...
app/routes/user/user_util.py
View file @
d1c917f5
import
string
import
secrets
from
typing
import
List
from
typing
import
List
from
app
import
orm
as
ORM
from
app
import
orm
as
ORM
from
app.utils.redis
import
set_value
from
app.utils.redis
import
set_value
...
@@ -40,3 +42,7 @@ def process_valid_loging(user_info: ORM.User, api_key: str) -> None:
...
@@ -40,3 +42,7 @@ def process_valid_loging(user_info: ORM.User, api_key: str) -> None:
1
,
1
,
60
*
60
*
24
,
60
*
60
*
24
,
)
)
def
generate_otp
()
->
str
:
return
''
.
join
(
secrets
.
choice
(
string
.
digits
)
for
_
in
range
(
6
))
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