1
This commit is contained in:
@@ -27,6 +27,12 @@
|
|||||||
'wizard/wecom_api_sync_wizard.xml',
|
'wizard/wecom_api_sync_wizard.xml',
|
||||||
'views/wx_work_views.xml',
|
'views/wx_work_views.xml',
|
||||||
],
|
],
|
||||||
|
"assets": {
|
||||||
|
|
||||||
|
"web.assets_frontend": [
|
||||||
|
"yuthon_wechat/static/src/js/frontend/**/*",
|
||||||
|
],
|
||||||
|
},
|
||||||
'application': True,
|
'application': True,
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'auto_install': False,
|
'auto_install': False,
|
||||||
|
|||||||
@@ -1,12 +1,32 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
||||||
|
|
||||||
|
# !参考 \addons\auth_oauth\controllers\main.py
|
||||||
|
|
||||||
from odoo import http
|
import base64
|
||||||
|
import functools
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
import werkzeug.urls
|
||||||
|
import werkzeug.utils
|
||||||
|
from werkzeug.exceptions import BadRequest
|
||||||
|
|
||||||
|
from odoo import api, http, SUPERUSER_ID, _
|
||||||
|
from odoo.exceptions import AccessDenied
|
||||||
|
from odoo.http import request, Response
|
||||||
|
from odoo import registry as registry_get
|
||||||
|
from odoo.tools.misc import clean_context
|
||||||
|
|
||||||
|
from odoo.addons.auth_signup.controllers.main import AuthSignupHome as Home # type: ignore
|
||||||
|
from odoo.addons.auth_oauth.controllers.main import OAuthController # type: ignore
|
||||||
|
from odoo.addons.web.controllers.utils import ensure_db, _get_login_redirect_url # type: ignore
|
||||||
|
from odoo.addons.wecom_api.api.wecom_abstract_api import ApiException # type: ignore
|
||||||
|
|
||||||
|
|
||||||
class Home(http.Controller):
|
class Home(http.Controller):
|
||||||
@http.route('/WW_verify_fC7AX158Ffby8Ed1.txt', type='http', auth="public")
|
@http.route('/WW_verify_fC7AX158Ffby8Ed1.txt', type='http', auth="public")
|
||||||
def WW_verify_UP42BAWNwtWK60RH(self):
|
def WW_verify_UP42BAWNwtWK60RH(self):
|
||||||
return 'fC7AX158Ffby8Ed1'
|
return 'fC7AX158Ffby8Ed1'
|
||||||
|
|
||||||
|
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
<field name="name">Wechat Corp</field>
|
<field name="name">Wechat Corp</field>
|
||||||
<field name="body">企业微信扫码登录</field>
|
<field name="body">企业微信扫码登录</field>
|
||||||
<field name="client_id">corpid agentid corpsecret</field>
|
<field name="client_id">corpid agentid corpsecret</field>
|
||||||
|
<field name="css_class">fa fa-fw fa-sign-in text-primary wecom_qr_login</field>
|
||||||
<field name="auth_endpoint">https://open.work.weixin.qq.com/wwopen/sso/qrConnect</field>
|
<field name="auth_endpoint">https://open.work.weixin.qq.com/wwopen/sso/qrConnect</field>
|
||||||
<field name="validation_endpoint">https://qyapi.weixin.qq.com/cgi-bin/gettoken</field>
|
<field name="validation_endpoint">https://qyapi.weixin.qq.com/cgi-bin/gettoken</field>
|
||||||
<field name="data_endpoint">https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo</field>
|
<field name="data_endpoint">https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo</field>
|
||||||
@@ -14,6 +15,7 @@
|
|||||||
<field name="name">Wechat Corp2</field>
|
<field name="name">Wechat Corp2</field>
|
||||||
<field name="body">企业微信直接登录</field>
|
<field name="body">企业微信直接登录</field>
|
||||||
<field name="client_id">corpid agentid corpsecret</field>
|
<field name="client_id">corpid agentid corpsecret</field>
|
||||||
|
<field name="css_class">fa fa-fw fa-sign-in text-primary wecom_quick_login</field>
|
||||||
<field name="auth_endpoint">https://open.weixin.qq.com/connect/oauth2/authorize</field>
|
<field name="auth_endpoint">https://open.weixin.qq.com/connect/oauth2/authorize</field>
|
||||||
<field name="validation_endpoint">https://qyapi.weixin.qq.com/cgi-bin/gettoken</field>
|
<field name="validation_endpoint">https://qyapi.weixin.qq.com/cgi-bin/gettoken</field>
|
||||||
<field name="data_endpoint">https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo</field>
|
<field name="data_endpoint">https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo</field>
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
import { browser } from "@web/core/browser/browser";
|
||||||
|
import { _t } from "@web/core/l10n/translation";
|
||||||
|
import { markup } from "@odoo/owl";
|
||||||
|
import { sprintf } from '@web/core/utils/strings';
|
||||||
|
import { session } from "@web/session";
|
||||||
|
import { WecomSsoLoginDialog } from "../wecom_sso_login_dialog/wecom_sso_login_dialog";
|
||||||
|
|
||||||
|
import publicWidget from "@web/legacy/js/public/public_widget";
|
||||||
|
|
||||||
|
publicWidget.registry.WecomAuthProviders = publicWidget.Widget.extend({
|
||||||
|
selector: 'div.o_login_auth',
|
||||||
|
events: {
|
||||||
|
// 'click a': '_onClick',
|
||||||
|
},
|
||||||
|
jsLibs: [
|
||||||
|
// document.location.protocol + "//wwcdn.weixin.qq.com/node/open/js/wecom-jssdk-2.0.2.js",
|
||||||
|
],
|
||||||
|
init: function (parent, options) {
|
||||||
|
this.rpc = this.bindService("rpc");
|
||||||
|
this.orm = this.bindService("orm");
|
||||||
|
this.dialog = this.bindService("dialog");
|
||||||
|
|
||||||
|
return this._super.apply(this, arguments);
|
||||||
|
},
|
||||||
|
start: function () {
|
||||||
|
var def = this._super.apply(this, arguments);
|
||||||
|
this.formEl = this.el.closest('form');
|
||||||
|
|
||||||
|
this.isWecomClient = this.checkWecomClient();
|
||||||
|
|
||||||
|
this.initAuthLinkElement();
|
||||||
|
|
||||||
|
return def;
|
||||||
|
},
|
||||||
|
checkWecomClient: function () {
|
||||||
|
/*
|
||||||
|
mozilla/5.0 (windows nt 10.0; wow64) applewebkit/537.36 (khtml, like gecko) chrome/129.0.6668.101 safari/537.36 language/zh colorscheme/light wxwork/4.1.33 (micromessenger/6.2) windowswechat mailplugin_electron wemail embeddisk wwmver/3.26.16.708
|
||||||
|
*/
|
||||||
|
const ua = navigator.userAgent.toLowerCase();
|
||||||
|
if (ua.match(/WxWork/i) === "wxwork") {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
initAuthLinkElement: function () {
|
||||||
|
const self = this;
|
||||||
|
self.el.querySelectorAll('a').forEach(function (linkElement) {
|
||||||
|
let iconElement = linkElement.firstElementChild;
|
||||||
|
if (self.isWecomClient && iconElement.classList.contains('wecom_quick_login')) {
|
||||||
|
// 企业微信客户端自动登录到Odoo
|
||||||
|
self._wecomClientAutoLogin(linkElement);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
_wecomClientAutoLogin(linkElement) {
|
||||||
|
|
||||||
|
// https://open.weixin.qq.com/connect/oauth2/authorize?
|
||||||
|
// appid=wwc955c117b738b052&agentid=1000115
|
||||||
|
// &redirect_uri=http://82.156.218.102:8057/auth_oauth/signin&
|
||||||
|
// state={"d":+"2531310",+"p":+5,+"r":+"http%3A%2F%2F82.156.218.102%3A8057%2Fweb"}&response_type=code&scope=snsapi_base#wechat_redirect
|
||||||
|
let urlString = linkElement.getAttribute('href');
|
||||||
|
|
||||||
|
window.location.href = urlString;
|
||||||
|
},
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user