mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-06-28 15:45:35 +08:00
"dingtalk QR login" frontend
This commit is contained in:
parent
c768845a45
commit
5404db07eb
@ -37,6 +37,7 @@ func (c *AccountController) Prepare() {
|
|||||||
c.Data["xsrfdata"] = template.HTML(c.XSRFFormHTML())
|
c.Data["xsrfdata"] = template.HTML(c.XSRFFormHTML())
|
||||||
c.Data["corpID"] = beego.AppConfig.String("dingtalk_corpid")
|
c.Data["corpID"] = beego.AppConfig.String("dingtalk_corpid")
|
||||||
c.Data["ENABLE_QR_DINGTALK"] = (beego.AppConfig.String("dingtalk_corpid") != "")
|
c.Data["ENABLE_QR_DINGTALK"] = (beego.AppConfig.String("dingtalk_corpid") != "")
|
||||||
|
c.Data["dingtalk_qr_key"] = beego.AppConfig.String("dingtalk_qr_key")
|
||||||
|
|
||||||
if !c.EnableXSRF {
|
if !c.EnableXSRF {
|
||||||
return
|
return
|
||||||
|
18
static/js/dingtalk-ddlogin.js
Normal file
18
static/js/dingtalk-ddlogin.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
!function (window, document) {
|
||||||
|
function d(a) {
|
||||||
|
var e, c = document.createElement("iframe"),
|
||||||
|
d = "https://login.dingtalk.com/login/qrcode.htm?goto=" + a.goto ;
|
||||||
|
d += a.style ? "&style=" + encodeURIComponent(a.style) : "",
|
||||||
|
d += a.href ? "&href=" + a.href : "",
|
||||||
|
c.src = d,
|
||||||
|
c.frameBorder = "0",
|
||||||
|
c.allowTransparency = "true",
|
||||||
|
c.scrolling = "no",
|
||||||
|
c.width = a.width ? a.width + 'px' : "365px",
|
||||||
|
c.height = a.height ? a.height + 'px' : "400px",
|
||||||
|
e = document.getElementById(a.id),
|
||||||
|
e.innerHTML = "",
|
||||||
|
e.appendChild(c)
|
||||||
|
}
|
||||||
|
window.DDLogin = d
|
||||||
|
}(window, document);
|
@ -72,7 +72,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{{if .ENABLE_QR_DINGTALK}}
|
{{if .ENABLE_QR_DINGTALK}}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<a href='https://oapi.dingtalk.com/connect/qrconnect?appid=dingoa0wp8qg6gyqtlyno1&response_type=code&scope=snsapi_login&state=1&redirect_uri={{ urlfor "AccountController.QRLogin" ":app" "dingtalk"}}' id="btn-dingtalk-qr" class="btn btn-default" style="width: 100%" data-loading-text="" autocomplete="off">钉钉扫码登录</a>
|
<a id="btn-dingtalk-qr" class="btn btn-default" style="width: 100%" data-loading-text="" autocomplete="off">钉钉扫码登录</a>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .ENABLED_REGISTER}}
|
{{if .ENABLED_REGISTER}}
|
||||||
@ -83,6 +83,10 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</form>
|
</form>
|
||||||
|
<div class="form-group dingtalk-container" style="display: none;">
|
||||||
|
<div id="dingtalk-qr-container"></div>
|
||||||
|
<a class="btn btn-default btn-dingtalk" style="width: 100%" data-loading-text="" autocomplete="off">返回账号密码登录</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
@ -92,6 +96,8 @@
|
|||||||
<script src="{{cdnjs "/static/bootstrap/js/bootstrap.min.js"}}" type="text/javascript"></script>
|
<script src="{{cdnjs "/static/bootstrap/js/bootstrap.min.js"}}" type="text/javascript"></script>
|
||||||
<script src="{{cdnjs "/static/layer/layer.js"}}" type="text/javascript"></script>
|
<script src="{{cdnjs "/static/layer/layer.js"}}" type="text/javascript"></script>
|
||||||
<script src="{{cdnjs "/static/js/dingtalk-jsapi.js"}}" type="text/javascript"></script>
|
<script src="{{cdnjs "/static/js/dingtalk-jsapi.js"}}" type="text/javascript"></script>
|
||||||
|
<script src="{{cdnjs "/static/js/dingtalk-ddlogin.js"}}" type="text/javascript"></script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function () {
|
$(function () {
|
||||||
if (dd.env.platform !== "notInDingTalk"){
|
if (dd.env.platform !== "notInDingTalk"){
|
||||||
@ -132,6 +138,34 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
var url = 'https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid={{.dingtalk_qr_key}}&response_type=code&scope=snsapi_login&state=1&redirect_uri={{ urlfor "AccountController.QRLogin" ":app" "dingtalk"}}'
|
||||||
|
var obj = DDLogin({
|
||||||
|
id:"dingtalk-qr-container",
|
||||||
|
goto: encodeURIComponent(url),
|
||||||
|
style: "border:none;background-color:#FFFFFF;",
|
||||||
|
width : "338",
|
||||||
|
height: "300"
|
||||||
|
});
|
||||||
|
var handleMessage = function (event) {
|
||||||
|
var origin = event.origin;
|
||||||
|
if( origin == "https://login.dingtalk.com" ) { //判断是否来自ddLogin扫码事件。
|
||||||
|
layer.load(1, { shade: [0.1, '#fff'] })
|
||||||
|
var loginTmpCode = event.data;
|
||||||
|
//获取到loginTmpCode后就可以在这里构造跳转链接进行跳转了
|
||||||
|
console.log("loginTmpCode", loginTmpCode);
|
||||||
|
url = url + "&loginTmpCode=" + loginTmpCode
|
||||||
|
window.location = url
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (typeof window.addEventListener != 'undefined') {
|
||||||
|
window.addEventListener('message', handleMessage, false);
|
||||||
|
} else if (typeof window.attachEvent != 'undefined') {
|
||||||
|
window.attachEvent('onmessage', handleMessage);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function () {
|
$(function () {
|
||||||
$("#account,#password,#code").on('focus', function () {
|
$("#account,#password,#code").on('focus', function () {
|
||||||
@ -145,6 +179,16 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#btn-dingtalk-qr").on('click', function(){
|
||||||
|
$('form').hide()
|
||||||
|
$(".dingtalk-container").show()
|
||||||
|
})
|
||||||
|
|
||||||
|
$(".btn-dingtalk").on('click', function(){
|
||||||
|
$('form').show()
|
||||||
|
$(".dingtalk-container").hide()
|
||||||
|
})
|
||||||
|
|
||||||
$("#btn-login").on('click', function () {
|
$("#btn-login").on('click', function () {
|
||||||
$(this).tooltip('destroy').parents('.form-group').removeClass('has-error');
|
$(this).tooltip('destroy').parents('.form-group').removeClass('has-error');
|
||||||
var $btn = $(this).button('loading');
|
var $btn = $(this).button('loading');
|
||||||
|
Loading…
Reference in New Issue
Block a user