[英]How to Autofill and login into a website from external login page?
Different customers use different websites to log-in to their account. 不同的客户使用不同的网站登录他们的帐户。 i want to provide them a single form to put their credentials onto it, and select the domain/platform t they want themselves log in to and those credentials are passed to the desired website's login form log them into it.
我想为他们提供一个表单,以便将其凭据放到上面,然后选择他们希望自己登录的域/平台,并将这些凭据传递到所需网站的登录表单中,然后将其登录到其中。 So, help me to send the credentials to the website.
因此,请帮助我将凭据发送到网站。 You can see the login form @ www.ubfmgps.com/login.html
您可以看到登录表单@ www.ubfmgps.com/login.html
Here is my html form to get the credentials 这是我的HTML表单以获取凭据
<form action="#" id="gaq-form" class="form-b" method="post">
<fieldset>
<p>
<span>
<label for="fba">Username</label>
<input type="text" id="txtUserName" name="txtUserName" autocomplete="on" required>
</span>
<span>
<label for="fbb">Password</label>
<input type="Password" id="txtUserPassword" name="txtUserPassword" required>
</span>
</p>
<p>
<solid>Choose Platform</solid>
<select name="platform" id="platform" width=100px>
<p> <option value="Jimishare" id="Jimishare">Jimishare</option>
<option value="Tracksolid" id="Tracksolid">Tracksolid</option>
<option value="Gpsyeah" id="Gpsyeah">Gpsyeah</option>
</select>
</p>
</p>
<p><button type="submit" onclick="login();">Log Me In</button></p>
</fieldset>
</form>
<script type="text/javascript">
function login()
{
if(document.getElementById("platform").value=='Jimishare')
{
var txtUserName = document.getElementById("username").value;
var txtUserPassword = document.getElementById("password").value;
$.ajax({
url : "http://www.jimishare.com",
type : 'post',
data : 'txtUserName=' + encodeURIComponent(username) + 'txtUserPassword=' + encodeURIComponent(password),
dataType : 'json',
error : function(data) { console.log("error"); console.error(data); },
success : function(data) { console.log("success"); console.info(data); }
});
}
else if (document.getElementById("platform").value=='Tracksolid') {
document.write("Tracksolid");
var account = document.getElementById("username").value;
var password = document.getElementById("password").value;
$.ajax({
url : "http://www.tracksolid.com/mainFrame",
type : 'post',
data : 'account=' + encodeURIComponent(account) + 'password=' + encodeURIComponent(password),
dataType : 'json',
error : function(data) { console.log("error"); console.error(data); },
success : function(data) { console.log("success"); console.info(data); }
});
}
else {
document.write("Gpsyeah");
}
}
</script>
As everyone said, you are looking for a SSO system. 大家都说过,您正在寻找SSO系统。 Anyway, if you want to make a quick login system, you have to add some javascript to perform this operation.
无论如何,如果要创建快速登录系统,则必须添加一些JavaScript才能执行此操作。
You need to define a mapping which describe the username and password fields name for each sites. 您需要定义一个映射,以描述每个站点的用户名和密码字段名称。 Assuming you have jQuery, you can try like this :
假设您有jQuery,则可以这样尝试:
$(document).ready(function() {
form = $("#gaq-form");
websitePickerField = $("select[name='platform']");
usernameField = $("#username");
passwordfield = $("#password");
submitBtn = $('#submit');
form.submit(function() {
updateFormAttrs($(this).val());
});
});
function updateFormAttrs(currentWebsite) {
var options = mapping[currentWebsite];
form.attr('action', options.url);
usernameField.attr('name', options.usernameName);
passwordfield.attr('name', options.passwordName);
submitBtn.attr('name', options.submitName);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.