Skip to content

Commit

Permalink
[IMP] pms_api_rest: jwt exp. date
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpadin committed Apr 11, 2022
1 parent 7aedd78 commit bc0c0de
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pms_api_rest/datamodels/pms_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PmsCalendarSearchParam(Datamodel):
class PmsCalendarFreeDailyRoomsByType(Datamodel):
_name = "pms.calendar.free.daily.rooms.by.type"
date = fields.String(required=True, allow_none=False)
roomType = fields.Integer(required=True, allow_none=False)
roomTypeId = fields.Integer(required=True, allow_none=False)
freeRooms = fields.Integer(required=True, allow_none=False)


Expand Down
1 change: 1 addition & 0 deletions pms_api_rest/datamodels/pms_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PmsApiRestUserInput(Datamodel):
class PmsApiRestUserOutput(Datamodel):
_name = "pms.api.rest.user.output"
token = fields.String(required=False, allow_none=True)
expirationDate = fields.Integer(required=True, allow_none=False)
userId = fields.Integer(required=True, allow_none=False)
userName = fields.String(required=True, allow_none=False)
userImageBase64 = fields.String(required=False, allow_none=True)
Expand Down
2 changes: 1 addition & 1 deletion pms_api_rest/services/pms_calendar_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def get_free_rooms(self, pms_calendar_search_param):
date=str(
datetime.combine(date, datetime.min.time()).isoformat()
),
roomType=room_type_iterator.id,
roomTypeId=room_type_iterator.id,
freeRooms=free_rooms_room_type,
)
)
Expand Down
9 changes: 7 additions & 2 deletions pms_api_rest/services/pms_login_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
from math import ceil

from jose import jwt

Expand Down Expand Up @@ -35,17 +36,20 @@ def login(self, user):
user_record = (
self.env["res.users"].sudo().search([("login", "=", user.username)])
)
# formula = ms_now + ms in 1 sec * secs in 1 min
minutes = 10
timestamp_expire_in_a_min = int(time.time()*1000.0) + 1000 * 60 * minutes

if not user_record:
raise ValidationError(_("user or password not valid"))
user_record.with_user(user_record)._check_credentials(user.password, None)
PmsApiRestUserOutput = self.env.datamodels["pms.api.rest.user.output"]
expiration_date = time.time() + 36660

token = jwt.encode(
{
"aud": "api_pms",
"iss": "pms",
"exp": expiration_date,
"exp": timestamp_expire_in_a_min,
"username": user.username,
"password": user.password,
},
Expand All @@ -55,6 +59,7 @@ def login(self, user):

return PmsApiRestUserOutput(
token=token,
expirationDate=timestamp_expire_in_a_min,
userId=user_record.id,
userName=user_record.name,
defaultPropertyId=user_record.pms_property_id.id,
Expand Down

0 comments on commit bc0c0de

Please sign in to comment.