mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Fix password login exception
This commit is contained in:
parent
c2d2d2543f
commit
3d69b62d7d
4 changed files with 13 additions and 7 deletions
|
@ -34,7 +34,7 @@ class ApiLoginRoyalnetStar(ApiStar):
|
|||
raise NotFoundError("User not found")
|
||||
pswd_check = user.test_password(password)
|
||||
if not pswd_check:
|
||||
raise ApiError("Invalid password")
|
||||
raise UnauthorizedError("Invalid password")
|
||||
token: Token = TokenT.generate(alchemy=self.alchemy, user=user, expiration_delta=datetime.timedelta(days=7))
|
||||
session.add(token)
|
||||
await ru.asyncify(session.commit)
|
||||
|
|
|
@ -9,7 +9,7 @@ from .apierrors import \
|
|||
ParameterError, \
|
||||
MissingParameterError, \
|
||||
InvalidParameterError, \
|
||||
NotImplementedError, \
|
||||
MethodNotImplementedError, \
|
||||
UnsupportedError
|
||||
|
||||
|
||||
|
@ -29,6 +29,6 @@ __all__ = [
|
|||
"ParameterError",
|
||||
"MissingParameterError",
|
||||
"InvalidParameterError",
|
||||
"NotImplementedError",
|
||||
"MethodNotImplementedError",
|
||||
"UnsupportedError",
|
||||
]
|
||||
|
|
|
@ -6,6 +6,10 @@ class NotFoundError(ApiError):
|
|||
pass
|
||||
|
||||
|
||||
class UnauthorizedError(ApiError):
|
||||
pass
|
||||
|
||||
|
||||
class ForbiddenError(ApiError):
|
||||
pass
|
||||
|
||||
|
@ -26,9 +30,9 @@ class InvalidParameterError(ParameterError):
|
|||
pass
|
||||
|
||||
|
||||
class NotImplementedError(ApiError):
|
||||
class MethodNotImplementedError(ApiError):
|
||||
pass
|
||||
|
||||
|
||||
class UnsupportedError(NotImplementedError):
|
||||
class UnsupportedError(MethodNotImplementedError):
|
||||
pass
|
||||
|
|
|
@ -32,11 +32,13 @@ class ApiStar(PageStar, ABC):
|
|||
apidata = ApiData(data=data, star=self, method=request.method)
|
||||
try:
|
||||
response = await self.api(apidata)
|
||||
except UnauthorizedError as e:
|
||||
return api_error(e, code=401)
|
||||
except NotFoundError as e:
|
||||
return api_error(e, code=404)
|
||||
except ForbiddenError as e:
|
||||
return api_error(e, code=403)
|
||||
except NotImplementedError as e:
|
||||
except MethodNotImplementedError as e:
|
||||
return api_error(e, code=501)
|
||||
except BadRequestError as e:
|
||||
return api_error(e, code=400)
|
||||
|
@ -49,7 +51,7 @@ class ApiStar(PageStar, ABC):
|
|||
await apidata.session_close()
|
||||
|
||||
async def api(self, data: ApiData) -> ru.JSON:
|
||||
raise NotImplementedError()
|
||||
raise MethodNotImplementedError()
|
||||
|
||||
@classmethod
|
||||
def swagger(cls) -> ru.JSON:
|
||||
|
|
Loading…
Reference in a new issue