photoprism/internal/entity/auth_user_cli.go
Michael Mayer 884dea17de Security: Use individual preview tokens for each user account #98
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-10-13 22:11:02 +02:00

60 lines
1.1 KiB
Go

package entity
import (
"github.com/photoprism/photoprism/pkg/clean"
"github.com/urfave/cli"
"github.com/photoprism/photoprism/internal/form"
)
// SetValuesFromCli updates the entity values from a CLI context and validates them.
func (m *User) SetValuesFromCli(ctx *cli.Context) error {
frm := form.NewUserFromCli(ctx)
// Email address.
if ctx.IsSet("email") {
m.UserEmail = frm.Email()
}
// Display name.
if ctx.IsSet("name") {
m.DisplayName = clean.Name(frm.DisplayName)
}
// User role.
if ctx.IsSet("role") {
m.UserRole = frm.Role()
}
// Super-admin status.
if ctx.IsSet("superadmin") {
m.SuperAdmin = frm.SuperAdmin
}
// Disable login (Web UI)?
if ctx.IsSet("no-login") {
m.CanLogin = frm.CanLogin
}
// Allow the use of WebDAV?
if ctx.IsSet("webdav") {
m.WebDAV = frm.WebDAV
}
// Set custom attributes?
if ctx.IsSet("attr") {
m.UserAttr = frm.Attr()
}
// Originals base folder.
if ctx.IsSet("base-path") {
m.SetBasePath(frm.BasePath)
}
// Sub-folder for uploads.
if ctx.IsSet("upload-path") {
m.SetUploadPath(frm.UploadPath)
}
return m.Validate()
}