def action_reset_password(self, cr, uid, ids, context=None):
    """ create signup token for each user, and send their signup url by email """
    # prepare reset password signup
    res_partner = self.pool.get('res.partner')
    partner_ids = [user.partner_id.id for user in self.browse(cr, uid, ids, context)]
    res_partner.signup_prepare(cr, uid, partner_ids, signup_type="reset", expiration=now(days=+1), context=context)

    if not context:
        context = {}

    # send email to users with their signup url
    template = False
    if context.get('create_user'):
        try:
            # get_object() raises ValueError if record does not exist
            template = self.pool.get('ir.model.data').get_object(cr, uid, 'custom_email_template', 'set_password_email')
        except ValueError:
            pass
    if not bool(template):
        template = self.pool.get('ir.model.data').get_object(cr, uid, 'custom_email_template', 'reset_password_email')
    assert template._name == 'email.template'

    for user in self.browse(cr, uid, ids, context):
        if not user.email:
            raise osv.except_osv(_("Cannot send email: user has no email address."), user.name)
        self.pool.get('email.template').send_mail(cr, uid, template.id, user.id, force_send=True, raise_exception=True, context=context)
Exemple #2
0
    def action_reset_password(self):
        """ create signup token for each user, and send their signup url by email """
        print(" inh_context_action_reset_password = %s" % self._context)
        # prepare reset password signup
        res_partner = self.env['res.partner']
        partner_ids = [user.partner_id.id for user in self]
        partner_ids = res_partner.browse(partner_ids)
        partner_ids.with_context(self._context).signup_prepare(
            signup_type="reset", expiration=now(days=+1))

        context = dict(self._context or {})

        # send email to users with their signup url
        template = False
        if context.get('create_user'):
            try:
                template = self.env.ref(
                    'aro_mail_templates.aro_set_password_email')
            except ValueError:
                pass
        if not bool(template):
            template = self.env.ref(
                'aro_mail_templates.aro_reset_password_email')
        assert template._name == 'email.template'
        logger.info('template = %s' % template._name)

        for user in self:
            if not user.email:
                raise exceptions.Warning(
                    _('Cannot send email: user has no email address. %s' %
                      user.name))
            context['lang'] = user.lang  # translate in targeted user language
            template.with_context(context).send_mail(user.id,
                                                     force_send=True,
                                                     raise_exception=True)
Exemple #3
0
 def create(self, values):
     user = super(Users, self).create(values)
     # user is not active yet, he needs to click a link in the email
     if self.env.context.get('confirm_signup'):
         user.active = False
         user.partner_id.signup_prepare(signup_type="authenticate", expiration=now(days=+1))
         redirect_url = self.env.context.get('redirect')
         template = self.with_context(redirect=redirect_url).env.ref('email_confirmation.user_confirmation_email')
         template.send_mail(user.id, force_send=True, raise_exception=True)
     return user
Exemple #4
0
 def create(self, values):
     user = super(Users, self).create(values)
     # user is not active yet, he needs to click a link in the email
     if self.env.context.get('confirm_signup'):
         user.active = False
         user.active_state = 'not_activated'
         user.partner_id.signup_prepare(signup_type="authenticate", expiration=now(days=+1))
         redirect_url = self.env.context.get('redirect')
         template = self.with_context(redirect=redirect_url).env.ref('email_confirmation.user_confirmation_email')
         template.send_mail(user.id, force_send=True, raise_exception=True)
     return user
Exemple #5
0
def action_reset_password(self, cr, uid, ids, context=None):
    """ create signup token for each user, and send their signup url by email """
    # prepare reset password signup
    res_partner = self.pool.get('res.partner')
    partner_ids = [
        user.partner_id.id for user in self.browse(cr, uid, ids, context)
    ]
    res_partner.signup_prepare(cr,
                               uid,
                               partner_ids,
                               signup_type="reset",
                               expiration=now(days=+1),
                               context=context)

    if not context:
        context = {}

    # send email to users with their signup url
    template = False
    if context.get('create_user'):
        try:
            # get_object() raises ValueError if record does not exist
            template = self.pool.get('ir.model.data').get_object(
                cr, uid, 'custom_email_template', 'set_password_email')
        except ValueError:
            pass
    if not bool(template):
        template = self.pool.get('ir.model.data').get_object(
            cr, uid, 'custom_email_template', 'reset_password_email')
    assert template._name == 'email.template'

    for user in self.browse(cr, uid, ids, context):
        if not user.email:
            raise osv.except_osv(
                _("Cannot send email: user has no email address."), user.name)
        self.pool.get('email.template').send_mail(cr,
                                                  uid,
                                                  template.id,
                                                  user.id,
                                                  force_send=True,
                                                  raise_exception=True,
                                                  context=context)