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
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
18 deletions
+25
-18
core/models.py
+5
-4
main.py
+2
-8
sredis/models.py
+2
-4
sredis/sredis.py
+16
-2
No files found.
core/models.py
View file @
adb1f3cd
from
typing
import
Union
from
pydantic
import
BaseModel
,
Field
,
EmailStr
from
pydantic
import
BaseModel
,
EmailStr
class
User
(
BaseModel
):
username
:
str
...
...
@@ -14,13 +14,13 @@ class Token(BaseModel):
token
:
str
class
UserLoginSchema
(
BaseModel
):
username
:
EmailStr
=
Field
(
...
)
password
:
str
=
Field
(
...
)
username
:
str
password
:
str
class
Config
:
schema_extra
=
{
"example"
:
{
"
email"
:
"abdulazeez@x.com
"
,
"
username"
:
"user
"
,
"password"
:
"weakpassword"
}
}
\ No newline at end of file
main.py
View file @
adb1f3cd
...
...
@@ -8,8 +8,7 @@ from sredis.sredis import *
from
sredis.models
import
*
import
logging
from
core.models
import
User
,
DataCenter
,
Token
from
uuid
import
uuid4
from
core.auth
import
signJWT
,
hash_pass
from
core.auth
import
signJWT
from
core.bearer
import
get_current_user
logging
.
config
.
fileConfig
(
'logging.conf'
,
disable_existing_loggers
=
False
)
...
...
@@ -26,12 +25,7 @@ add_datacenter("https://kappa3.fured.cloud.bme.hu")
@app.post
(
"/user/signup"
,
tags
=
[
"user"
])
async
def
create_user
(
user
:
User
=
Body
(
...
)):
user
=
PUser
(
username
=
user
.
username
,
email
=
user
.
email
,
password
=
hash_pass
(
user
.
password
)
)
user
.
save
()
create_puser
(
user
)
return
signJWT
(
user
.
username
)
@app.post
(
"/user/login"
,
tags
=
[
"user"
])
...
...
sredis/models.py
View file @
adb1f3cd
import
datetime
from
typing
import
Optional
from
redis_om
import
HashModel
from
redis_om
import
HashModel
,
Field
from
pydantic
import
EmailStr
class
PUser
(
HashModel
):
username
:
str
username
:
str
=
Field
(
index
=
True
)
email
:
EmailStr
password
:
str
sredis/sredis.py
View file @
adb1f3cd
import
redis
from
core.auth
import
hash_pass
from
core.models
import
UserLoginSchema
from
.models
import
PUser
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
.
set
(
"datacenters_cnt"
,
1
)
...
...
@@ -33,7 +36,18 @@ def get_datacenter_token(username: str, datacenter: str):
return
str
(
r
.
hget
(
f
"tokens:{username}"
,
datacenter
))
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
):
return
user
[
0
]
return
False
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