mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms_api_rest: added services to reset user password
This commit is contained in:
@@ -42,6 +42,7 @@
|
|||||||
"data/pms_precheckin_invitation_email_template.xml",
|
"data/pms_precheckin_invitation_email_template.xml",
|
||||||
"data/pms_data.xml",
|
"data/pms_data.xml",
|
||||||
"data/traveller_report_paperformat.xml",
|
"data/traveller_report_paperformat.xml",
|
||||||
|
"data/pms_reset_password_email.xml",
|
||||||
"report/pms_folio.xml",
|
"report/pms_folio.xml",
|
||||||
"report/pms_folio_templates.xml",
|
"report/pms_folio_templates.xml",
|
||||||
"report/traveller_report_action.xml",
|
"report/traveller_report_action.xml",
|
||||||
|
|||||||
109
pms/data/pms_reset_password_email.xml
Normal file
109
pms/data/pms_reset_password_email.xml
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<data>
|
||||||
|
<record id="pms_reset_password_email" model="mail.template">
|
||||||
|
<field name="name">Pms Reset Password</field>
|
||||||
|
<field name="model_id" ref="base.model_res_users"/>
|
||||||
|
<field name="subject">Restablecer Contraseña</field>
|
||||||
|
<field name="email_from">"${object.company_id.name | safe}" <${(object.company_id.email or user.email) | safe}></field>
|
||||||
|
<field name="email_to">${object.email_formatted | safe}</field>
|
||||||
|
<field name="body_html" type="html">
|
||||||
|
<table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; font-family:Verdana, Arial,sans-serif; color: #454748; width: 100%; border-collapse:separate;"><tr><td align="center">
|
||||||
|
<table border="0" cellpadding="0" cellspacing="0" width="590" style="padding: 16px; background-color: white; color: #454748; border-collapse:separate;">
|
||||||
|
<tbody>
|
||||||
|
<!-- HEADER -->
|
||||||
|
<tr>
|
||||||
|
<td align="center" style="min-width: 590px;">
|
||||||
|
<table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:separate;">
|
||||||
|
<tr><td valign="middle">
|
||||||
|
<span style="font-size: 10px;">Tu Cuenta en Roomdoo</span><br/>
|
||||||
|
<span style="font-size: 20px; font-weight: bold;">
|
||||||
|
${object.name}
|
||||||
|
</span>
|
||||||
|
</td><td valign="middle" align="right">
|
||||||
|
<img src="/logo.png?company=${object.company_id.id}" style="padding: 0px; margin: 0px; height: auto; width: 80px;" alt="${object.company_id.name}"/>
|
||||||
|
</td></tr>
|
||||||
|
<tr><td colspan="2" style="text-align:center;">
|
||||||
|
<hr width="100%" style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 16px 0px 16px 0px;"/>
|
||||||
|
</td></tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<!-- CONTENT -->
|
||||||
|
<tr>
|
||||||
|
<td align="center" style="min-width: 590px;">
|
||||||
|
<table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:separate;">
|
||||||
|
<tr><td valign="top" style="font-size: 13px;">
|
||||||
|
<div>
|
||||||
|
${object.name},<br/><br/>
|
||||||
|
Se solicitó un restablecimiento de contraseña para la cuenta de Roomdoo vinculada a este correo electrónico.
|
||||||
|
Puede cambiar su contraseña siguiendo este enlace que permanecerá válido durante 15 minutos:<br/>
|
||||||
|
<!-- % if object.partner_id.signup_expiration > datetime.datetime.now():-->
|
||||||
|
<div style="margin: 16px 0px 16px 0px;">
|
||||||
|
<a href="${object.company_id.url_app}/reset-password?token=${object.signup_token}"
|
||||||
|
style="background-color: #875A7B; padding: 8px 16px 8px 16px; text-decoration: none; color: #fff; border-radius: 5px; font-size:13px;">
|
||||||
|
Reestablecer contraseña
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<!-- % else:-->
|
||||||
|
<!-- <div style="margin: 16px 0px 16px 0px;">-->
|
||||||
|
<!-- <a href="http://localhost:8080/reset-password"-->
|
||||||
|
<!-- style="background-color: #875A7B; padding: 8px 16px 8px 16px; text-decoration: none; color: #fff; border-radius: 5px; font-size:13px;">-->
|
||||||
|
<!-- Reestablecer contraseña-->
|
||||||
|
<!-- </a>-->
|
||||||
|
<!-- </div>-->
|
||||||
|
<!-- % endif-->
|
||||||
|
Puede ignorar este correo electrónico si no lo esperaba.<br/><br/>
|
||||||
|
Gracias,
|
||||||
|
% if user.signature:
|
||||||
|
<br/>
|
||||||
|
${user.signature | safe}
|
||||||
|
% endif
|
||||||
|
</div>
|
||||||
|
</td></tr>
|
||||||
|
<tr><td style="text-align:center;">
|
||||||
|
<hr width="100%" style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 16px 0px 16px 0px;"/>
|
||||||
|
</td></tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<!-- FOOTER -->
|
||||||
|
<tr>
|
||||||
|
<td align="center" style="min-width: 590px;">
|
||||||
|
<table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: white; font-size: 11px; padding: 0px 8px 0px 8px; border-collapse:separate;">
|
||||||
|
<tr><td valign="middle" align="left">
|
||||||
|
${object.company_id.name}
|
||||||
|
</td></tr>
|
||||||
|
<tr><td valign="middle" align="left" style="opacity: 0.7;">
|
||||||
|
${object.company_id.phone}
|
||||||
|
% if object.company_id.email
|
||||||
|
| <a href="'mailto:%s' % ${object.company_id.email}" style="text-decoration:none; color: #454748;">${object.company_id.email}</a>
|
||||||
|
% endif
|
||||||
|
% if object.company_id.website
|
||||||
|
| <a href="'%s' % ${object.company_id.website}" style="text-decoration:none; color: #454748;">
|
||||||
|
${object.company_id.website}
|
||||||
|
</a>
|
||||||
|
% endif
|
||||||
|
</td></tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td></tr>
|
||||||
|
<!-- POWERED BY -->
|
||||||
|
<tr><td align="center" style="min-width: 590px;">
|
||||||
|
<table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: #F1F1F1; color: #454748; padding: 8px; border-collapse:separate;">
|
||||||
|
<tr><td style="text-align: center; font-size: 13px;">
|
||||||
|
Powered by <a target="_blank" href="https://www.odoo.com?utm_source=db&utm_medium=auth" style="color: #875A7B;">Odoo</a>
|
||||||
|
</td></tr>
|
||||||
|
</table>
|
||||||
|
</td></tr>
|
||||||
|
</table>
|
||||||
|
</field>
|
||||||
|
<field name="lang">${object.lang}</field>
|
||||||
|
<field name="auto_delete" eval="True"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</odoo>
|
||||||
@@ -24,6 +24,7 @@
|
|||||||
"data/auth_jwt_validator.xml",
|
"data/auth_jwt_validator.xml",
|
||||||
"views/pms_property_views.xml",
|
"views/pms_property_views.xml",
|
||||||
"views/res_users_views.xml",
|
"views/res_users_views.xml",
|
||||||
|
"views/res_company_views.xml",
|
||||||
],
|
],
|
||||||
"demo": [
|
"demo": [
|
||||||
"demo/pms_api_rest_master_data.xml",
|
"demo/pms_api_rest_master_data.xml",
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ class PmsApiRestUserInput(Datamodel):
|
|||||||
password = fields.String(required=False, allow_none=True)
|
password = fields.String(required=False, allow_none=True)
|
||||||
newPassword = fields.String(required=False, allow_none=True)
|
newPassword = fields.String(required=False, allow_none=True)
|
||||||
userId = fields.Integer(required=False, allow_none=True)
|
userId = fields.Integer(required=False, allow_none=True)
|
||||||
|
userEmail = fields.String(required=False, allow_none=True)
|
||||||
|
resetToken = fields.String(required=False, allow_none=True)
|
||||||
|
|
||||||
|
|
||||||
class PmsApiRestUserOutput(Datamodel):
|
class PmsApiRestUserOutput(Datamodel):
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from . import res_company
|
||||||
from . import pms_property
|
from . import pms_property
|
||||||
from . import res_users
|
from . import res_users
|
||||||
from . import account_payment
|
from . import account_payment
|
||||||
|
|||||||
7
pms_api_rest/models/res_company.py
Normal file
7
pms_api_rest/models/res_company.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class ResCompany(models.Model):
|
||||||
|
_inherit = "res.company"
|
||||||
|
|
||||||
|
url_app = fields.Char(string="Url App", help="Url to identify the app")
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
import base64
|
import base64
|
||||||
import tempfile
|
import tempfile
|
||||||
import os
|
import os
|
||||||
|
import werkzeug.exceptions
|
||||||
|
|
||||||
from odoo.addons.base_rest import restapi
|
from odoo.addons.base_rest import restapi
|
||||||
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
||||||
from odoo.addons.component.core import Component
|
from odoo.addons.component.core import Component
|
||||||
|
from odoo.exceptions import AccessDenied
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from odoo import _
|
from odoo import _
|
||||||
@@ -113,8 +118,8 @@ class PmsRoomTypeClassService(Component):
|
|||||||
if user:
|
if user:
|
||||||
try:
|
try:
|
||||||
user.with_user(user)._check_credentials(input_data.password, None)
|
user.with_user(user)._check_credentials(input_data.password, None)
|
||||||
except:
|
except AccessDenied:
|
||||||
raise MissingError(_("Wrong password"))
|
raise werkzeug.exceptions.Unauthorized(_("Wrong password"))
|
||||||
|
|
||||||
|
|
||||||
user.change_password(input_data.password, input_data.newPassword)
|
user.change_password(input_data.password, input_data.newPassword)
|
||||||
@@ -124,3 +129,71 @@ class PmsRoomTypeClassService(Component):
|
|||||||
login=user.login,
|
login=user.login,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/p/reset-password",
|
||||||
|
],
|
||||||
|
"PATCH",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
input_param=Datamodel("pms.api.rest.user.input", is_list=False),
|
||||||
|
auth="public",
|
||||||
|
cors="*",
|
||||||
|
)
|
||||||
|
def reset_password(self, input_data):
|
||||||
|
values = {
|
||||||
|
"password": input_data.password,
|
||||||
|
}
|
||||||
|
self.env["res.users"].sudo().signup(values, input_data.resetToken)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/send-mail-reset-password",
|
||||||
|
],
|
||||||
|
"POST",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
input_param=Datamodel("pms.api.rest.user.input", is_list=False),
|
||||||
|
auth="public",
|
||||||
|
cors="*",
|
||||||
|
)
|
||||||
|
def send_mail_to_reset_password(self, input_data):
|
||||||
|
user = self.env["res.users"].sudo().search([("email", "=", input_data.userEmail)])
|
||||||
|
if user:
|
||||||
|
template_id = self.env.ref("pms.pms_reset_password_email").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.send_mail(user.id, force_send=True)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/check-reset-password-token/<string:reset_token>",
|
||||||
|
],
|
||||||
|
"GET",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
auth="public",
|
||||||
|
cors="*",
|
||||||
|
)
|
||||||
|
def check_reset_password_token(self, reset_token):
|
||||||
|
user = self.env["res.partner"].sudo().search([("signup_token", "=", reset_token)])
|
||||||
|
is_token_expired = False
|
||||||
|
if not user:
|
||||||
|
return True
|
||||||
|
if user.sudo().signup_expiration < datetime.now():
|
||||||
|
is_token_expired = True
|
||||||
|
return is_token_expired
|
||||||
|
|||||||
12
pms_api_rest/views/res_company_views.xml
Normal file
12
pms_api_rest/views/res_company_views.xml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<odoo>
|
||||||
|
<record id="company_view_form" model="ir.ui.view">
|
||||||
|
<field name="model">res.company</field>
|
||||||
|
<field name="inherit_id" ref="base.view_company_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='url_advert']" position="after">
|
||||||
|
<field name="url_app" />
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user