diff --git a/.gitignore b/.gitignore index ee72ef4..428dce9 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ /**/.DS_Store /node_modules -/nbproject \ No newline at end of file +/nbproject +/workspaces \ No newline at end of file diff --git a/conf/wide.go b/conf/wide.go index 8df1fdb..b03b231 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -69,6 +69,7 @@ type conf struct { WD string // current working direcitory, ${pwd} Locale string // default locale Playground string // playground directory + UsersWorkspaces string // users' workspaces directory (admin defaults to ${GOPATH}, others using this) AllowRegister bool // allow register or not Autocomplete bool // default autocomplete } @@ -87,11 +88,11 @@ var Docker bool // Load loads the Wide configurations from wide.json and users' configurations from users/{username}.json. func Load(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, - confPlayground string, confDocker bool) { + confPlayground string, confDocker bool, confUsersWorkspaces string) { // XXX: ugly args list.... initWide(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, - confPlayground, confDocker) + confPlayground, confDocker, confUsersWorkspaces) initUsers() } @@ -144,7 +145,7 @@ func initUsers() { } func initWide(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, - confPlayground string, confDocker bool) { + confPlayground string, confDocker bool, confUsersWorkspaces string) { bytes, err := ioutil.ReadFile(confPath) if nil != err { logger.Error(err) @@ -190,6 +191,16 @@ func initWide(confPath, confIP, confPort, confServer, confLogLevel, confStaticSe Wide.Playground = confPlayground } + // Users' workspaces Directory + logger.Debug(Wide.UsersWorkspaces) + + Wide.UsersWorkspaces = strings.Replace(Wide.UsersWorkspaces, "${WD}", Wide.WD, 1) + Wide.UsersWorkspaces = strings.Replace(Wide.UsersWorkspaces, "${home}", home, 1) + if "" != confUsersWorkspaces { + Wide.UsersWorkspaces = confUsersWorkspaces + } + Wide.UsersWorkspaces = filepath.Clean(Wide.UsersWorkspaces) + if !util.File.IsExist(Wide.Playground) { if err := os.Mkdir(Wide.Playground, 0775); nil != err { logger.Errorf("Create Playground [%s] error", err) diff --git a/conf/wide.json b/conf/wide.json index 7d3741a..f8d8803 100644 --- a/conf/wide.json +++ b/conf/wide.json @@ -13,6 +13,7 @@ "WD": "${pwd}", "Locale": "en_US", "Playground": "${home}/playground", + "UsersWorkspaces": "${WD}/workspaces", "AllowRegister": true, "Autocomplete": true } \ No newline at end of file diff --git a/main.go b/main.go index abf3e0e..9cd8a86 100644 --- a/main.go +++ b/main.go @@ -57,6 +57,7 @@ func init() { confStat := flag.Bool("stat", false, "whether report statistics periodically") confDocker := flag.Bool("docker", false, "whether run in a docker container") confPlayground := flag.String("playground", "", "this will overwrite Wide.Playground if specified") + confUsersWorkspaces := flag.String("users_workspaces", "", "this will overwrite Wide.UsersWorkspaces if specified") flag.Parse() @@ -75,7 +76,7 @@ func init() { event.Load() conf.Load(*confPath, *confIP, *confPort, *confServer, *confLogLevel, *confStaticServer, *confContext, *confChannel, - *confPlayground, *confDocker) + *confPlayground, *confDocker, *confUsersWorkspaces) conf.FixedTimeCheckEnv() diff --git a/session/users.go b/session/users.go index 54f58d4..d9cf7ba 100644 --- a/session/users.go +++ b/session/users.go @@ -224,11 +224,8 @@ func SignUpUserHandler(w http.ResponseWriter, r *http.Request) { if "GET" == r.Method { // show the user sign up page - firstUserWorkspace := conf.GetUserWorkspace(conf.Users[0].Name) - dir := filepath.Dir(firstUserWorkspace) - model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(conf.Wide.Locale), - "locale": conf.Wide.Locale, "ver": conf.WideVersion, "dir": dir, + "locale": conf.Wide.Locale, "ver": conf.WideVersion, "dir": conf.Wide.UsersWorkspaces, "pathSeparator": conf.PathSeparator, "year": time.Now().Year()} t, err := template.ParseFiles("views/sign_up.html") @@ -374,9 +371,7 @@ func addUser(username, password, email string) string { } } - firstUserWorkspace := conf.GetUserWorkspace(conf.Users[0].Name) - dir := filepath.Dir(firstUserWorkspace) - workspace := filepath.Join(dir, username) + workspace := filepath.Join(conf.Wide.UsersWorkspaces, username) newUser := conf.NewUser(username, password, email, workspace) conf.Users = append(conf.Users, newUser)