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")
|
raise NotFoundError("User not found")
|
||||||
pswd_check = user.test_password(password)
|
pswd_check = user.test_password(password)
|
||||||
if not pswd_check:
|
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))
|
token: Token = TokenT.generate(alchemy=self.alchemy, user=user, expiration_delta=datetime.timedelta(days=7))
|
||||||
session.add(token)
|
session.add(token)
|
||||||
await ru.asyncify(session.commit)
|
await ru.asyncify(session.commit)
|
||||||
|
|
|
@ -9,7 +9,7 @@ from .apierrors import \
|
||||||
ParameterError, \
|
ParameterError, \
|
||||||
MissingParameterError, \
|
MissingParameterError, \
|
||||||
InvalidParameterError, \
|
InvalidParameterError, \
|
||||||
NotImplementedError, \
|
MethodNotImplementedError, \
|
||||||
UnsupportedError
|
UnsupportedError
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,6 +29,6 @@ __all__ = [
|
||||||
"ParameterError",
|
"ParameterError",
|
||||||
"MissingParameterError",
|
"MissingParameterError",
|
||||||
"InvalidParameterError",
|
"InvalidParameterError",
|
||||||
"NotImplementedError",
|
"MethodNotImplementedError",
|
||||||
"UnsupportedError",
|
"UnsupportedError",
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,6 +6,10 @@ class NotFoundError(ApiError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class UnauthorizedError(ApiError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ForbiddenError(ApiError):
|
class ForbiddenError(ApiError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -26,9 +30,9 @@ class InvalidParameterError(ParameterError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class NotImplementedError(ApiError):
|
class MethodNotImplementedError(ApiError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class UnsupportedError(NotImplementedError):
|
class UnsupportedError(MethodNotImplementedError):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -32,11 +32,13 @@ class ApiStar(PageStar, ABC):
|
||||||
apidata = ApiData(data=data, star=self, method=request.method)
|
apidata = ApiData(data=data, star=self, method=request.method)
|
||||||
try:
|
try:
|
||||||
response = await self.api(apidata)
|
response = await self.api(apidata)
|
||||||
|
except UnauthorizedError as e:
|
||||||
|
return api_error(e, code=401)
|
||||||
except NotFoundError as e:
|
except NotFoundError as e:
|
||||||
return api_error(e, code=404)
|
return api_error(e, code=404)
|
||||||
except ForbiddenError as e:
|
except ForbiddenError as e:
|
||||||
return api_error(e, code=403)
|
return api_error(e, code=403)
|
||||||
except NotImplementedError as e:
|
except MethodNotImplementedError as e:
|
||||||
return api_error(e, code=501)
|
return api_error(e, code=501)
|
||||||
except BadRequestError as e:
|
except BadRequestError as e:
|
||||||
return api_error(e, code=400)
|
return api_error(e, code=400)
|
||||||
|
@ -49,7 +51,7 @@ class ApiStar(PageStar, ABC):
|
||||||
await apidata.session_close()
|
await apidata.session_close()
|
||||||
|
|
||||||
async def api(self, data: ApiData) -> ru.JSON:
|
async def api(self, data: ApiData) -> ru.JSON:
|
||||||
raise NotImplementedError()
|
raise MethodNotImplementedError()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def swagger(cls) -> ru.JSON:
|
def swagger(cls) -> ru.JSON:
|
||||||
|
|
Loading…
Reference in a new issue