diff --git a/main.go b/main.go index 63363c9..3e37e08 100644 --- a/main.go +++ b/main.go @@ -111,6 +111,17 @@ func loginHandler(w http.ResponseWriter, r *http.Request) { glog.Infof("Created a HTTP session [%s] for user [%s]", httpSession.Values["id"].(string), args.Username) } +// 退出(登出). +func logoutHandler(w http.ResponseWriter, r *http.Request) { + data := map[string]interface{}{"succ": true} + defer util.RetJSON(w, r, data) + + httpSession, _ := session.HTTPSession.Get(r, "wide-session") + + httpSession.Options.MaxAge = 0 + httpSession.Save(r, w) +} + // Wide 首页. func indexHandler(w http.ResponseWriter, r *http.Request) { i18n.Load() @@ -167,6 +178,7 @@ func main() { // IDE http.HandleFunc("/login", handlerWrapper(loginHandler)) + http.HandleFunc("/logout", handlerWrapper(logoutHandler)) http.HandleFunc("/", handlerWrapper(indexHandler)) // 静态资源 diff --git a/output/outputs.go b/output/outputs.go index ed30f81..bc2b3f6 100644 --- a/output/outputs.go +++ b/output/outputs.go @@ -179,7 +179,6 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { return } - // TODO: 会话校验 sid := args["sid"].(string) filePath := args["file"].(string) diff --git a/static/js/wide.js b/static/js/wide.js index d8d7929..7ede54c 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -400,7 +400,6 @@ var wide = { this.fmt(editors.getCurrentPath(), wide.curEditor); }, saveAllFiles: function () { - // TODO: 需要全部保存的接口 if ($(".menu li.save-all").hasClass("disabled")) { return false; } @@ -409,9 +408,6 @@ var wide = { this.fmt(tree.fileTree.getNodeByTId(editors.data[i].id).path, editors.data[i].editor); } }, - closeFile: function () { - // TODO: close file - }, closeAllFiles: function () { if ($(".menu li.close-all").hasClass("disabled")) { return false; @@ -427,7 +423,19 @@ var wide = { menu.disabled(['save-all', 'close-all', 'run', 'go-get', 'go-install']); }, exit: function () { - // TODO: exit + var request = newWideRequest(); + + $.ajax({ + type: 'POST', + url: '/logout', + data: JSON.stringify(request), + dataType: "json", + success: function (data) { + if (data.succ) { + window.location.href = "/login"; + } + } + }); }, stop: function () { if ($(".toolbars .ico-buildrun").length === 1) {