mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[REF] pms-api-rest: add controller 4 login
This commit is contained in:
committed by
Darío Lodeiros
parent
b3ed4109bb
commit
6f672029f5
@@ -5,4 +5,8 @@ from . import calendar_service
|
||||
from . import partner_services
|
||||
|
||||
from . import reservation_services
|
||||
<<<<<<< HEAD
|
||||
from . import property_services
|
||||
=======
|
||||
from . import login_service
|
||||
>>>>>>> a4394db3... [REF] pms-api-rest: add controller 4 login
|
||||
|
||||
@@ -7,7 +7,7 @@ from odoo.addons.component.core import Component
|
||||
|
||||
class PmsCalendarService(Component):
|
||||
_inherit = "base.rest.service"
|
||||
_name = "pms.calendar.service"
|
||||
_name = "pms.private.services"
|
||||
_usage = "calendar"
|
||||
_collection = "pms.reservation.service"
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class PmsFolioService(Component):
|
||||
_inherit = "base.rest.service"
|
||||
_name = "pms.folio.service"
|
||||
_usage = "folios"
|
||||
_collection = "pms.reservation.service"
|
||||
_collection = "pms.private.services"
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
|
||||
116
pms_api_rest/services/login_service.py
Normal file
116
pms_api_rest/services/login_service.py
Normal file
@@ -0,0 +1,116 @@
|
||||
import time
|
||||
|
||||
from jose import jwt
|
||||
|
||||
from odoo import _
|
||||
from odoo.exceptions import ValidationError, AccessDenied, UserError
|
||||
|
||||
from odoo.addons.base_rest import restapi
|
||||
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
||||
from odoo.addons.component.core import Component
|
||||
|
||||
|
||||
class PmsPartnerService(Component):
|
||||
_inherit = "base.rest.service"
|
||||
_name = "pms.auth.service"
|
||||
_usage = "login"
|
||||
_collection = "pms.public.services"
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/",
|
||||
],
|
||||
"POST",
|
||||
)
|
||||
],
|
||||
input_param=Datamodel("pms.api.rest.user.input", is_list=False),
|
||||
# output_param=Datamodel("pms.api.rest.user.output", is_list=False),
|
||||
)
|
||||
def aa(self, user):
|
||||
|
||||
user_record = (
|
||||
self.env["res.users"].sudo().search([("login", "=", user.username)])
|
||||
)
|
||||
|
||||
if not user_record:
|
||||
ValidationError(_("user or password not valid"))
|
||||
try:
|
||||
user_record.with_user(user_record)._check_credentials(user.password, None)
|
||||
|
||||
except Exception as e:
|
||||
raise UserError("")
|
||||
|
||||
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,
|
||||
"username": user.username,
|
||||
"password": user.password,
|
||||
},
|
||||
key="pms_secret_key_example",
|
||||
algorithm=jwt.ALGORITHMS.HS256,
|
||||
)
|
||||
# return PmsApiRestUserOutput(token=token)
|
||||
return token
|
||||
|
||||
def user_error(self):
|
||||
"""
|
||||
Simulate an odoo.exceptions.UserError
|
||||
Should be translated into BadRequest with a description into the json
|
||||
body
|
||||
"""
|
||||
raise UserError(_("UserError message"))
|
||||
|
||||
# Validator
|
||||
def _validator_user_error(self):
|
||||
return {}
|
||||
|
||||
def _validator_return_user_error(self):
|
||||
return {}
|
||||
|
||||
def _validator_validation_error(self):
|
||||
return {}
|
||||
|
||||
def _validator_return_validation_error(self):
|
||||
return {}
|
||||
|
||||
def _validator_session_expired(self):
|
||||
return {}
|
||||
|
||||
def _validator_return_session_expired(self):
|
||||
return {}
|
||||
|
||||
def _validator_missing_error(self):
|
||||
return {}
|
||||
|
||||
def _validator_return_missing_error(self):
|
||||
return {}
|
||||
|
||||
def _validator_access_error(self):
|
||||
return {}
|
||||
|
||||
def _validator_return_access_error(self):
|
||||
return {}
|
||||
|
||||
def _validator_access_denied(self):
|
||||
return {}
|
||||
|
||||
def _validator_return_access_denied(self):
|
||||
return {}
|
||||
|
||||
def _validator_http_exception(self):
|
||||
return {}
|
||||
|
||||
def _validator_return_http_exception(self):
|
||||
return {}
|
||||
|
||||
def _validator_bare_exception(self):
|
||||
return {}
|
||||
|
||||
def _validator_return_bare_exception(self):
|
||||
return {}
|
||||
@@ -7,7 +7,7 @@ class PmsPartnerService(Component):
|
||||
_inherit = "base.rest.service"
|
||||
_name = "pms.partner.service"
|
||||
_usage = "partners"
|
||||
_collection = "pms.reservation.service"
|
||||
_collection = "pms.private.services"
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
|
||||
@@ -9,7 +9,7 @@ class PmsRoomService(Component):
|
||||
_inherit = "base.rest.service"
|
||||
_name = "pms.reservation.service"
|
||||
_usage = "reservations"
|
||||
_collection = "pms.reservation.service"
|
||||
_collection = "pms.private.services"
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
|
||||
@@ -7,7 +7,7 @@ class PmsRoomService(Component):
|
||||
_inherit = "base.rest.service"
|
||||
_name = "pms.room.service"
|
||||
_usage = "rooms"
|
||||
_collection = "pms.reservation.service"
|
||||
_collection = "pms.private.services"
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
|
||||
@@ -7,7 +7,7 @@ class PmsRoomTypeService(Component):
|
||||
_inherit = "base.rest.service"
|
||||
_name = "pms.room.type.service"
|
||||
_usage = "room-types"
|
||||
_collection = "pms.reservation.service"
|
||||
_collection = "pms.private.services"
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user