Beispiel #1
0
 def _get_invitation_hash(self):
     """ We use a method instead of a field in order to reduce DB space."""
     self.ensure_one()
     return tools.hmac(
         self.env(su=True), 'knowledge-article-invite',
         f'{self.id}-{self.create_date}-{self.partner_id.id}-{self.article_id.id}'
     )
Beispiel #2
0
    def _get_unsubscribe_token(self, user_id):
        """Generate a secure hash for this digest and user. It allows to
        unsubscribe from a digest while keeping some security in that process.

        :param int user_id: ID of the user to unsubscribe
        """
        return tools.hmac(self.env(su=True), 'digest-unsubscribe',
                          (self.id, user_id))
Beispiel #3
0
    def track_mail_open(self, mail_id, token, **post):
        """ Email tracking. """
        if not consteq(token, tools.hmac(request.env(su=True), 'mass_mailing-mail_mail-open', mail_id)):
            raise BadRequest()

        request.env['mailing.trace'].sudo().set_opened(mail_mail_ids=[mail_id])
        response = werkzeug.wrappers.Response()
        response.mimetype = 'image/gif'
        response.data = base64.b64decode(b'R0lGODlhAQABAIAAANvf7wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==')

        return response
Beispiel #4
0
    def _generate_action_token(self, email, action):
        """Generate an action token to be able to subscribe / unsubscribe from the mailing list."""
        if action not in ['subscribe', 'unsubscribe']:
            raise ValueError(_('Invalid action for URL generation (%s)', action))
        self.ensure_one()

        email_normalized = email_normalize(email)
        if not email_normalized:
            raise UserError(_('Email %s is invalid', email))

        data = (self.id, email_normalized, action)
        return hmac(self.env(su=True), 'mail_group-email-subscription', data)
Beispiel #5
0
 def _generate_group_access_token(self):
     """Generate an action token to be able to subscribe / unsubscribe from the mailing list."""
     self.ensure_one()
     return hmac(self.env(su=True), 'mail_group-access-token-portal', self.id)
Beispiel #6
0
 def _generate_action_token(self, partner_id, action='unsubscribe'):
     self.ensure_one()
     data = '$'.join([str(self.id), str(partner_id), action])
     return tools.hmac(self.env(su=True),
                       'website_mail_channel-email-subscription', data)
 def _get_tracking_url(self):
     base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
     token = tools.hmac(self.env(su=True), 'mass_mailing-mail_mail-open', self.id)
     return werkzeug.urls.url_join(base_url, 'mail/track/%s/%s/blank.gif' % (self.id, token))
Beispiel #8
0
 def _get_tracking_url(self):
     token = tools.hmac(self.env(su=True), 'mass_mailing-mail_mail-open', self.id)
     return werkzeug.urls.url_join(self.get_base_url(), 'mail/track/%s/%s/blank.gif' % (self.id, token))