我正在将Rocket.Chat集成到我的系统中,该系统通过LDAP数据库共享用户帐户。我们创建了一个从我们的系统转到Rocket.Chat的快捷方式,当用户点击这个快捷方式时,我们的系统将打开Rocket.Chat页面,网址为:http://rocketchat.host:3000/?username={username}&password={password}
username
和password
是经常账户。
我们在已编译的Rocket.Chat包上改变了一些东西:
// Changed file: {bundle}\programs\web.browser\head.html
<title>Rocket.Chat</title>
<meta charset="utf-8" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="expires" content="-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="fragment" content="!" />
<meta name="distribution" content="global" />
<meta name="rating" content="general" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<meta name="msapplication-TileColor" content="#04436a">
<meta name="msapplication-TileImage" content="images/logo/mstile-144x144.png?v=3">
<meta name="msapplication-config" content="images/logo/browserconfig.xml?v=3">
<meta name="theme-color" content="#04436a">
<link rel="manifest" href="images/logo/manifest.json?v=3">
<link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/nocfbnnmjnndkbipkabodnheejiegccf">
<link rel="icon" sizes="any" type="image/svg+xml" href="assets/favicon.svg?v=3">
<link rel="icon" sizes="256x256" type="image/png" href="assets/favicon_256.png?v=3">
<link rel="icon" sizes="192x192" type="image/png" href="assets/favicon_192.png?v=3">
<link rel="icon" sizes="128x128" type="image/png" href="assets/favicon_128.png?v=3">
<link rel="icon" sizes="96x96" type="image/png" href="assets/favicon_96.png?v=3">
<link rel="icon" sizes="64x64" type="image/png" href="assets/favicon_64.png?v=3">
<link rel="shortcut icon" sizes="16x16 32x32 48x48" type="image/x-icon" href="assets/favicon_ico.ico?v=3" />
<link rel="apple-touch-icon" sizes="57x57" href="images/logo/apple-touch-icon-57x57.png?v=3">
<link rel="apple-touch-icon" sizes="60x60" href="images/logo/apple-touch-icon-60x60.png?v=3">
<link rel="apple-touch-icon" sizes="72x72" href="images/logo/apple-touch-icon-72x72.png?v=3">
<link rel="apple-touch-icon" sizes="76x76" href="images/logo/apple-touch-icon-76x76.png?v=3">
<link rel="apple-touch-icon" sizes="114x114" href="images/logo/apple-touch-icon-114x114.png?v=3">
<link rel="apple-touch-icon" sizes="120x120" href="images/logo/apple-touch-icon-120x120.png?v=3">
<link rel="apple-touch-icon" sizes="144x144" href="images/logo/apple-touch-icon-144x144.png?v=3">
<link rel="apple-touch-icon" sizes="152x152" href="images/logo/apple-touch-icon-152x152.png?v=3">
<link rel="apple-touch-icon" sizes="180x180" href="images/logo/apple-touch-icon-180x180.png?v=3">
<script type="text/javascript">
// alert("test js");
</script>
<script type="text/javascript">
function getURLParameter(name) {
console.log("location.search: " + location.search);
var result = decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
console.log("getURLParameter, " + name + ": " + result);
return result;
}
var username = getURLParameter('username'),
password = getURLParameter('password'); // Query parameter from url that our system passed
Meteor.loginWithPassword(username, password, function () {
console.log('loginWithPassword callback, username: ' + username + "; password:" + password);
}); // Call login direct to Meteor.login
// Query "username" and "password" input fields from login from then pass data and simulate click login button
document.addEventListener("DOMContentLoaded", function(event) {
document.getElementById('username').value = username;
document.getElementById('password').value = password;
document.getElementById('loginButton').click();
});
</script>
我们还在{bundle}\programs\web.browser\{sso number}.js
更改了Rocket.Chat的缩小javascript文件,其中sso number
是构建工具生成的随机数:
原件:
...
function(){o.loginLayout.onRendered(function(){$("#initial-page-loading").remove()})}.call(this)
...
要:
...
function(){o.loginLayout.onRendered(function(){function e(e){return decodeURIComponent((new RegExp("[?|&]"+e+"=([^&;]+?)(&|#|;|$)").exec(location.search)||[null,""])[1].replace(/\+/g,"%20"))||null}$("#initial-pageloading").remove();varn=e("username"),t=e("password");console.log("username,password="+n+","+t),console.log("getElementById(username)="+$("input[name=emailOrUsername]").val()),"null"!=n&&"null"!=t&&($("input[name=emailOrUsername]").val(n),$("input[name=pass]").val(t),$(".login")[0].click())})}.call(this)
...
它对应于Rocket.Chat源代码文件“{source code} \ packages \ rocketchat-ui-login \ login \ layout.js”中的以下代码:
Template.loginLayout.onRendered(function() {
$('#initial-page-loading').remove();
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
}
var username = getURLParameter('username'),
password = getURLParameter('password');
console.log("username,password="+username+","+password);
console.log("getElementById(username)="+$('input[name=emailOrUsername]').val());
if (username != 'null' && password != 'null') {
$('input[name=emailOrUsername]').val(username);
$('input[name=pass]').val(password);
$('.login')[0].click();
}
});
以前已经通过Rocket.Chat登录表单登录帐户(案例1 ),它运行正常。但如果帐户尚未确定(案例2 ),则会失败。
案例1 :此Chrome日志:
案例2 :Chrome日志:
问题:我知道Rocket.Chat有问题是首先通过Meteor.loginWithPassword()
api登录,然后我会模拟登录UI。我知道这些日志意味着找不到“登录表单”。我的问题是为什么我的登录UI模拟不起作用?我该如何解决?
谢谢!