This commit is contained in:
Liang Ding 2014-10-15 21:50:28 +08:00
parent 87d2f7a134
commit 71de834e60
3 changed files with 25 additions and 6 deletions

12
main.go
View File

@ -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))
// 静态资源

View File

@ -179,7 +179,6 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
return
}
// TODO: 会话校验
sid := args["sid"].(string)
filePath := args["file"].(string)

View File

@ -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) {