diff --git a/assets/src/views/Files.vue b/assets/src/views/Files.vue index d72bafce..10a2fa05 100644 --- a/assets/src/views/Files.vue +++ b/assets/src/views/Files.vue @@ -1,231 +1,231 @@ - - - + + + diff --git a/assets/src/views/settings/User.vue b/assets/src/views/settings/User.vue index a877a7f0..6619e17b 100644 --- a/assets/src/views/settings/User.vue +++ b/assets/src/views/settings/User.vue @@ -7,10 +7,21 @@
+

+ + +

+ +

+ + +

+ +

+ + +

-

-

-

@@ -91,6 +102,7 @@ export default { components: { Languages }, data: () => { return { + originalUser: null, id: 0, admin: false, allowNew: false, @@ -141,6 +153,7 @@ export default { } getUser(user).then(user => { + this.originalUser = user this.id = user.ID this.admin = user.admin this.allowCommands = user.allowCommands @@ -242,23 +255,21 @@ export default { }) }, parseForm () { - let user = { - ID: this.id, - username: this.username, - password: this.password, - lockPassword: this.lockPassword, - filesystem: this.filesystem, - admin: this.admin, - allowCommands: this.allowCommands, - allowNew: this.allowNew, - allowEdit: this.allowEdit, - allowPublish: this.allowPublish, - permissions: this.permissions, - css: this.css, - locale: this.locale, - commands: this.commands.split(' '), - rules: [] - } + let user = this.originalUser + user.username = this.username + user.password = this.password + user.lockPassword = this.lockPassword + user.filesystem = this.filesystem + user.admin = this.admin + user.allowCommands = this.allowCommands + user.allowNew = this.allowNew + user.allowEdit = this.allowEdit + user.allowPublish = this.allowPublish + user.permissions = this.permissions + user.css = this.css + user.locale = this.locale + user.commands = this.commands.split(' ') + user.rules = [] let rules = this.rules.split('\n') diff --git a/filemanager.go b/filemanager.go index 57149d03..a743a618 100644 --- a/filemanager.go +++ b/filemanager.go @@ -39,7 +39,7 @@ var ( ErrEmptyScope = errors.New("scope is empty") ErrWrongDataType = errors.New("wrong data type") ErrInvalidUpdateField = errors.New("invalid field to update") - ErrInvalidOption = errors.New("Invalid option") + ErrInvalidOption = errors.New("invalid option") ) // FileManager is a file manager instance. It should be creating using the diff --git a/http/auth.go b/http/auth.go index 03ec09f3..360ceed4 100644 --- a/http/auth.go +++ b/http/auth.go @@ -1,7 +1,6 @@ package http import ( - "bytes" "encoding/json" "fmt" "net/http" @@ -14,22 +13,23 @@ import ( fm "github.com/hacdias/filemanager" ) +const reCaptchaAPI = "https://www.google.com/recaptcha/api/siteverify" + type cred struct { Password string `json:"password"` Username string `json:"username"` - Recaptcha string `json:"recaptcha"` + ReCaptcha string `json:"recaptcha"` } -// recaptcha checks the recaptcha code. -func recaptcha(secret string, response string) (bool, error) { - api := "https://www.google.com/recaptcha/api/siteverify" - +// reCaptcha checks the reCaptcha code. +func reCaptcha(secret string, response string) (bool, error) { body := url.Values{} body.Set("secret", secret) body.Add("response", response) client := &http.Client{} - resp, err := client.Post(api, "application/x-www-form-urlencoded", bytes.NewBufferString(body.Encode())) + + resp, err := client.Post(reCaptchaAPI, "application/x-www-form-urlencoded", strings.NewReader(body.Encode())) if err != nil { return false, err } @@ -73,7 +73,7 @@ func authHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, er // If ReCaptcha is enabled, check the code. if len(c.ReCaptchaSecret) > 0 { - ok, err := recaptcha(c.ReCaptchaSecret, cred.Recaptcha) + ok, err := reCaptcha(c.ReCaptchaSecret, cred.ReCaptcha) if err != nil { fmt.Println(err) return http.StatusForbidden, err @@ -179,6 +179,7 @@ func validateAuth(c *fm.Context, r *http.Request) (bool, *fm.User) { keyFunc := func(token *jwt.Token) (interface{}, error) { return c.Key, nil } + var claims claims token, err := request.ParseFromRequestWithClaims(r, extractor{}, diff --git a/http/download.go b/http/download.go index 0fe696b7..556427e3 100644 --- a/http/download.go +++ b/http/download.go @@ -17,21 +17,13 @@ import ( // downloadHandler creates an archive in one of the supported formats (zip, tar, // tar.gz or tar.bz2) and sends it to be downloaded. func downloadHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { - query := r.URL.Query().Get("format") - // If the file isn't a directory, serve it using http.ServeFile. We display it // inline if it is requested. if !c.File.IsDir { - if r.URL.Query().Get("inline") == "true" { - w.Header().Set("Content-Disposition", "inline") - } else { - w.Header().Set("Content-Disposition", "attachment; filename=\""+c.File.Name+"\"") - } - - http.ServeFile(w, r, c.File.Path) - return 0, nil + return downloadFileHandler(c, w, r) } + query := r.URL.Query().Get("format") files := []string{} names := strings.Split(r.URL.Query().Get("files"), ",") @@ -111,3 +103,14 @@ func downloadHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int _, err = io.Copy(w, file) return 0, err } + +func downloadFileHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { + if r.URL.Query().Get("inline") == "true" { + w.Header().Set("Content-Disposition", "inline") + } else { + w.Header().Set("Content-Disposition", "attachment; filename=\""+c.File.Name+"\"") + } + + http.ServeFile(w, r, c.File.Path) + return 0, nil +} diff --git a/http/users.go b/http/users.go index 9846217e..9e6601ca 100644 --- a/http/users.go +++ b/http/users.go @@ -160,6 +160,11 @@ func usersPostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (in u.Rules = []*fm.Rule{} } + // If the view mode is empty, initialize with the default one. + if u.ViewMode == "" { + u.ViewMode = c.DefaultUser.ViewMode + } + // Initialize commands if not initialized. if u.Commands == nil { u.Commands = []string{} diff --git a/rice-box.go.REMOVED.git-id b/rice-box.go.REMOVED.git-id deleted file mode 100644 index 7355137c..00000000 --- a/rice-box.go.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -9536ea589ebfb34b4ccbf549776ff8b4c70d6dd6 \ No newline at end of file