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> <script>
$(document).ready(function() { $(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 = { toastr.options = {
"closeButton": false, "closeButton": false,
"debug": false, "debug": false,
@@ -81,13 +88,7 @@
$.ajax({ $.ajax({
url : window.location.href.replace("login.html", "") + 'api/authn/login', url : window.location.href.replace("login.html", "") + 'api/authn/login',
success : function(result, status, xhr) { success : successHandler,
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);
},
error : function(result, status, xhr) { error : function(result, status, xhr) {
if (xhr == 401) { if (xhr == 401) {
var loc = result.getResponseHeader("location"); var loc = result.getResponseHeader("location");
@@ -110,13 +111,7 @@
"Content-Type" : 'application/x-www-form-urlencoded', "Content-Type" : 'application/x-www-form-urlencoded',
"Accept:" : '*/*' "Accept:" : '*/*'
}, },
success : function(result, status, xhr) { success : successHandler,
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);
},
error : function() { error : function() {
toastr.error('The credentials you entered are invalid. Please try again.', 'Login Failed'); toastr.error('The credentials you entered are invalid. Please try again.', 'Login Failed');
} }