From 003354ffe4e645b746c2c23a1c8bf9074d6316ef Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 16 May 2019 23:37:04 +0800 Subject: [PATCH] :art: #347 --- conf/user.go | 2 +- conf/wide.go | 4 ++-- editor/formatter.go | 4 ++-- file/files.go | 4 ++-- output/build.go | 2 -- output/cross.go | 4 ---- playground/playgrounds.go | 2 +- session/oauthctl.go | 4 ++-- session/sessions.go | 10 +++++----- 9 files changed, 15 insertions(+), 21 deletions(-) diff --git a/conf/user.go b/conf/user.go index cdcf89e..947b516 100644 --- a/conf/user.go +++ b/conf/user.go @@ -76,7 +76,7 @@ type editor struct { TabSize string } -// Save saves the user's configurations in conf/users/{username}.json. +// Save saves the user's configurations in conf/users/{userId}.json. func (u *User) Save() bool { bytes, err := json.MarshalIndent(u, "", " ") diff --git a/conf/wide.go b/conf/wide.go index 88d33cd..491c928 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -92,7 +92,7 @@ var Docker bool // Docker image to run user's program const DockerImageGo = "golang" -// Load loads the Wide configurations from wide.json and users' configurations from users/{username}.json. +// Load loads the Wide configurations from wide.json and users' configurations from users/{userId}.json. func Load(confPath, confUsers, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, confPlayground string, confUsersWorkspaces string) { initWide(confPath, confUsers, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, confPlayground, confUsersWorkspaces) initUsers() @@ -391,7 +391,7 @@ func initCustomizedConfs() { // UpdateCustomizedConf creates (if not exists) or updates user customized configuration files. // -// 1. /static/user/{username}/style.css +// 1. /static/user/{userId}/style.css func UpdateCustomizedConf(userId string) { var u *User for _, user := range Users { // maybe it is a beauty of the trade-off of the another world between design and implementation diff --git a/editor/formatter.go b/editor/formatter.go index bbd1afa..621f9ab 100644 --- a/editor/formatter.go +++ b/editor/formatter.go @@ -40,7 +40,7 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) { return } - username := session.Values["username"].(string) + uid := session.Values["uid"].(string) var args map[string]interface{} @@ -85,7 +85,7 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) { result.Data = data - fmt := conf.GetGoFmt(username) + fmt := conf.GetGoFmt(uid) argv := []string{filePath} cmd := exec.Command(fmt, argv...) diff --git a/file/files.go b/file/files.go index 06b5c5c..678ed36 100644 --- a/file/files.go +++ b/file/files.go @@ -204,8 +204,8 @@ func GetFileHandler(w http.ResponseWriter, r *http.Request) { data["mode"] = "img" - username := conf.GetOwner(path) - if "" == username { + userId := conf.GetOwner(path) + if "" == userId { logger.Warnf("The path [%s] has no owner", path) data["path"] = "" diff --git a/output/build.go b/output/build.go index 442f20f..0125bcd 100644 --- a/output/build.go +++ b/output/build.go @@ -155,8 +155,6 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { return } - // logger.Debugf("User [%s, %s] is building [id=%d, dir=%s]", username, sid, runningId, curDir) - channelRet["cmd"] = "build" channelRet["executable"] = executable diff --git a/output/cross.go b/output/cross.go index 1db55b9..3f026fc 100644 --- a/output/cross.go +++ b/output/cross.go @@ -155,8 +155,6 @@ func CrossCompilationHandler(w http.ResponseWriter, r *http.Request) { defer util.Recover() defer cmd.Wait() - // logger.Debugf("User [%s, %s] is building [id=%d, dir=%s]", username, sid, runningId, curDir) - // read all buf, _ := ioutil.ReadAll(reader) @@ -235,8 +233,6 @@ func CrossCompilationHandler(w http.ResponseWriter, r *http.Request) { } if nil != session.OutputWS[sid] { - // logger.Debugf("User [%s, %s] 's build [id=%d, dir=%s] has done", username, sid, runningId, curDir) - wsChannel := session.OutputWS[sid] err := wsChannel.WriteJSON(&channelRet) if nil != err { diff --git a/playground/playgrounds.go b/playground/playgrounds.go index 515ae4f..c1abad3 100644 --- a/playground/playgrounds.go +++ b/playground/playgrounds.go @@ -43,7 +43,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { httpSession, _ := session.HTTPSession.Get(r, "wide-session") if httpSession.IsNew { httpSession.Values["id"] = strconv.Itoa(rand.Int()) - httpSession.Values["username"] = "playground" + httpSession.Values["uid"] = "playground" } httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge diff --git a/session/oauthctl.go b/session/oauthctl.go index 9c43500..887057a 100644 --- a/session/oauthctl.go +++ b/session/oauthctl.go @@ -111,7 +111,7 @@ func GithubCallbackHandler(w http.ResponseWriter, r *http.Request) { // create a HTTP session httpSession, _ := HTTPSession.Get(r, "wide-session") - httpSession.Values["username"] = userName + httpSession.Values["uid"] = githubId httpSession.Values["id"] = strconv.Itoa(rand.Int()) httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge @@ -120,7 +120,7 @@ func GithubCallbackHandler(w http.ResponseWriter, r *http.Request) { } httpSession.Save(r, w) - logger.Debugf("Created a HTTP session [%s] for user [%s]", httpSession.Values["id"].(string), userName) + logger.Debugf("Created a HTTP session [%s] for user [%s]", httpSession.Values["id"].(string), githubId) } // GitHubUserInfo returns GitHub user info specified by the given access token. diff --git a/session/sessions.go b/session/sessions.go index 1813d05..4eb2f6f 100644 --- a/session/sessions.go +++ b/session/sessions.go @@ -122,7 +122,7 @@ func FixedTimeRelease() { // Online user statistic report. type userReport struct { - username string + userId string sessionCnt int processCnt int updated time.Time @@ -130,7 +130,7 @@ type userReport struct { // report returns a online user statistics in pretty format. func (u *userReport) report() string { - return "[" + u.username + "] has [" + strconv.Itoa(u.sessionCnt) + "] sessions and [" + strconv.Itoa(u.processCnt) + + return "[" + u.userId + "] has [" + strconv.Itoa(u.sessionCnt) + "] sessions and [" + strconv.Itoa(u.processCnt) + "] running processes, latest activity [" + u.updated.Format("2006-01-02 15:04:05") + "]" } @@ -155,7 +155,7 @@ func FixedTimeReport() { report.sessionCnt++ report.processCnt += processCnt } else { - users = append(users, &userReport{username: s.UserId, sessionCnt: 1, processCnt: processCnt, updated: s.Updated}) + users = append(users, &userReport{userId: s.UserId, sessionCnt: 1, processCnt: processCnt, updated: s.Updated}) } } @@ -174,9 +174,9 @@ func FixedTimeReport() { }() } -func contains(reports []*userReport, username string) (*userReport, bool) { +func contains(reports []*userReport, userId string) (*userReport, bool) { for _, ur := range reports { - if username == ur.username { + if userId == ur.userId { return ur, true } }