Skip to content

Commit de0ee58

Browse files
committed
rename endpoint
1 parent d006508 commit de0ee58

File tree

3 files changed

+74
-72
lines changed

3 files changed

+74
-72
lines changed

backend/app/routers/authentication.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,37 @@ async def save_user(userIn: UserIn):
6767
return user.dict()
6868

6969

70-
@router.patch("/users", response_model=UserOut)
70+
@router.post("/login")
71+
async def login(userIn: UserLogin):
72+
try:
73+
token = keycloak_openid.token(userIn.email, userIn.password)
74+
return {"token": token["access_token"]}
75+
# bad credentials
76+
except KeycloakAuthenticationError as e:
77+
raise HTTPException(
78+
status_code=e.response_code,
79+
detail=json.loads(e.error_message),
80+
headers={"WWW-Authenticate": "Bearer"},
81+
)
82+
# account not fully setup (for example if new password is set to temporary)
83+
except KeycloakGetError as e:
84+
raise HTTPException(
85+
status_code=e.response_code,
86+
detail=json.loads(e.error_message),
87+
headers={"WWW-Authenticate": "Bearer"},
88+
)
89+
90+
91+
async def authenticate_user(email: str, password: str):
92+
user = await UserDB.find_one({"email": email})
93+
if not user:
94+
return None
95+
if not user.verify_password(password):
96+
return None
97+
return user
98+
99+
100+
@router.patch("/users/me", response_model=UserOut)
71101
async def update_current_user(
72102
userUpdate: UserUpdate, current_user=Depends(get_current_user)
73103
):
@@ -108,36 +138,6 @@ async def update_current_user(
108138
return user.dict()
109139

110140

111-
@router.post("/login")
112-
async def login(userIn: UserLogin):
113-
try:
114-
token = keycloak_openid.token(userIn.email, userIn.password)
115-
return {"token": token["access_token"]}
116-
# bad credentials
117-
except KeycloakAuthenticationError as e:
118-
raise HTTPException(
119-
status_code=e.response_code,
120-
detail=json.loads(e.error_message),
121-
headers={"WWW-Authenticate": "Bearer"},
122-
)
123-
# account not fully setup (for example if new password is set to temporary)
124-
except KeycloakGetError as e:
125-
raise HTTPException(
126-
status_code=e.response_code,
127-
detail=json.loads(e.error_message),
128-
headers={"WWW-Authenticate": "Bearer"},
129-
)
130-
131-
132-
async def authenticate_user(email: str, password: str):
133-
user = await UserDB.find_one({"email": email})
134-
if not user:
135-
return None
136-
if not user.verify_password(password):
137-
return None
138-
return user
139-
140-
141141
@router.get("/users/me/is_admin", response_model=bool)
142142
async def get_admin(
143143
dataset_id: str = None, current_username=Depends(get_current_user)

frontend/src/openapi/v2/services/LoginService.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ export class LoginService {
3131
}
3232

3333
/**
34-
* Update Current User
34+
* Login
3535
* @param requestBody
36-
* @returns UserOut Successful Response
36+
* @returns any Successful Response
3737
* @throws ApiError
3838
*/
39-
public static updateCurrentUserApiV2UsersPatch(
40-
requestBody: UserUpdate,
41-
): CancelablePromise<UserOut> {
39+
public static loginApiV2LoginPost(
40+
requestBody: UserLogin,
41+
): CancelablePromise<any> {
4242
return __request({
43-
method: 'PATCH',
44-
path: `/api/v2/users`,
43+
method: 'POST',
44+
path: `/api/v2/login`,
4545
body: requestBody,
4646
mediaType: 'application/json',
4747
errors: {
@@ -51,17 +51,17 @@ export class LoginService {
5151
}
5252

5353
/**
54-
* Login
54+
* Update Current User
5555
* @param requestBody
56-
* @returns any Successful Response
56+
* @returns UserOut Successful Response
5757
* @throws ApiError
5858
*/
59-
public static loginApiV2LoginPost(
60-
requestBody: UserLogin,
61-
): CancelablePromise<any> {
59+
public static updateCurrentUserApiV2UsersMePatch(
60+
requestBody: UserUpdate,
61+
): CancelablePromise<UserOut> {
6262
return __request({
63-
method: 'POST',
64-
path: `/api/v2/login`,
63+
method: 'PATCH',
64+
path: `/api/v2/users/me`,
6565
body: requestBody,
6666
mediaType: 'application/json',
6767
errors: {

openapi.json

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,20 @@
115115
}
116116
}
117117
}
118-
},
119-
"patch": {
118+
}
119+
},
120+
"/api/v2/login": {
121+
"post": {
120122
"tags": [
121123
"login"
122124
],
123-
"summary": "Update Current User",
124-
"operationId": "update_current_user_api_v2_users_patch",
125+
"summary": "Login",
126+
"operationId": "login_api_v2_login_post",
125127
"requestBody": {
126128
"content": {
127129
"application/json": {
128130
"schema": {
129-
"$ref": "#/components/schemas/UserUpdate"
131+
"$ref": "#/components/schemas/UserLogin"
130132
}
131133
}
132134
},
@@ -137,9 +139,7 @@
137139
"description": "Successful Response",
138140
"content": {
139141
"application/json": {
140-
"schema": {
141-
"$ref": "#/components/schemas/UserOut"
142-
}
142+
"schema": {}
143143
}
144144
}
145145
},
@@ -153,32 +153,21 @@
153153
}
154154
}
155155
}
156-
},
157-
"security": [
158-
{
159-
"OAuth2AuthorizationCodeBearer": []
160-
},
161-
{
162-
"APIKeyHeader": []
163-
},
164-
{
165-
"APIKeyCookie": []
166-
}
167-
]
156+
}
168157
}
169158
},
170-
"/api/v2/login": {
171-
"post": {
159+
"/api/v2/users/me": {
160+
"patch": {
172161
"tags": [
173162
"login"
174163
],
175-
"summary": "Login",
176-
"operationId": "login_api_v2_login_post",
164+
"summary": "Update Current User",
165+
"operationId": "update_current_user_api_v2_users_me_patch",
177166
"requestBody": {
178167
"content": {
179168
"application/json": {
180169
"schema": {
181-
"$ref": "#/components/schemas/UserLogin"
170+
"$ref": "#/components/schemas/UserUpdate"
182171
}
183172
}
184173
},
@@ -189,7 +178,9 @@
189178
"description": "Successful Response",
190179
"content": {
191180
"application/json": {
192-
"schema": {}
181+
"schema": {
182+
"$ref": "#/components/schemas/UserOut"
183+
}
193184
}
194185
}
195186
},
@@ -203,7 +194,18 @@
203194
}
204195
}
205196
}
206-
}
197+
},
198+
"security": [
199+
{
200+
"OAuth2AuthorizationCodeBearer": []
201+
},
202+
{
203+
"APIKeyHeader": []
204+
},
205+
{
206+
"APIKeyCookie": []
207+
}
208+
]
207209
}
208210
},
209211
"/api/v2/users/me/is_admin": {

0 commit comments

Comments
 (0)