res_users.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import _, models
  4. class Users(models.Model):
  5. _inherit = 'res.users'
  6. def action_open_my_account_settings(self):
  7. action = {
  8. "name": _("Account Security"),
  9. "type": "ir.actions.act_window",
  10. "res_model": "res.users",
  11. "views": [[self.env.ref('auth_totp_mail.res_users_view_form').id, "form"]],
  12. "res_id": self.id,
  13. }
  14. return action
  15. def get_totp_invite_url(self):
  16. return '/web#action=auth_totp_mail.action_activate_two_factor_authentication'
  17. def action_totp_invite(self):
  18. invite_template = self.env.ref('auth_totp_mail.mail_template_totp_invite')
  19. users_to_invite = self.sudo().filtered(lambda user: not user.totp_secret)
  20. for user in users_to_invite:
  21. email_values = {
  22. 'email_from': self.env.user.email_formatted,
  23. 'author_id': self.env.user.partner_id.id,
  24. }
  25. invite_template.send_mail(user.id, force_send=True, email_values=email_values,
  26. email_layout_xmlid='mail.mail_notification_light')
  27. # Display a confirmation toaster
  28. return {
  29. 'type': 'ir.actions.client',
  30. 'tag': 'display_notification',
  31. 'params': {
  32. 'type': 'info',
  33. 'sticky': False,
  34. 'message': _("Invitation to use two-factor authentication sent for the following user(s): %s",
  35. ', '.join(users_to_invite.mapped('name'))),
  36. }
  37. }