get all users
Browse files- App/Users/Schema.py +8 -1
- App/Users/UserRoutes.py +16 -0
App/Users/Schema.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from pydantic import BaseModel, Field, constr
|
2 |
from typing import Optional
|
3 |
from datetime import datetime
|
4 |
from passlib.context import CryptContext
|
@@ -10,6 +10,13 @@ PHONE_PATTERN = r"^(?:\+255|0)\d{9}$"
|
|
10 |
MAC_PATTERN = r"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$"
|
11 |
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
# Register User Request
|
14 |
class RegisterUserRequest(BaseModel):
|
15 |
name: str = Field(..., max_length=100)
|
|
|
1 |
+
from pydantic import BaseModel, Field, constr, ConfigDict
|
2 |
from typing import Optional
|
3 |
from datetime import datetime
|
4 |
from passlib.context import CryptContext
|
|
|
10 |
MAC_PATTERN = r"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$"
|
11 |
|
12 |
|
13 |
+
class UserResponse(BaseModel):
|
14 |
+
id: str
|
15 |
+
phoneNumber: str
|
16 |
+
name: str
|
17 |
+
model_config = ConfigDict(from_attributes=True)
|
18 |
+
|
19 |
+
|
20 |
# Register User Request
|
21 |
class RegisterUserRequest(BaseModel):
|
22 |
name: str = Field(..., max_length=100)
|
App/Users/UserRoutes.py
CHANGED
@@ -7,10 +7,13 @@ from .Schema import (
|
|
7 |
VerifyResetTokenRequest,
|
8 |
ResetPasswordRequest,
|
9 |
BaseResponse,
|
|
|
10 |
)
|
11 |
from .Model import User
|
12 |
from jose import jwt
|
|
|
13 |
from datetime import datetime, timedelta
|
|
|
14 |
|
15 |
# JWT Configurations
|
16 |
SECRET_KEY = "your_secret_key_here"
|
@@ -37,6 +40,11 @@ async def register_user(request: RegisterUserRequest):
|
|
37 |
raise HTTPException(
|
38 |
status_code=status.HTTP_400_BAD_REQUEST, detail="User already exists."
|
39 |
)
|
|
|
|
|
|
|
|
|
|
|
40 |
request.hash_password()
|
41 |
new_user = await User.create(**request.dict())
|
42 |
return BaseResponse(
|
@@ -100,3 +108,11 @@ async def reset_password(request: ResetPasswordRequest):
|
|
100 |
status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid or expired token."
|
101 |
)
|
102 |
return BaseResponse(code=200, message="Password has been reset successfully.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
VerifyResetTokenRequest,
|
8 |
ResetPasswordRequest,
|
9 |
BaseResponse,
|
10 |
+
UserResponse,
|
11 |
)
|
12 |
from .Model import User
|
13 |
from jose import jwt
|
14 |
+
from typing import List
|
15 |
from datetime import datetime, timedelta
|
16 |
+
from App.Android.Android import AndroidClient
|
17 |
|
18 |
# JWT Configurations
|
19 |
SECRET_KEY = "your_secret_key_here"
|
|
|
40 |
raise HTTPException(
|
41 |
status_code=status.HTTP_400_BAD_REQUEST, detail="User already exists."
|
42 |
)
|
43 |
+
# client part
|
44 |
+
client = AndroidClient()
|
45 |
+
print(request.json())
|
46 |
+
response = await client.register_user(request=request)
|
47 |
+
print(response)
|
48 |
request.hash_password()
|
49 |
new_user = await User.create(**request.dict())
|
50 |
return BaseResponse(
|
|
|
108 |
status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid or expired token."
|
109 |
)
|
110 |
return BaseResponse(code=200, message="Password has been reset successfully.")
|
111 |
+
|
112 |
+
|
113 |
+
@user_router.get(
|
114 |
+
"/user/all", response_model=List[UserResponse], status_code=status.HTTP_200_OK
|
115 |
+
)
|
116 |
+
async def get_all_users():
|
117 |
+
users = await User.all()
|
118 |
+
return [UserResponse.from_orm(user) for user in users]
|