在条件odoo 10中自动注销

时间:2018-04-12 16:17:22

标签: python session odoo-10

当我尝试在odoo 10中进行自动注销时遇到了问题。我创建了更改密码页面,更改密码后,我想要结束会话并再次返回登录页面。但结果从来没有让我登录页面。这是我的代码:

@api.model
def create(self, vals):
    res = super(MyPass, self).create(vals)

    get_new_passwd = vals['new_password']
    get_conf_passwd = vals['confirm_pwd']

    if get_conf_passwd != get_new_passwd:
        raise ValidationError ("Pass")

    hashing_pass = CryptContext(['pbkdf2_sha512']).encrypt(get_new_passwd)

    data_users = self.env['res.users'].browse(self.env.uid)


    data_users.write({'password_crypt': hashing_pass})
    request.session.logout(keep_db=True

我找到了解决方案。

def check(self, **kw):
    get_re_users = request.env.user
    error = {}
    if get_re_users.passwd_changed:
        return werkzeug.utils.redirect('/web')
    else:
        if request.httprequest.method == 'POST':
            get_new_passwd = http.request.params['new_password']
            get_conf_passwd = http.request.params['confirm_pwd']

            session = http.request.session

            hashing_pass = CryptContext(['pbkdf2_sha512']).encrypt(get_new_passwd)

            data_users = http.request.env['res.users'].sudo().browse(http.request.env.uid)

            data_users.write({'password_crypt': hashing_pass, "passwd_changed":True, "name":get_username_odoo, "login":get_name_login})

            if session.db and session.uid:
                session.logout(keep_db=True)
                # return {
                #   'type' : 'ir.actions.act_url',
                #   'url': '/web',
                #   'target': 'self',
                # }
                return werkzeug.utils.redirect('/web/login')

        return http.request.render('name_model.id_view')

0 个答案:

没有答案