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
2fb82414
Commit
2fb82414
authored
Jul 20, 2024
by
Pratik Shrivastava
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: make generate_api_key() a generic function in utils
parent
d1c917f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
10 deletions
+8
-10
app/routes/user/__init__.py
app/routes/user/__init__.py
+3
-10
app/routes/user/user_util.py
app/routes/user/user_util.py
+5
-0
No files found.
app/routes/user/__init__.py
View file @
2fb82414
...
@@ -6,7 +6,6 @@ from flask import request
...
@@ -6,7 +6,6 @@ from flask import request
from
flask_restx
import
Resource
from
flask_restx
import
Resource
from
marshmallow
import
ValidationError
from
marshmallow
import
ValidationError
from
app.app_config.config
import
get_logger
from
app.app_config.config
import
get_logger
from
app.app_config.constant
import
ALPHANUMARIC_STRING
from
app.app_config.response_code
import
*
from
app.app_config.response_code
import
*
from
app.app_config.response_message
import
*
from
app.app_config.response_message
import
*
from
app.app_config.swagger_config
import
SECURITY
from
app.app_config.swagger_config
import
SECURITY
...
@@ -18,7 +17,7 @@ from app import bcrypt
...
@@ -18,7 +17,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
,
generate_otp
from
app.routes.user.user_util
import
process_valid_loging
,
generate_otp
,
generate_api_key
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
...
@@ -36,9 +35,6 @@ ns = api.namespace(
...
@@ -36,9 +35,6 @@ ns = api.namespace(
@
ns
.
route
(
'/login'
,
methods
=
[
'POST'
])
@
ns
.
route
(
'/login'
,
methods
=
[
'POST'
])
class
Login
(
Resource
):
class
Login
(
Resource
):
def
generate_api_key
(
self
)
->
str
:
return
''
.
join
(
secrets
.
choice
(
ALPHANUMARIC_STRING
)
for
_
in
range
(
18
))
@
ns
.
expect
(
*
login_payload
())
@
ns
.
expect
(
*
login_payload
())
@
ns
.
response
(
*
login_response
())
@
ns
.
response
(
*
login_response
())
@
sanitized
()
@
sanitized
()
...
@@ -60,7 +56,7 @@ class Login(Resource):
...
@@ -60,7 +56,7 @@ class Login(Resource):
if
not
bcrypt
.
check_password_hash
(
user_info
.
password
,
password
):
if
not
bcrypt
.
check_password_hash
(
user_info
.
password
,
password
):
return
prepare_api_response
(
401
,
'Invalid password'
)
return
prepare_api_response
(
401
,
'Invalid password'
)
api_key
=
self
.
generate_api_key
()
api_key
=
generate_api_key
()
process_valid_loging
(
user_info
,
api_key
)
process_valid_loging
(
user_info
,
api_key
)
return
prepare_api_response
(
return
prepare_api_response
(
...
@@ -127,9 +123,6 @@ class LoginOTP(Resource):
...
@@ -127,9 +123,6 @@ class LoginOTP(Resource):
@
ns
.
route
(
'/login-otp-verify'
,
methods
=
[
'POST'
])
@
ns
.
route
(
'/login-otp-verify'
,
methods
=
[
'POST'
])
class
LoginOTPVerify
(
Resource
):
class
LoginOTPVerify
(
Resource
):
def
generate_api_key
(
self
)
->
str
:
return
''
.
join
(
secrets
.
choice
(
ALPHANUMARIC_STRING
)
for
_
in
range
(
18
))
@
ns
.
expect
(
*
otp_verify_payload
())
@
ns
.
expect
(
*
otp_verify_payload
())
@
ns
.
response
(
*
otp_verify_response
())
@
ns
.
response
(
*
otp_verify_response
())
@
sanitized
()
@
sanitized
()
...
@@ -154,7 +147,7 @@ class LoginOTPVerify(Resource):
...
@@ -154,7 +147,7 @@ class LoginOTPVerify(Resource):
raise
Exception
(
'OTP is invalid.'
)
raise
Exception
(
'OTP is invalid.'
)
api_key
=
self
.
generate_api_key
()
api_key
=
generate_api_key
()
process_valid_loging
(
user_info
,
api_key
)
process_valid_loging
(
user_info
,
api_key
)
return
prepare_api_response
(
return
prepare_api_response
(
...
...
app/routes/user/user_util.py
View file @
2fb82414
...
@@ -4,6 +4,7 @@ from typing import List
...
@@ -4,6 +4,7 @@ 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
from
app
import
db
from
app
import
db
from
app.app_config.constant
import
ALPHANUMARIC_STRING
def
process_valid_loging
(
user_info
:
ORM
.
User
,
api_key
:
str
)
->
None
:
def
process_valid_loging
(
user_info
:
ORM
.
User
,
api_key
:
str
)
->
None
:
...
@@ -46,3 +47,7 @@ def process_valid_loging(user_info: ORM.User, api_key: str) -> None:
...
@@ -46,3 +47,7 @@ def process_valid_loging(user_info: ORM.User, api_key: str) -> None:
def
generate_otp
()
->
str
:
def
generate_otp
()
->
str
:
return
''
.
join
(
secrets
.
choice
(
string
.
digits
)
for
_
in
range
(
6
))
return
''
.
join
(
secrets
.
choice
(
string
.
digits
)
for
_
in
range
(
6
))
def
generate_api_key
()
->
str
:
return
''
.
join
(
secrets
.
choice
(
ALPHANUMARIC_STRING
)
for
_
in
range
(
18
))
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