Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T1714 - mycompassion - display password change failure reason #37

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion my_compassion/controllers/my_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from werkzeug.exceptions import NotFound

from odoo import _, fields
from odoo.exceptions import UserError
from odoo.exceptions import AccessDenied, UserError
from odoo.http import local_redirect, request, route

from odoo.addons.portal.controllers.portal import CustomerPortal
Expand Down Expand Up @@ -649,3 +649,43 @@ def my_letter_preview(self, child, mode):
"preview_url": f"{web_base_url}web/image/{gen._name}/{gen.id}/preview_pdf",
"generator_id": gen.id,
}

def _update_password(self, old, new1, new2):
# TODO: Delete me in Odoo 16.0
# Fixes a bug present in Odoo < 16.0
# Fix commit in Odoo repository:
# https://github.com/odoo/odoo/commit/6fea44277edef8ae7058e7bae9c69e84a026cfb8
for k, v in [("old", old), ("new1", new1), ("new2", new2)]:
if not v:
return {
"errors": {
"password": {k: _("You cannot leave any password empty.")}
}
}
if new1 != new2:
return {
"errors": {
"password": {
"new2": _(
"The new password and its confirmation must be identical."
)
}
}
}

try:
request.env["res.users"].change_password(old, new1)
except AccessDenied as e:
msg = e.args[0]
if msg == AccessDenied().args[0]:
msg = _(
"The old password you provided is incorrect, your password was not "
"changed."
)
return {"errors": {"password": {"old": msg}}}
except UserError as e:
return {"errors": {"password": e.name}}

new_token = request.env.user._compute_session_token(request.session.sid)
request.session.session_token = new_token
return {"success": {"password": True}}
Loading