Skip to content

Instantly share code, notes, and snippets.

@digitaltoad
Last active March 2, 2017 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitaltoad/19df46e165e072d8e09d34dd9e77ee2c to your computer and use it in GitHub Desktop.
Save digitaltoad/19df46e165e072d8e09d34dd9e77ee2c to your computer and use it in GitHub Desktop.
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