コード例 #1
0
ファイル: res_users.py プロジェクト: 10537/odoo
    def action_reset_password(self):
        """ create signup token for each user, and send their signup url by email """
        # prepare reset password signup
        create_mode = bool(self.env.context.get('create_user'))

        # no time limit for initial invitation, only for reset password
        expiration = False if create_mode else now(days=+1)

        self.mapped('partner_id').signup_prepare(signup_type="reset", expiration=expiration)

        # send email to users with their signup url
        template = False
        if create_mode:
            try:
                template = self.env.ref('auth_signup.set_password_email', raise_if_not_found=False)
            except ValueError:
                pass
        if not template:
            template = self.env.ref('auth_signup.reset_password_email')
        assert template._name == 'mail.template'

        for user in self:
            if not user.email:
                raise UserError(_("Cannot send email: user %s has no email address.") % user.name)
            template.with_context(lang=user.lang).send_mail(user.id, force_send=True, raise_exception=True)
            _logger.info("Password reset email sent for user <%s> to <%s>", user.login, user.email)
コード例 #2
0
    def action_verify_email(self):
        """ create signup token for each user, and send their verification  url by email """

        create_mode = bool(self.env.context.get('create_user'))

        # no time limit for initial invitation to verify email
        expiration = False if create_mode else now(days=+1)

        self.mapped('partner_id').signup_prepare(signup_type="verify",
                                                 expiration=expiration)

        # send email to users with their signup url
        template = False
        if create_mode:
            template = self.env.ref('auth_signup.verification_email',
                                    raise_if_not_found=False)

        assert template._name == 'mail.template'

        for user in self:
            if not user.email:
                raise UserError(
                    _("Cannot send email: user %s has no email address.") %
                    user.name)
            template.with_context(lang=user.lang).send_mail(
                user.id, force_send=True, raise_exception=True)
            _logger.info("Verification email sent for user <%s> to <%s>",
                         user.login, user.email)
コード例 #3
0
ファイル: res_users.py プロジェクト: zoolook495/odoo
    def action_reset_password(self):
        """ create signup token for each user, and send their signup url by email """
        # prepare reset password signup
        create_mode = bool(self.env.context.get('create_user'))

        # no time limit for initial invitation, only for reset password
        expiration = False if create_mode else now(days=+1)

        self.mapped('partner_id').signup_prepare(signup_type="reset",
                                                 expiration=expiration)

        # send email to users with their signup url
        template = False
        if create_mode:
            try:
                template = self.env.ref('auth_signup.set_password_email',
                                        raise_if_not_found=False)
            except ValueError:
                pass
        if not template:
            template = self.env.ref('auth_signup.reset_password_email')
        assert template._name == 'mail.template'

        for user in self:
            if not user.email:
                raise UserError(
                    _("Cannot send email: user %s has no email address.") %
                    user.name)
            template.with_context(lang=user.lang).send_mail(
                user.id, force_send=True, raise_exception=True)
コード例 #4
0
    def send_account_verify_email(self):
        """ create account verification token for each user, and send their account verify url by email """
        # prepare reset password signup
        create_mode = bool(self.env.context.get('create_user'))

        # no time limit for initial invitation, only for reset password
        expiration = False if create_mode else now(days=+1)

        self.mapped('partner_id').verify_prepare(expiration=expiration)
        # send email to users with their signup url
        template = self.env.ref('pragtech_housemates.mail_verify_account')
        assert template._name == 'mail.template'

        template_values = {
            #             'email_to': '${object.email|safe}',
            'email_cc': False,
            'auto_delete': True,
            'partner_to': False,
            'scheduled_date': False,
        }
        template.write(template_values)
        #         try:

        for user in self:
            if not user.email:
                raise UserError(
                    _("Cannot send email: user %s has no email address.") %
                    user.name)
            with self.env.cr.savepoint():
                template.with_context(lang=user.lang).send_mail(
                    user.id, force_send=True, raise_exception=True)
            _logger.info("Password reset email sent for user <%s> to <%s>",
                         user.login, user.email)
コード例 #5
0
ファイル: res_users.py プロジェクト: vidtsin/hrms
 def action_reset_password_custom(self):
     """ create signup token for each user, and send their signup url by email """
     # prepare reset password signup
     create_mode = bool(self.env.context.get('create_user'))
     # no time limit for initial invitation, only for reset password
     expiration = False if create_mode else now(days=+1)
     signup_url = self.mapped('partner_id').signup_prepare(
         signup_type="reset", expiration=expiration)
コード例 #6
0
    def action_reset_password(self):
        """
        为每个用户创建注册令牌,并通过电子邮件发送他们的注册url
        增加判断模板对象为企业微信用户,使用企业微信发送模板消息的方法
        """
        if self.env.context.get("install_mode", False):
            return
        if self.filtered(lambda user: not user.active):
            raise UserError(
                _("You cannot perform this action on an archived user."))
        # prepare reset password signup
        create_mode = bool(self.env.context.get("create_user"))

        # no time limit for initial invitation, only for reset password
        expiration = False if create_mode else now(days=+1)

        self.mapped("partner_id").signup_prepare(signup_type="reset",
                                                 expiration=expiration)

        # send email to users with their signup url
        template = False
        if create_mode:
            try:
                template = self.env.ref("auth_signup.set_password_email",
                                        raise_if_not_found=False)
            except ValueError:
                pass
        if not template:
            template = self.env.ref("auth_signup.reset_password_email")
        assert template._name == "mail.template"
        template_values = {
            "email_to": "${object.email|safe}",
            "email_cc": False,
            "auto_delete": True,
            "partner_to": False,
            "scheduled_date": False,
        }
        template.write(template_values)
        for user in self:
            if user.wecom_userid:
                return self.action_reset_password_by_wecom(user, create_mode)
            elif not user.email:
                raise UserError(
                    _("Cannot send email: user %s has no email address.",
                      user.name))
            # TDE FIXME: make this template technical (qweb)
            with self.env.cr.savepoint():
                force_send = not (self.env.context.get("import_file", False))
                template.send_mail(user.id,
                                   force_send=force_send,
                                   raise_exception=True)
            _logger.info(
                "Password reset email sent for user <%s> to <%s>",
                user.login,
                user.email,
            )
        return super(ResUsers, self).action_reset_password()
コード例 #7
0
    def action_reset_password(self):
        """ create signup token for each user, and send their signup url by email """
        if self.env.context.get('install_mode', False):
            return
        if self.filtered(lambda user: not user.active):
            raise UserError(
                _("You cannot perform this action on an archived user."))
        # prepare reset password signup
        create_mode = bool(self.env.context.get('create_user'))

        # no time limit for initial invitation, only for reset password
        expiration = False if create_mode else now(days=+1)

        self.mapped('partner_id').signup_prepare(signup_type="reset",
                                                 expiration=expiration)

        # send email to users with their signup url
        template = False
        if create_mode:
            try:
                template = self.env.ref('auth_signup.set_password_email',
                                        raise_if_not_found=False)
            except ValueError:
                pass
        if not template:
            template = self.env.ref('auth_signup.reset_password_email')
        assert template._name == 'mail.template'

        template_values = {
            'email_to': '${object.email|safe}',
            'email_cc': False,
            'auto_delete': True,
            'partner_to': False,
            'scheduled_date': False,
        }
        if any(template[field] != value
               for (field, value) in template_values.items()):
            template.write(template_values)

        for user in self:
            if not user.email:
                raise UserError(
                    _("Cannot send email: user %s has no email address.",
                      user.name))
            # TDE FIXME: make this template technical (qweb)
            with self.env.cr.savepoint():
                force_send = not (self.env.context.get('import_file', False))
                template.send_mail(user.id,
                                   force_send=force_send,
                                   raise_exception=True)
            _logger.info("Password reset email sent for user <%s> to <%s>",
                         user.login, user.email)
コード例 #8
0
 def action_po_send(self):
     self.ensure_one()
     date_format = '%Y-%m-%d'
     delDate = self.date_planned
     mailTemplateModel = self.env['mail.template']
     irModelData = self.env['ir.model.data']
     templXmlId = irModelData.get_object_reference(
         'dropship_portal', 'email_template_dropship_po')[1]
     vendorObj = self.partner_id
     user_id = self.partner_id.user_id.id
     x_id = str(self.id)
     expiration = now(days=+1)
     x_url = "3QI6I5o5fJTW2oCzivoK/" + x_id + "/"
     x_notes = ""
     self.mapped('partner_id').signup_prepare(signup_type=x_url,
                                              expiration=expiration)
     redirectUrl = vendorObj.signup_url
     _logger.debug("*********** purchase.py action_po_send wurl: %r",
                   redirectUrl)
     baseUrl = self.env['ir.config_parameter'].sudo().get_param(
         'web.base.url')
     _logger.debug("*********** purchase.py action_po_send redirectUrl: %r",
                   redirectUrl)
     if templXmlId and vendorObj:
         mailTmplObj = mailTemplateModel.browse(templXmlId)
         for vendor in vendorObj:
             ctx = {
                 'wkemail': vendor.email,
                 'wkname': vendor.name,
                 'wkDate': delDate,
                 'lang': vendor.lang,
                 'redirectUrl': redirectUrl
             }
             mailTmplObj.with_context(**ctx).send_mail(self.id,
                                                       force_send=True)
         trusted = vendor.trusted_vendor or False
         x_notes = "VALIDATED by " + vendor.name or ""
         if trusted:
             self.write({
                 'state': 'purchase',
                 'user_id': user_id,
                 'observ': x_notes
             })
         else:
             self.write({
                 'state': "sent",
                 'user_id': user_id,
                 'observ': x_notes
             })
     else:
         raise ValidationError(_('First add the Vendors'))
コード例 #9
0
 def send_verification_email(self, res_id):
     user = self.browse(res_id)
     validity = self.env['ir.default'].sudo().get(
         'email.verification.config', 'token_validity') or 2
     expiration = now(days=+validity)
     temp_id = self.env.ref(
         'email_verification.wk_email_verification_email_template_id')
     user.partner_id.signup_prepare(signup_type="verify",
                                    expiration=expiration)
     if temp_id:
         try:
             res = temp_id.send_mail(res_id, True)
         except Exception as e:
             return False
     return True
コード例 #10
0
 def action_reset_password(self):
     create_mode = bool(self.env.context.get('create_user'))
     # Only override the rest behavior, not normal signup
     if create_mode:
         super(ResUsers, self).action_reset_password()
     else:
         expiration = now(days=+1)
         self.mapped('partner_id').signup_prepare(
             signup_type="reset", expiration=expiration)
         config = self.env.ref(
             'partner_communication_switzerland.reset_password_email')
         for user in self:
             self.env['partner.communication.job'].create({
                 'partner_id': user.partner_id.id,
                 'config_id': config.id
             })
コード例 #11
0
    def reset_password_cpnapp(self):
        """ create signup token for user, and send their signup url by email to reset password from CPNAAP """
        expiration = now(days=+1)
        self.mapped('partner_id').signup_prepare(signup_type="reset",
                                                 expiration=expiration)
        template = http.request.env['mail.template'].sudo().search([
            ('name', '=', 'Password reset CPNAAPP')
        ])[0]

        if not self.email:
            raise UserError(
                _("Cannot send email: user %s has no email address.") %
                self.name)
        template.send_mail(self.id, force_send=True, raise_exception=True)
        _logger.info("Password reset email sent for CPNAAPP user <%s> to <%s>",
                     self.login, self.email)
コード例 #12
0
ファイル: res_users.py プロジェクト: HarshalBhoir/portal
    def action_reset_password(self):
        """ create signup token for each user, and send their signup url by email """
        # prepare reset password signup
        create_mode = bool(self.env.context.get('create_user'))

        # no time limit for initial invitation, only for reset password
        expiration = False if create_mode else now(days=+1)

        self.mapped('partner_id').signup_prepare(signup_type="reset",
                                                 expiration=expiration)

        # send email to users with their signup url
        template = False
        if create_mode:
            try:
                template = self.env.ref('auth_signup.set_password_email',
                                        raise_if_not_found=False)
            except ValueError:
                pass
        if not template:
            template = self.env.ref('auth_signup.reset_password_email')
        assert template._name == 'mail.template'

        template_values = {
            'email_to': '${object.email|safe}',
            'email_cc': False,
            'auto_delete': True,
            'partner_to': False,
            'scheduled_date': False,
        }
        template.write(template_values)

        for user in self:
            if not user.email:
                raise UserError(_(
                    "Cannot send email: user %s has no email address.") % user.name)
            if not user.share:
                with self.env.cr.savepoint():
                    force_send = not (
                        self.env.context.get('import_file', False))
                    template.with_context(lang=user.lang).send_mail(user.id,
                                                                    force_send=force_send,
                                                                    raise_exception=True)
                _logger.info("Password reset email sent for user <%s> to <%s>",
                             user.login, user.email)
コード例 #13
0
    def action_reset_password(self):

        create_mode = False
        expiration = False if create_mode else now(days=+1)

        self.mapped('partner_id').signup_prepare(signup_type="reset",
                                                 expiration=expiration)

        template = False
        if create_mode:
            try:
                template = self.env.ref('auth_signup.set_password_email',
                                        raise_if_not_found=False)
            except ValueError:
                pass
        if not template:
            template = self.env.ref('auth_signup.reset_password_email')
        assert template._name == 'mail.template'
コード例 #14
0
 def action_reset_password(self):
     create_mode = bool(self.env.context.get("create_user"))
     # Only override the rest behavior, not normal signup
     if create_mode:
         super().action_reset_password()
     else:
         expiration = now(days=+1)
         self.mapped("partner_id").signup_prepare(signup_type="reset",
                                                  expiration=expiration)
         config = self.env.ref(
             "partner_communication_switzerland.reset_password_email")
         for user in self:
             self.env["partner.communication.job"].create({
                 "partner_id":
                 user.partner_id.id,
                 "config_id":
                 config.id,
                 "auto_send":
                 True,
             })
コード例 #15
0
    def action_reset_password(self):
        """
        Action to change partner's password from backend.
        generate a token and start a communication. The
        communication is not sent automatically but rather
        shown to the backend user once created.
        :return: a redirection to communication job form
        """

        # handle on reset at a time to allow redirection to work properly
        self.ensure_one()

        # use signup prepare to generate a token valid 1 day for password reset
        expiration = now(days=+1)
        self.sudo().signup_prepare(
            signup_type="reset", expiration=expiration
        )

        # create but does not send the communication for password reset
        config = self.env.ref(
            "partner_communication_switzerland.reset_password_email"
        )
        comm = self.env["partner.communication.job"].create(
            {
                "partner_id": self.id,
                "config_id": config.id,
                "auto_send": False,
            }
        )

        # redirect the backend user to the newly created communication.
        return {
            "type": "ir.actions.act_window",
            "name": "Reset Password",
            "view_type": "form",
            "view_mode": "form",
            "res_model": "partner.communication.job",
            "res_id": comm.id,
            "target": "current",
        }
コード例 #16
0
 def action_signup_prepare(self):
     for record in self:
         record.mapped('partner_id').signup_prepare(signup_type='reset',
                                                    expiration=now(days=+1))