Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
balancer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
adb1f3cd
authored
Mar 09, 2023
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfixes
parent
9a6f23b7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
20 deletions
+26
-20
core/models.py
+5
-4
main.py
+2
-8
sredis/models.py
+2
-4
sredis/sredis.py
+17
-4
No files found.
core/models.py
View file @
adb1f3cd
from
typing
import
Union
from
typing
import
Union
from
pydantic
import
BaseModel
,
Field
,
EmailStr
from
pydantic
import
BaseModel
,
EmailStr
class
User
(
BaseModel
):
class
User
(
BaseModel
):
username
:
str
username
:
str
...
@@ -14,13 +14,13 @@ class Token(BaseModel):
...
@@ -14,13 +14,13 @@ class Token(BaseModel):
token
:
str
token
:
str
class
UserLoginSchema
(
BaseModel
):
class
UserLoginSchema
(
BaseModel
):
username
:
EmailStr
=
Field
(
...
)
username
:
str
password
:
str
=
Field
(
...
)
password
:
str
class
Config
:
class
Config
:
schema_extra
=
{
schema_extra
=
{
"example"
:
{
"example"
:
{
"
email"
:
"abdulazeez@x.com
"
,
"
username"
:
"user
"
,
"password"
:
"weakpassword"
"password"
:
"weakpassword"
}
}
}
}
\ No newline at end of file
main.py
View file @
adb1f3cd
...
@@ -8,8 +8,7 @@ from sredis.sredis import *
...
@@ -8,8 +8,7 @@ from sredis.sredis import *
from
sredis.models
import
*
from
sredis.models
import
*
import
logging
import
logging
from
core.models
import
User
,
DataCenter
,
Token
from
core.models
import
User
,
DataCenter
,
Token
from
uuid
import
uuid4
from
core.auth
import
signJWT
from
core.auth
import
signJWT
,
hash_pass
from
core.bearer
import
get_current_user
from
core.bearer
import
get_current_user
logging
.
config
.
fileConfig
(
'logging.conf'
,
disable_existing_loggers
=
False
)
logging
.
config
.
fileConfig
(
'logging.conf'
,
disable_existing_loggers
=
False
)
...
@@ -26,12 +25,7 @@ add_datacenter("https://kappa3.fured.cloud.bme.hu")
...
@@ -26,12 +25,7 @@ add_datacenter("https://kappa3.fured.cloud.bme.hu")
@app.post
(
"/user/signup"
,
tags
=
[
"user"
])
@app.post
(
"/user/signup"
,
tags
=
[
"user"
])
async
def
create_user
(
user
:
User
=
Body
(
...
)):
async
def
create_user
(
user
:
User
=
Body
(
...
)):
user
=
PUser
(
create_puser
(
user
)
username
=
user
.
username
,
email
=
user
.
email
,
password
=
hash_pass
(
user
.
password
)
)
user
.
save
()
return
signJWT
(
user
.
username
)
return
signJWT
(
user
.
username
)
@app.post
(
"/user/login"
,
tags
=
[
"user"
])
@app.post
(
"/user/login"
,
tags
=
[
"user"
])
...
...
sredis/models.py
View file @
adb1f3cd
import
datetime
from
redis_om
import
HashModel
,
Field
from
typing
import
Optional
from
redis_om
import
HashModel
from
pydantic
import
EmailStr
from
pydantic
import
EmailStr
class
PUser
(
HashModel
):
class
PUser
(
HashModel
):
username
:
str
username
:
str
=
Field
(
index
=
True
)
email
:
EmailStr
email
:
EmailStr
password
:
str
password
:
str
sredis/sredis.py
View file @
adb1f3cd
import
redis
import
redis
from
core.auth
import
hash_pass
from
core.models
import
UserLoginSchema
from
core.models
import
UserLoginSchema
from
.models
import
PUser
from
.models
import
PUser
from
passlib.hash
import
pbkdf2_sha256
from
passlib.hash
import
pbkdf2_sha256
from
core.models
import
User
from
core.auth
import
hash_pass
from
fastapi
import
HTTPException
from
redis_om
import
Migrator
r
=
redis
.
Redis
(
host
=
'localhost'
,
port
=
6379
,
db
=
0
,
decode_responses
=
True
)
r
=
redis
.
Redis
(
host
=
'localhost'
,
port
=
6379
,
db
=
0
,
decode_responses
=
True
)
r
.
set
(
"datacenters_cnt"
,
1
)
r
.
set
(
"datacenters_cnt"
,
1
)
...
@@ -33,7 +36,18 @@ def get_datacenter_token(username: str, datacenter: str):
...
@@ -33,7 +36,18 @@ def get_datacenter_token(username: str, datacenter: str):
return
str
(
r
.
hget
(
f
"tokens:{username}"
,
datacenter
))
return
str
(
r
.
hget
(
f
"tokens:{username}"
,
datacenter
))
def
check_user
(
data
:
UserLoginSchema
):
def
check_user
(
data
:
UserLoginSchema
):
user
=
PUser
.
find
(
(
PUser
.
username
==
data
.
username
)
)
.
all
()
user
=
PUser
.
find
(
PUser
.
username
==
data
.
username
)
.
all
()
if
pbkdf2_sha256
.
verify
(
data
.
password
,
user
[
0
]
.
password
):
if
pbkdf2_sha256
.
verify
(
data
.
password
,
user
[
0
]
.
password
):
return
user
[
0
]
return
user
[
0
]
return
False
return
False
\ No newline at end of file
def
create_puser
(
user
:
User
):
s
=
PUser
.
find
(
PUser
.
username
==
'karsa'
)
.
all
()
if
s
:
raise
HTTPException
(
status_code
=
403
,
detail
=
"User already exists"
)
user
=
PUser
(
username
=
user
.
username
,
email
=
user
.
email
,
password
=
hash_pass
(
user
.
password
)
)
user
.
save
()
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