Difference between revisions of "NationStates:Login"
From NSWiki
(add status message) |
Todd McCloud (Talk | contribs) (Undo revision 1179411 by Todd McCloud (talk)) |
||
(10 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | <shtml version="2" keyname="afforess" hash=" | + | <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> | <p id='login_status' style='color:green; font-weight:bold; display:none;'>Logging in...</p> | ||
Line 5: | Line 6: | ||
<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='btn' 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=' | + | <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) { | $("#nation_name").on("keydown", function(event) { | ||
if (event.keyCode != 13) { | if (event.keyCode != 13) { | ||
Line 22: | Line 33: | ||
$("#nation_verify").click(); | $("#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("/ | + | $.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(); | ||
Line 35: | Line 45: | ||
$("#advanced").show(); | $("#advanced").show(); | ||
}).fail(function() { | }).fail(function() { | ||
− | $("#login_error").html("No Nationstates Nation named " | + | $("#login_error").html("No Nationstates Nation named " + $("#nation_name").val() + ".").show(); |
$("#nation_enter").removeAttr("disabled"); | $("#nation_enter").removeAttr("disabled"); | ||
}); | }); | ||
Line 45: | Line 55: | ||
$("#nation_verify").attr("disabled", true); | $("#nation_verify").attr("disabled", true); | ||
$("#login_status").html("Logging in...").show(); | $("#login_status").html("Logging in...").show(); | ||
− | var password = | + | var password = generatePassword(); |
− | $ | + | $.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("Login Accepted"); | console.log("Login Accepted"); | ||
$("#login_status").html("Login Accepted..."); | $("#login_status").html("Login Accepted..."); | ||
Line 53: | Line 62: | ||
var token = $(data).find("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" + ampersand + "action=submitlogin" + ampersand + "type=login", "wpName=" + $("#nation_name").val().split(" ").join("+") + ampersand + "wpPassword=" + | + | $.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( | + | 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(); | $("#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(); |
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.