Difference between revisions of "NationStates:Login"

From NSWiki
Jump to: navigation, search
m (lowercase)
(Undo revision 1179411 by Todd McCloud (talk))
 
(17 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<shtml version="2" keyname="afforess" hash="023ee342b4ec1700d86a7268f252e8bf51c58a901b0eb19e5f3f8960f8707165"><input id='nation_name' placeholder='Nation Name' type='text' style='width:350px;height:24px;'></input><button class='btn' style='margin-left:5px;margin-top: -3px;' id='nation_enter'>Locate Nation</button>
+
<shtml version="2" keyname="afforess" hash="3ab69b2ca4545dd7437f8024798c8e2f4f0a05a94c85dc39f2d063fd2623b329"><input id='nation_name' placeholder='Nation Name' type='text' style='width:350px;height:24px;'></input><button class='btn btn-primary' style='margin-left:5px;margin-top: -3px;' id='nation_enter'>Locate Nation</button>
 +
<p style='font-style: italic; font-size:15px; color:red;'>Ensure you are logged into the same NationStates nation you wish to login with to NSWiki! If not, go to NationStates.net and switch your nation.</p>
 
<p id='login_error' style='color:red; font-weight:bold; display:none;'>An Error Occured</p>
 
<p id='login_error' style='color:red; font-weight:bold; display:none;'>An Error Occured</p>
 +
<p id='login_status' style='color:green; font-weight:bold; display:none;'>Logging in...</p>
  
 
<div id='advanced' style='display:none; float:left;'>
 
<div id='advanced' style='display:none; float:left;'>
 
<input id='nation_verify_login' placeholder='Your Login Verification Code' type='text' style='width:450px;height:24px;'></input>
 
<input id='nation_verify_login' placeholder='Your Login Verification Code' type='text' style='width:450px;height:24px;'></input>
<button class='button primary' style='margin-left:5px;margin-top: -3px;' id='nation_verify'>Verify Nation</button>
+
<button class='btn btn-primary' style='margin-left:5px;margin-top: -3px;' id='nation_verify'>Verify Nation</button>
<iframe frameborder="0" style='float: left; height:450px; width:750px;' data-src='http://embed.nationstates.net/page=verify_login'></iframe>
+
<p style='font-style: italic; font-size:14px; color:blue;'>If the below text shows there was a problem with your request, first login to <a href='//www.nationstates.net'>NationStates.net</a> and try again.</p>
 +
<iframe frameborder="0" style='float: left; height:450px; width:750px; border: 2px solid grey; margin-top: 10px;' data-src='//embed.nationstates.net/page=verify_login'></iframe>
 
</div>
 
</div>
 
<script type="text/javascript">
 
<script type="text/javascript">
 
$(document).ready(function() {
 
$(document).ready(function() {
 +
function generatePassword() {
 +
var pass = "";
 +
var charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
 +
for( var i = 0; i < 24; i++ )
 +
pass += charset .charAt(Math.floor(Math.random() * charset.length));
 +
 +
return pass;
 +
}
 +
 +
$("#nation_name").on("keydown", function(event) {
 +
if (event.keyCode != 13) {
 +
return;
 +
}
 +
$("#nation_enter").click();
 +
});
 +
$("#nation_verify_login").on("keydown", function(event) {
 +
if (event.keyCode != 13) {
 +
return;
 +
}
 +
$("#nation_verify").click();
 +
});
 +
var ampersand = "&"[0];
 
$("#nation_enter").on("click", function(event) {
 
$("#nation_enter").on("click", function(event) {
 
event.preventDefault();
 
event.preventDefault();
 
$("#login_error").hide();
 
$("#login_error").hide();
 
$("#nation_enter").attr("disabled", true);
 
$("#nation_enter").attr("disabled", true);
$.get("/nsapi/nation/title/?name=" + encodeURIComponent($("#nation_name").val()), function(data) {
+
$.get("https://nationstatesplusplus.net/api/nation/name/?name=" + encodeURIComponent($("#nation_name").val()), function(data) {
 
console.log("found nation named " + $("#nation_name").val());
 
console.log("found nation named " + $("#nation_name").val());
 
$("#nation_enter").removeAttr("disabled").hide();
 
$("#nation_enter").removeAttr("disabled").hide();
 +
$("#nation_name").val(data[$("#nation_name").val()]);
 
$("#nation_name").hide()
 
$("#nation_name").hide()
 
$("#advanced").show();
 
$("#advanced").show();
 
}).fail(function() {
 
}).fail(function() {
$("#login_error").html("No Nationstates Nation named " + + $("#nation_name").val() + ".").show();
+
$("#login_error").html("No Nationstates Nation named " + $("#nation_name").val() + ".").show();
 
$("#nation_enter").removeAttr("disabled");
 
$("#nation_enter").removeAttr("disabled");
 
});
 
});
Line 28: Line 54:
 
event.preventDefault();
 
event.preventDefault();
 
$("#nation_verify").attr("disabled", true);
 
$("#nation_verify").attr("disabled", true);
var password = Date.now() + $("#nation_name").val().toLowerCase().split(" ").join("");
+
$("#login_status").html("Logging in...").show();
$("#nation_name").attr("password", password);
+
var password = generatePassword();
$.post("/nsapi/nswiki/login/", "nation=" + $("#nation_name").val().toLowerCase().split(" ").join("_") + "&auth=" + encodeURIComponent($("#nation_verify_login").val().trim()) + "&password=" + password, function(data) {
+
$.post("https://nationstatesplusplus.net/api/nswiki/login/", "nation=" + $("#nation_name").val().toLowerCase().split(" ").join("_") + ampersand + "auth=" + encodeURIComponent($("#nation_verify_login").val().trim()) + ampersand + "password=" + password, function(data) {
console.log("Accepted login");
+
console.log("Login Accepted");
 +
$("#login_status").html("Login Accepted...");
 
$.get("http://nswiki.org/index.php?title=Special:UserLogin", function(data) {
 
$.get("http://nswiki.org/index.php?title=Special:UserLogin", function(data) {
var token = $("input[name='wpLoginToken']").val();
+
var token = $(data).find("input[name='wpLoginToken']").val();
 
console.log("Lokin token: " + token);
 
console.log("Lokin token: " + token);
$.post("http://nswiki.org/index.php?title=Special:UserLogin&action=submitlogin&type=login", "wpName=" + encodeURIComponent($("#nation_name").val()) + "&wpPassword=" + $("#nation_name").attr("password") + "&wpRemember=1&wpLoginAttempt=Log+in&wpLoginToken=b41707a7bcb6c93ec75bb44cc30c5187", function(data) {
+
$.post("http://nswiki.org/index.php?title=Special:UserLogin" + ampersand + "action=submitlogin" + ampersand + "type=login", "wpName=" + $("#nation_name").val().split(" ").join("+") + ampersand + "wpPassword=" + password + ampersand + "wpRemember=1" + ampersand + "wpLoginAttempt=Log+in" + ampersand + "wpLoginToken=" + token, function(data) {
 
console.log("Login Successful");
 
console.log("Login Successful");
 
console.log(data);
 
console.log(data);
window.location.href = "http://nswiki.org";
+
//window.location.href = "http://nswiki.org";
 
}).fail(function(jqXHR, textStatus, errorThrown) {
 
}).fail(function(jqXHR, textStatus, errorThrown) {
$("#login_error").html(jqXHR.responseText).show();
+
console.log(jqXHR.responseText);
 +
$("#login_error").html("Login Failed. Try again or report the error to an administrator.").show();
 
$("#nation_verify").removeAttr("disabled");
 
$("#nation_verify").removeAttr("disabled");
 +
$("#login_status").hide();
 +
});
 +
});
 +
setTimeout(function() {
 +
$.get("http://nswiki.org/index.php?title=Special:UserLogin", function(data) {
 +
var token = $(data).find("input[name='wpLoginToken']").val();
 +
console.log("Lokin token: " + token);
 +
$.post("http://nswiki.org/index.php?title=Special:UserLogin" + ampersand + "action=submitlogin" + ampersand + "type=login", "wpName=" + $("#nation_name").val().split(" ").join("+") + ampersand + "wpPassword=" + password + ampersand + "wpRemember=1" + ampersand + "wpLoginAttempt=Log+in" + ampersand + "wpLoginToken=" + token, function(data) {
 +
console.log("Login Successful");
 +
console.log(data);
 +
window.location.href = "http://nswiki.org";
 +
}).fail(function(jqXHR, textStatus, errorThrown) {
 +
console.log(jqXHR.responseText);
 +
$("#login_error").html("Login Failed. Try again or report the error to an administrator.").show();
 +
$("#nation_verify").removeAttr("disabled");
 +
$("#login_status").hide();
 +
});
 
});
 
});
})
+
}, 1000);
 
}).fail(function(jqXHR, textStatus, errorThrown) {
 
}).fail(function(jqXHR, textStatus, errorThrown) {
 
$("#login_error").html(jqXHR.responseText).show();
 
$("#login_error").html(jqXHR.responseText).show();
 
$("#nation_verify").removeAttr("disabled");
 
$("#nation_verify").removeAttr("disabled");
 +
$("#login_status").hide();
 
$("iframe")[1].src = $("iframe")[1].src;
 
$("iframe")[1].src = $("iframe")[1].src;
 
});
 
});

Latest revision as of 01:00, 4 January 2017

Ensure you are logged into the same NationStates nation you wish to login with to NSWiki! If not, go to NationStates.net and switch your nation.