Consolidate success handler

This commit is contained in:
Terry W Brady
2018-01-24 10:13:31 -08:00
parent ec7781156c
commit 80f3df4740

View File

@@ -61,6 +61,13 @@
<script>
$(document).ready(function() {
var successHandler = function(result, status, xhr) {
document.cookie = "MyHalBrowserToken=" + xhr.getResponseHeader('Authorization').split(" ")[1];
toastr.success('You are now logged in. Please wait while we redirect you...', 'Login Successful');
setTimeout(function() {
window.location.href = window.location.pathname.replace("login.html", "");
}, 2000);
};
toastr.options = {
"closeButton": false,
"debug": false,
@@ -81,13 +88,7 @@
$.ajax({
url : window.location.href.replace("login.html", "") + 'api/authn/login',
success : function(result, status, xhr) {
document.cookie = "MyHalBrowserToken=" + xhr.getResponseHeader('Authorization').split(" ")[1];
toastr.success('You are now logged in. Please wait while we redirect you...', 'Login Successful');
setTimeout(function() {
window.location.href = window.location.pathname.replace("login.html", "");
}, 2000);
},
success : successHandler,
error : function(result, status, xhr) {
if (xhr == 401) {
var loc = result.getResponseHeader("location");
@@ -110,13 +111,7 @@
"Content-Type" : 'application/x-www-form-urlencoded',
"Accept:" : '*/*'
},
success : function(result, status, xhr) {
document.cookie = "MyHalBrowserToken=" + xhr.getResponseHeader('Authorization').split(" ")[1];
toastr.success('You are now logged in. Please wait while we redirect you...', 'Login Successful');
setTimeout(function() {
window.location.href = window.location.pathname.replace("login.html", "");
}, 2000);
},
success : successHandler,
error : function() {
toastr.error('The credentials you entered are invalid. Please try again.', 'Login Failed');
}