mirror of
				https://github.com/filebrowser/filebrowser.git
				synced 2025-11-04 11:23:02 +00:00 
			
		
		
		
	close #195
Former-commit-id: 2491dc59e82845c50ece7d7b0753dce2b0484e3f [formerly 57ded9ff433cedf0011fedbbd6a1c8963103d9a7] [formerly 70bad58f0dc863e1885fb486d9c02be8a6e3ca43 [formerly e533a3aa6eca1627b08080c28be9e3f73cfe6e8e]] Former-commit-id: 2481eaceaba80955dea0552aacdef58937069edb [formerly b4890a9b2147c7410706604563188f1d3b1e8b56] Former-commit-id: 7354ce9185a8e63fb5993246ea0f357f2aa6d358
This commit is contained in:
		
							parent
							
								
									3ff8908047
								
							
						
					
					
						commit
						aaf6d60c3c
					
				
							
								
								
									
										35
									
								
								users.go
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								users.go
									
									
									
									
									
								
							@ -4,6 +4,7 @@ import (
 | 
				
			|||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
	"sort"
 | 
						"sort"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
@ -175,6 +176,11 @@ func usersPostHandler(c *RequestContext, w http.ResponseWriter, r *http.Request)
 | 
				
			|||||||
		u.ID = 0
 | 
							u.ID = 0
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Checks if the scope exists.
 | 
				
			||||||
 | 
						if code, err := checkFS(string(u.FileSystem)); err != nil {
 | 
				
			||||||
 | 
							return code, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Hashes the password.
 | 
						// Hashes the password.
 | 
				
			||||||
	pw, err := hashPassword(u.Password)
 | 
						pw, err := hashPassword(u.Password)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@ -202,6 +208,28 @@ func usersPostHandler(c *RequestContext, w http.ResponseWriter, r *http.Request)
 | 
				
			|||||||
	return 0, nil
 | 
						return 0, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func checkFS(path string) (int, error) {
 | 
				
			||||||
 | 
						info, err := os.Stat(path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							if !os.IsNotExist(err) {
 | 
				
			||||||
 | 
								return http.StatusInternalServerError, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							err = os.MkdirAll(path, 0666)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return http.StatusInternalServerError, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !info.IsDir() {
 | 
				
			||||||
 | 
							return http.StatusBadRequest, errors.New("Scope is not a dir")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func usersDeleteHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) {
 | 
					func usersDeleteHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) {
 | 
				
			||||||
	if r.URL.Path == "/" {
 | 
						if r.URL.Path == "/" {
 | 
				
			||||||
		return http.StatusMethodNotAllowed, nil
 | 
							return http.StatusMethodNotAllowed, nil
 | 
				
			||||||
@ -308,6 +336,11 @@ func usersPutHandler(c *RequestContext, w http.ResponseWriter, r *http.Request)
 | 
				
			|||||||
		return http.StatusBadRequest, errEmptyScope
 | 
							return http.StatusBadRequest, errEmptyScope
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Checks if the scope exists.
 | 
				
			||||||
 | 
						if code, err := checkFS(string(u.FileSystem)); err != nil {
 | 
				
			||||||
 | 
							return code, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Initialize rules if they're not initialized.
 | 
						// Initialize rules if they're not initialized.
 | 
				
			||||||
	if u.Rules == nil {
 | 
						if u.Rules == nil {
 | 
				
			||||||
		u.Rules = []*Rule{}
 | 
							u.Rules = []*Rule{}
 | 
				
			||||||
@ -344,8 +377,6 @@ func usersPutHandler(c *RequestContext, w http.ResponseWriter, r *http.Request)
 | 
				
			|||||||
		u.Password = suser.Password
 | 
							u.Password = suser.Password
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Updates the whole User struct because we always are supposed
 | 
						// Updates the whole User struct because we always are supposed
 | 
				
			||||||
	// to send a new entire object.
 | 
						// to send a new entire object.
 | 
				
			||||||
	err = c.db.Save(u)
 | 
						err = c.db.Save(u)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user