Docs updates and default user updates
Former-commit-id: 9298fb352e71134edd6fbe2dfa171b1d9dcc4d22 [formerly c51c50f2a03869be18eec2f4d5af408902f26b6b] [formerly deff3d3ecc5912dba5f34ff02813a908e5866558 [formerly 0fc290f032
]]
Former-commit-id: c21c8881b03846d2ab689fd34c13a0b9a8ba3902 [formerly 4a390dde126112e9969774173c15b28e6ce6d98c]
Former-commit-id: de457e083b6197077641ca38c28a0446c3097963
pull/726/head
parent
885f11d324
commit
5a14eaaee0
|
@ -126,8 +126,6 @@ func parse(c *caddy.Controller) ([]*config, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fm, err := New(database, User{
|
fm, err := New(database, User{
|
||||||
Username: "admin",
|
|
||||||
Password: "admin",
|
|
||||||
AllowCommands: true,
|
AllowCommands: true,
|
||||||
AllowEdit: true,
|
AllowEdit: true,
|
||||||
AllowNew: true,
|
AllowNew: true,
|
||||||
|
|
|
@ -101,8 +101,6 @@ func parse(c *caddy.Controller) ([]*filemanager.FileManager, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := filemanager.New(database, filemanager.User{
|
m, err := filemanager.New(database, filemanager.User{
|
||||||
Username: "admin",
|
|
||||||
Password: "admin",
|
|
||||||
AllowCommands: true,
|
AllowCommands: true,
|
||||||
AllowEdit: true,
|
AllowEdit: true,
|
||||||
AllowNew: true,
|
AllowNew: true,
|
||||||
|
|
19
doc.go
19
doc.go
|
@ -6,7 +6,24 @@ you'll need to create a filemanager instance:
|
||||||
m, err := filemanager.New(database, user)
|
m, err := filemanager.New(database, user)
|
||||||
|
|
||||||
Where 'user' contains the default options for new users. You can just
|
Where 'user' contains the default options for new users. You can just
|
||||||
use 'filemanager.DefaultUser'
|
use 'filemanager.DefaultUser' or create yourself a default user:
|
||||||
|
|
||||||
|
m, err := filemanager.New(database, filemanager.User{
|
||||||
|
Admin: false,
|
||||||
|
AllowCommands: false,
|
||||||
|
AllowEdit: true,
|
||||||
|
AllowNew: true,
|
||||||
|
Commands: []string{
|
||||||
|
"git",
|
||||||
|
},
|
||||||
|
Rules: []*filemanager.Rule{},
|
||||||
|
CSS: "",
|
||||||
|
FileSystem: webdav.Dir("/path/to/files"),
|
||||||
|
})
|
||||||
|
|
||||||
|
The credentials for the first user are always 'admin' for both the user and
|
||||||
|
the password, and they can be changed later through the settings. The first
|
||||||
|
user is always an Admin and has all of the permissions set to 'true'.
|
||||||
|
|
||||||
Then, you should set the Prefix URL and the Base URL, using the following
|
Then, you should set the Prefix URL and the Base URL, using the following
|
||||||
functions:
|
functions:
|
||||||
|
|
|
@ -127,8 +127,6 @@ type Plugin interface {
|
||||||
|
|
||||||
// DefaultUser is used on New, when no 'base' user is provided.
|
// DefaultUser is used on New, when no 'base' user is provided.
|
||||||
var DefaultUser = User{
|
var DefaultUser = User{
|
||||||
Username: "admin",
|
|
||||||
Password: "admin",
|
|
||||||
AllowCommands: true,
|
AllowCommands: true,
|
||||||
AllowEdit: true,
|
AllowEdit: true,
|
||||||
AllowNew: true,
|
AllowNew: true,
|
||||||
|
@ -203,32 +201,34 @@ func New(database string, base User) (*FileManager, error) {
|
||||||
// If there are no users in the database, it creates a new one
|
// If there are no users in the database, it creates a new one
|
||||||
// based on 'base' User that must be provided by the function caller.
|
// based on 'base' User that must be provided by the function caller.
|
||||||
if len(users) == 0 {
|
if len(users) == 0 {
|
||||||
|
u := base
|
||||||
|
u.Username = "admin"
|
||||||
|
|
||||||
// Hashes the password.
|
// Hashes the password.
|
||||||
pw, err := hashPassword(base.Password)
|
u.Password, err = hashPassword("admin")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// The first user must be an administrator.
|
// The first user must be an administrator.
|
||||||
base.Admin = true
|
u.Admin = true
|
||||||
base.Password = pw
|
u.AllowCommands = true
|
||||||
|
u.AllowNew = true
|
||||||
|
u.AllowEdit = true
|
||||||
|
|
||||||
// Saves the user to the database.
|
// Saves the user to the database.
|
||||||
if err := db.Save(&base); err != nil {
|
if err := db.Save(&u); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Users[base.Username] = &base
|
m.Users[u.Username] = &u
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attaches db to this File Manager instance.
|
// Attaches db to this File Manager instance.
|
||||||
m.db = db
|
m.db = db
|
||||||
|
|
||||||
// Create the default user, making a copy of the base.
|
// Create the default user, making a copy of the base.
|
||||||
u := base
|
m.DefaultUser = &base
|
||||||
u.Username = ""
|
|
||||||
u.Password = ""
|
|
||||||
m.DefaultUser = &u
|
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue