From 70cd91e6fed727e1f623d0749f81746a054b7306 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Sun, 18 Feb 2018 14:14:00 +0000 Subject: [PATCH] Encode the services JSON in the logout handler --- server/bindata.go | 18 +++++++++--------- server/http.go | 6 ++++-- server/static/js/logout.js | 8 ++++---- server/templates/logout.html | 2 +- server/templates/page.html | 2 +- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/server/bindata.go b/server/bindata.go index dd0fe6a..f7ec29f 100644 --- a/server/bindata.go +++ b/server/bindata.go @@ -200,7 +200,7 @@ idlogout.get_services = function() { return JSON.parse($('#services').attr('data-services')); }; -idlogout.logout_service = function(service) { +idlogout.logout_service = function(idx, service) { var logout_url = service.url + 'sso_logout'; console.log('logging out of ' + service.name); $.ajax({ @@ -211,11 +211,11 @@ idlogout.logout_service = function(service) { withCredentials: true }, success: function() { - $('#status_'+service.idx).class('logout-status-ok').text('OK'); + $('#status_'+idx).class('logout-status-ok').text('OK'); console.log('successful logout for ' + service.name); }, error: function() { - $('#status_'+service.idx).class('logout-status-error').text('ERROR'); + $('#status_'+idx).class('logout-status-error').text('ERROR'); console.log('error logging out of ' + service.name); } }); @@ -224,7 +224,7 @@ idlogout.logout_service = function(service) { idlogout.logout = function() { var services = idlogout.get_services(); $.each(services, function(index, arg) { - idlogout.logout_service(arg); + idlogout.logout_service(index, arg); }); }; @@ -243,7 +243,7 @@ func staticJsLogoutJs() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "static/js/logout.js", size: 1019, mode: os.FileMode(436), modTime: time.Unix(1518961249, 0)} + info := bindataFileInfo{name: "static/js/logout.js", size: 1015, mode: os.FileMode(436), modTime: time.Unix(1518963191, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -1276,7 +1276,7 @@ var _templatesLogoutHtml = []byte(`{{template "header" .}} {{end}} </ul> - <div id="#services" data-services="[{{range $i, $svc := .Services}}{{if gt $i 0}},{{end}}{%22idx%22:{{$i}},%22name%22:%22{{$svc.Name}}%22,%22url%22:%22{{$svc.URL}}%22}{{end}}]"></div> + <div id="services" data-services="{{.ServicesJSON}}"></div> </div> {{else}} @@ -1313,7 +1313,7 @@ func templatesLogoutHtml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "templates/logout.html", size: 1505, mode: os.FileMode(436), modTime: time.Unix(1518961241, 0)} + info := bindataFileInfo{name: "templates/logout.html", size: 1381, mode: os.FileMode(436), modTime: time.Unix(1518963171, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -1344,7 +1344,7 @@ var _templatesPageHtml = []byte(`{{define "header"}}<!DOCTYPE html> <script type="text/javascript" src="/static/js/u2f.js" integrity="sha384-vd6lytRvVm189G5gr34wlOvN672vVBceTZqV+lTSeec0DBLc0GlWLyKDHc6mrIZS"></script> {{end}} {{if .IncludeLogoutScripts}} - <script type="text/javascript" src="/static/js/logout.js" integrity="sha384-+V9VUvMMX5z37HxqZoSrTvQ2vHEH3OPksWy9gyQYfeWdzxtmpNR1r/z3+i0roLxS"></script> + <script type="text/javascript" src="/static/js/logout.js" integrity="sha384-swhUuZtRhByZOwc9Obn/dcrmcTXonO4xFuaIZKU3X8Ge/DSv3b+O4rL0+rjzRiRz"></script> {{end}} </body> </html> @@ -1361,7 +1361,7 @@ func templatesPageHtml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "templates/page.html", size: 1686, mode: os.FileMode(436), modTime: time.Unix(1518961516, 0)} + info := bindataFileInfo{name: "templates/page.html", size: 1686, mode: os.FileMode(436), modTime: time.Unix(1518963201, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/server/http.go b/server/http.go index efd91d6..1b669f3 100644 --- a/server/http.go +++ b/server/http.go @@ -5,6 +5,7 @@ package server import ( "encoding/gob" + "encoding/json" "fmt" "html/template" "io" @@ -234,8 +235,8 @@ func (h *Server) handleHomepage(w http.ResponseWriter, req *http.Request, sessio } type logoutServiceInfo struct { - URL string - Name string + URL string `json:"url"` + Name string `json:"name"` } func (h *Server) handleLogout(w http.ResponseWriter, req *http.Request, session *authSession) { @@ -255,6 +256,7 @@ func (h *Server) handleLogout(w http.ResponseWriter, req *http.Request, session if req.Method == "POST" { data["IsPOST"] = true data["IncludeLogoutScripts"] = true + data["ServicesJSON"], _ = json.Marshal(svcs) // Clear the local session. httpSession, _ := h.authSessionStore.Get(req, authSessionKey) diff --git a/server/static/js/logout.js b/server/static/js/logout.js index e8b4863..c516f35 100644 --- a/server/static/js/logout.js +++ b/server/static/js/logout.js @@ -4,7 +4,7 @@ idlogout.get_services = function() { return JSON.parse($('#services').attr('data-services')); }; -idlogout.logout_service = function(service) { +idlogout.logout_service = function(idx, service) { var logout_url = service.url + 'sso_logout'; console.log('logging out of ' + service.name); $.ajax({ @@ -15,11 +15,11 @@ idlogout.logout_service = function(service) { withCredentials: true }, success: function() { - $('#status_'+service.idx).class('logout-status-ok').text('OK'); + $('#status_'+idx).class('logout-status-ok').text('OK'); console.log('successful logout for ' + service.name); }, error: function() { - $('#status_'+service.idx).class('logout-status-error').text('ERROR'); + $('#status_'+idx).class('logout-status-error').text('ERROR'); console.log('error logging out of ' + service.name); } }); @@ -28,7 +28,7 @@ idlogout.logout_service = function(service) { idlogout.logout = function() { var services = idlogout.get_services(); $.each(services, function(index, arg) { - idlogout.logout_service(arg); + idlogout.logout_service(index, arg); }); }; diff --git a/server/templates/logout.html b/server/templates/logout.html index 769b6b0..a6f12cc 100644 --- a/server/templates/logout.html +++ b/server/templates/logout.html @@ -32,7 +32,7 @@ {{end}} </ul> - <div id="#services" data-services="[{{range $i, $svc := .Services}}{{if gt $i 0}},{{end}}{%22idx%22:{{$i}},%22name%22:%22{{$svc.Name}}%22,%22url%22:%22{{$svc.URL}}%22}{{end}}]"></div> + <div id="services" data-services="{{.ServicesJSON}}"></div> </div> {{else}} diff --git a/server/templates/page.html b/server/templates/page.html index 103864b..9acab50 100644 --- a/server/templates/page.html +++ b/server/templates/page.html @@ -24,7 +24,7 @@ <script type="text/javascript" src="/static/js/u2f.js" integrity="sha384-vd6lytRvVm189G5gr34wlOvN672vVBceTZqV+lTSeec0DBLc0GlWLyKDHc6mrIZS"></script> {{end}} {{if .IncludeLogoutScripts}} - <script type="text/javascript" src="/static/js/logout.js" integrity="sha384-+V9VUvMMX5z37HxqZoSrTvQ2vHEH3OPksWy9gyQYfeWdzxtmpNR1r/z3+i0roLxS"></script> + <script type="text/javascript" src="/static/js/logout.js" integrity="sha384-swhUuZtRhByZOwc9Obn/dcrmcTXonO4xFuaIZKU3X8Ge/DSv3b+O4rL0+rjzRiRz"></script> {{end}} </body> </html> -- GitLab