Skip to content

Commit

Permalink
[IMP]pms_api_rest: reset-password public auth PATCH by POST
Browse files Browse the repository at this point in the history
  • Loading branch information
DarioLodeiros authored and miguelpadin committed Oct 26, 2023
1 parent 4551037 commit 8450470
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions pms_api_rest/services/pms_user_service.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import base64
import tempfile
import os
import tempfile
from datetime import datetime, timedelta

import werkzeug.exceptions

from odoo import _
from odoo.exceptions import AccessDenied, MissingError

from odoo.addons.base_rest import restapi
from odoo.addons.base_rest_datamodel.restapi import Datamodel
from odoo.addons.component.core import Component
from odoo.exceptions import AccessDenied
from datetime import datetime, timedelta



from odoo import _
from odoo.exceptions import MissingError


class PmsRoomTypeClassService(Component):
Expand All @@ -33,7 +31,6 @@ class PmsRoomTypeClassService(Component):
output_param=Datamodel("pms.api.rest.user.output", is_list=False),
auth="jwt_api_pms",
)

def get_user(self, user_id):
user = self.env["res.users"].sudo().search([("id", "=", user_id)])
if user:
Expand Down Expand Up @@ -96,7 +93,7 @@ def write_user(self, user_id, input_data):
else:
user.write(
{
"image_1024": '',
"image_1024": "",
}
)
return True
Expand All @@ -122,7 +119,6 @@ def change_password(self, user_id, input_data):
except AccessDenied:
raise werkzeug.exceptions.Unauthorized(_("Wrong password"))


user.change_password(input_data.password, input_data.newPassword)

PmsUserInfo = self.env.datamodels["pms.api.rest.user.login.output"]
Expand All @@ -136,7 +132,7 @@ def change_password(self, user_id, input_data):
[
"/p/reset-password",
],
"PATCH",
"POST",
)
],
input_param=Datamodel("pms.api.rest.user.input", is_list=False),
Expand All @@ -150,7 +146,6 @@ def reset_password(self, input_data):
self.env["res.users"].sudo().signup(values, input_data.resetToken)
return True


@restapi.method(
[
(
Expand All @@ -165,19 +160,22 @@ def reset_password(self, input_data):
cors="*",
)
def send_mail_to_reset_password(self, input_data):
user = self.env["res.users"].sudo().search([("email", "=", input_data.userEmail)])
user = (
self.env["res.users"].sudo().search([("email", "=", input_data.userEmail)])
)
if user:
template_id = self.env.ref("pms_api_rest.pms_reset_password_email").id
template = self.env['mail.template'].sudo().browse(template_id)
template = self.env["mail.template"].sudo().browse(template_id)
if not template:
return False
expiration_datetime = datetime.now() + timedelta(minutes=15)
user.partner_id.sudo().signup_prepare(expiration=expiration_datetime)
template.with_context({'app_url': input_data.url}).send_mail(user.id, force_send=True)
template.with_context({"app_url": input_data.url}).send_mail(
user.id, force_send=True
)
return True
return False


@restapi.method(
[
(
Expand All @@ -191,7 +189,9 @@ def send_mail_to_reset_password(self, input_data):
cors="*",
)
def check_reset_password_token(self, reset_token):
user = self.env["res.partner"].sudo().search([("signup_token", "=", reset_token)])
user = (
self.env["res.partner"].sudo().search([("signup_token", "=", reset_token)])
)
is_token_expired = False
if not user:
return True
Expand Down

0 comments on commit 8450470

Please sign in to comment.