|
| 1 | +# Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. |
| 2 | +# |
| 3 | +# This software is licensed under the Apache License, Version 2.0 (the |
| 4 | +# "License") as published by the Apache Software Foundation. |
| 5 | +# |
| 6 | +# You may not use this file except in compliance with the License. You may |
| 7 | +# obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +# License for the specific language governing permissions and limitations |
| 13 | +# under the License. |
| 14 | +from __future__ import annotations |
| 15 | + |
| 16 | +from typing import TYPE_CHECKING |
| 17 | + |
| 18 | +if TYPE_CHECKING: |
| 19 | + from supertokens_python.recipe.dashboard.interfaces import APIInterface, APIOptions |
| 20 | + |
| 21 | +from supertokens_python.exceptions import raise_bad_input_exception |
| 22 | +from supertokens_python.normalised_url_path import NormalisedURLPath |
| 23 | +from supertokens_python.querier import Querier |
| 24 | +from supertokens_python.utils import send_200_response |
| 25 | + |
| 26 | + |
| 27 | +async def handle_emailpassword_signin_api(_: APIInterface, api_options: APIOptions): |
| 28 | + body = await api_options.request.json() |
| 29 | + if body is None: |
| 30 | + raise_bad_input_exception("Please send body") |
| 31 | + email = body.get("email") |
| 32 | + password = body.get("password") |
| 33 | + |
| 34 | + if email is None or not isinstance(email, str): |
| 35 | + raise_bad_input_exception("Missing required parameter 'email'") |
| 36 | + if password is None or not isinstance(password, str): |
| 37 | + raise_bad_input_exception("Missing required parameter 'password'") |
| 38 | + response = await Querier.get_instance().send_post_request( |
| 39 | + NormalisedURLPath("/recipe/dashboard/signin"), |
| 40 | + {"email": email, "password": password}, |
| 41 | + ) |
| 42 | + |
| 43 | + if "status" in response and response["status"] == "OK": |
| 44 | + return send_200_response( |
| 45 | + {"status": "OK", "sessionId": response["sessionId"]}, api_options.response |
| 46 | + ) |
| 47 | + if "status" in response and response["status"] == "INVALID_CREDENTIALS_ERROR": |
| 48 | + return send_200_response( |
| 49 | + {"status": "INVALID_CREDENTIALS_ERROR"}, |
| 50 | + api_options.response, |
| 51 | + ) |
| 52 | + if "status" in response and response["status"] == "USER_SUSPENDED_ERROR": |
| 53 | + return send_200_response( |
| 54 | + {"status": "USER_SUSPENDED_ERROR", "message": response["message"]}, |
| 55 | + api_options.response, |
| 56 | + ) |
0 commit comments