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
8ddf56d5
Commit
8ddf56d5
authored
Jul 13, 2024
by
deepdey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: implement core logic
parent
55105971
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
8 deletions
+36
-8
app/orm/api_orm.py
app/orm/api_orm.py
+2
-2
app/routes/user/__init__.py
app/routes/user/__init__.py
+2
-4
app/routes/user/user_util.py
app/routes/user/user_util.py
+29
-0
database/query.sql
database/query.sql
+2
-2
database/schema.sql
database/schema.sql
+1
-0
No files found.
app/orm/api_orm.py
View file @
8ddf56d5
...
@@ -15,6 +15,6 @@ class Api(db.Model, SerializerMixin):
...
@@ -15,6 +15,6 @@ class Api(db.Model, SerializerMixin):
endpoint
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
endpoint
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
method
=
db
.
Column
(
db
.
String
(
10
),
nullable
=
False
)
method
=
db
.
Column
(
db
.
String
(
10
),
nullable
=
False
)
tag
=
db
.
Column
(
db
.
String
(
10
),
nullable
=
False
)
created_at
=
db
.
Column
(
db
.
DATETIME
,
default
=
datetime
.
now
)
created_at
=
db
.
Column
(
db
.
DATETIME
,
default
=
datetime
.
now
)
updated_at
=
db
.
Column
(
db
.
DATETIME
,
onupdate
=
datetime
.
now
)
updated_at
=
db
.
Column
(
db
.
DATETIME
,
onupdate
=
datetime
.
now
)
\ No newline at end of file
is_deleted
=
db
.
Column
(
db
.
Boolean
,
default
=
False
)
\ No newline at end of file
app/routes/user/__init__.py
View file @
8ddf56d5
...
@@ -15,9 +15,9 @@ from app import bcrypt
...
@@ -15,9 +15,9 @@ 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_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.redis
import
set_value
logger
=
get_logger
(
__name__
)
logger
=
get_logger
(
__name__
)
...
@@ -58,9 +58,7 @@ class Login(Resource):
...
@@ -58,9 +58,7 @@ class Login(Resource):
# fetch user role info
# fetch user role info
api_key
=
self
.
generate_api_key
()
api_key
=
self
.
generate_api_key
()
process_valid_loging
(
user_info
,
api_key
)
if
user_info
.
id
:
set_value
(
api_key
,
user_info
.
id
)
return
prepare_api_response
(
return
prepare_api_response
(
SUCCESS_CODE
,
SUCCESS_CODE
,
...
...
app/routes/user/user_util.py
0 → 100644
View file @
8ddf56d5
from
typing
import
List
from
app
import
orm
as
ORM
from
app.utils.redis
import
set_value
from
app
import
db
def
process_valid_loging
(
user_info
:
ORM
.
User
,
api_key
:
str
)
->
None
:
set_value
(
f
'{user_info.id}_un'
,
user_info
.
username
)
set_value
(
f
'{api_key}_id'
,
user_info
.
id
)
# TODO: currently we consider user have only one role
if
(
len
(
user_info
.
user_roles
)
>
0
):
set_value
(
f
'{api_key}_rid'
,
user_info
.
user_roles
[
0
]
.
role
.
id
)
set_value
(
f
'{user_info.id}_rn'
,
user_info
.
user_roles
[
0
]
.
role
.
role_name
)
set_value
(
f
'{user_info.id}_rt'
,
user_info
.
user_roles
[
0
]
.
role
.
role_type
.
role_name
)
# TODO: fetch all api mapped with role id and set in redis
api_list
:
List
[
ORM
.
Api
]
=
db
.
session
.
query
(
ORM
.
Api
)
.
join
(
ORM
.
RoleApiMap
,
ORM
.
Api
.
id
==
ORM
.
RoleApiMap
.
api_id
)
\
.
filter
(
ORM
.
RoleApiMap
.
role_id
==
user_info
.
user_roles
[
0
]
.
role
.
id
,
ORM
.
Api
.
tag
==
'RA'
)
\
.
all
()
for
api
in
api_list
:
set_value
(
f
'r_{user_info.user_roles[0].role.id}_{api.id}_{api.method}'
,
1
)
\ No newline at end of file
database/query.sql
View file @
8ddf56d5
...
@@ -38,6 +38,6 @@ VALUES
...
@@ -38,6 +38,6 @@ VALUES
(
3
,
'PRODUCT_MANAGER'
,
1
,
false
);
(
3
,
'PRODUCT_MANAGER'
,
1
,
false
);
INSERT
INTO
INSERT
INTO
public
.
webomagic_api
(
endpoint
,
method
)
public
.
webomagic_api
(
endpoint
,
method
,
tag
)
VALUES
VALUES
(
'/webomagic-user/v1/profile'
,
'GET'
);
(
'/webomagic-user/v1/profile'
,
'GET'
,
'RA'
);
database/schema.sql
View file @
8ddf56d5
...
@@ -3,6 +3,7 @@ CREATE TABLE
...
@@ -3,6 +3,7 @@ CREATE TABLE
id
BIGSERIAL
PRIMARY
KEY
NOT
NULL
,
id
BIGSERIAL
PRIMARY
KEY
NOT
NULL
,
endpoint
VARCHAR
(
255
)
NOT
NULL
,
endpoint
VARCHAR
(
255
)
NOT
NULL
,
method
VARCHAR
(
10
)
NOT
NULL
,
method
VARCHAR
(
10
)
NOT
NULL
,
tag
VARCHAR
(
10
)
NOT
NULL
,
created_at
TIMESTAMP
NOT
NULL
DEFAULT
now
(),
created_at
TIMESTAMP
NOT
NULL
DEFAULT
now
(),
updated_at
TIMESTAMP
updated_at
TIMESTAMP
);
);
...
...
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