diff --git a/editor/editors.go b/editor/editors.go index ae06259..44599ea 100644 --- a/editor/editors.go +++ b/editor/editors.go @@ -3,7 +3,7 @@ package editor import ( "bytes" "encoding/json" - "github.com/b3log/wide/session" + "github.com/b3log/wide/user" "github.com/b3log/wide/util" "github.com/golang/glog" "github.com/gorilla/websocket" @@ -16,7 +16,7 @@ import ( var editorWS = map[string]*websocket.Conn{} func WSHandler(w http.ResponseWriter, r *http.Request) { - session, _ := session.Store.Get(r, "wide-session") + session, _ := user.Session.Get(r, "wide-session") sid := session.Values["id"].(string) editorWS[sid], _ = websocket.Upgrade(w, r, nil, 1024, 1024) diff --git a/file/files.go b/file/files.go index 2ab459a..383252e 100644 --- a/file/files.go +++ b/file/files.go @@ -3,7 +3,7 @@ package file import ( "encoding/json" "github.com/b3log/wide/conf" - "github.com/b3log/wide/session" + "github.com/b3log/wide/user" "github.com/golang/glog" "io/ioutil" "net/http" @@ -14,7 +14,7 @@ import ( ) func GetFiles(w http.ResponseWriter, r *http.Request) { - session, _ := session.Store.Get(r, "wide-session") + session, _ := user.Session.Get(r, "wide-session") username := session.Values["name"].(string) diff --git a/main.go b/main.go index 7293e4e..b4b32c0 100644 --- a/main.go +++ b/main.go @@ -6,8 +6,8 @@ import ( "github.com/b3log/wide/file" "github.com/b3log/wide/i18n" "github.com/b3log/wide/output" - "github.com/b3log/wide/session" "github.com/b3log/wide/shell" + "github.com/b3log/wide/user" "github.com/golang/glog" "html/template" "math/rand" @@ -18,7 +18,7 @@ import ( func indexHandler(w http.ResponseWriter, r *http.Request) { model := map[string]interface{}{"Wide": conf.Wide, "i18n": i18n.GetLangs(r)} - session, _ := session.Store.Get(r, "wide-session") + session, _ := user.Session.Get(r, "wide-session") if session.IsNew { // TODO: 以 daniel 作为用户登录 diff --git a/output/outputs.go b/output/outputs.go index 1f37fa9..a33b0c8 100644 --- a/output/outputs.go +++ b/output/outputs.go @@ -3,7 +3,7 @@ package output import ( "encoding/json" "github.com/b3log/wide/conf" - "github.com/b3log/wide/session" + "github.com/b3log/wide/user" "github.com/golang/glog" "github.com/gorilla/websocket" "io" @@ -18,7 +18,7 @@ import ( var outputWS = map[string]*websocket.Conn{} func WSHandler(w http.ResponseWriter, r *http.Request) { - session, _ := session.Store.Get(r, "wide-session") + session, _ := user.Session.Get(r, "wide-session") sid := session.Values["id"].(string) outputWS[sid], _ = websocket.Upgrade(w, r, nil, 1024, 1024) @@ -30,7 +30,7 @@ func WSHandler(w http.ResponseWriter, r *http.Request) { } func RunHandler(w http.ResponseWriter, r *http.Request) { - session, _ := session.Store.Get(r, "wide-session") + session, _ := user.Session.Get(r, "wide-session") sid := session.Values["id"].(string) decoder := json.NewDecoder(r.Body) @@ -105,7 +105,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) { } func BuildHandler(w http.ResponseWriter, r *http.Request) { - session, _ := session.Store.Get(r, "wide-session") + session, _ := user.Session.Get(r, "wide-session") sid := session.Values["id"].(string) decoder := json.NewDecoder(r.Body) diff --git a/session/sessions.go b/session/sessions.go deleted file mode 100644 index e2947d6..0000000 --- a/session/sessions.go +++ /dev/null @@ -1,7 +0,0 @@ -package session - -import ( - "github.com/gorilla/sessions" -) - -var Store = sessions.NewCookieStore([]byte("BEYOND")) diff --git a/shell/shells.go b/shell/shells.go index 649a3ad..3ef9fa5 100644 --- a/shell/shells.go +++ b/shell/shells.go @@ -2,7 +2,7 @@ package shell import ( "github.com/b3log/wide/conf" - "github.com/b3log/wide/session" + "github.com/b3log/wide/user" "github.com/golang/glog" "github.com/gorilla/websocket" "net/http" @@ -14,7 +14,7 @@ import ( var shellWS = map[string]*websocket.Conn{} func WSHandler(w http.ResponseWriter, r *http.Request) { - session, _ := session.Store.Get(r, "wide-session") + session, _ := user.Session.Get(r, "wide-session") sid := session.Values["id"].(string) shellWS[sid], _ = websocket.Upgrade(w, r, nil, 1024, 1024) diff --git a/user/sessions.go b/user/sessions.go new file mode 100644 index 0000000..8646955 --- /dev/null +++ b/user/sessions.go @@ -0,0 +1,7 @@ +package user + +import ( + "github.com/gorilla/sessions" +) + +var Session = sessions.NewCookieStore([]byte("BEYOND"))