2021-08-18 20:18:39 +02:00
|
|
|
package form
|
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
import (
|
|
|
|
"github.com/urfave/cli"
|
2021-11-12 09:10:15 +01:00
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/clean"
|
|
|
|
)
|
|
|
|
|
2022-10-15 21:54:11 +02:00
|
|
|
// User represents a user account form.
|
2022-09-28 09:01:17 +02:00
|
|
|
type User struct {
|
2022-10-19 05:09:09 +02:00
|
|
|
UserName string `json:"Name,omitempty" yaml:"Name,omitempty"`
|
|
|
|
UserEmail string `json:"Email,omitempty" yaml:"Email,omitempty"`
|
|
|
|
DisplayName string `json:"DisplayName,omitempty" yaml:"DisplayName,omitempty"`
|
|
|
|
UserRole string `json:"Role,omitempty" yaml:"Role,omitempty"`
|
|
|
|
SuperAdmin bool `json:"SuperAdmin,omitempty" yaml:"SuperAdmin,omitempty"`
|
|
|
|
CanLogin bool `json:"CanLogin,omitempty" yaml:"CanLogin,omitempty"`
|
|
|
|
WebDAV bool `json:"WebDAV,omitempty" yaml:"WebDAV,omitempty"`
|
|
|
|
UserAttr string `json:"Attr,omitempty" yaml:"Attr,omitempty"`
|
|
|
|
BasePath string `json:"BasePath,omitempty" yaml:"BasePath,omitempty"`
|
|
|
|
UploadPath string `json:"UploadPath,omitempty" yaml:"UploadPath,omitempty"`
|
|
|
|
Password string `json:"Password,omitempty" yaml:"Password,omitempty"`
|
|
|
|
UserDetails *UserDetails `json:"Details,omitempty"`
|
2022-09-28 09:01:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewUserFromCli creates a new form with values from a CLI context.
|
|
|
|
func NewUserFromCli(ctx *cli.Context) User {
|
|
|
|
return User{
|
|
|
|
UserName: clean.Username(ctx.Args().First()),
|
|
|
|
UserEmail: clean.Email(ctx.String("email")),
|
2022-09-30 00:42:19 +02:00
|
|
|
DisplayName: clean.Name(ctx.String("name")),
|
2022-09-28 09:01:17 +02:00
|
|
|
UserRole: clean.Role(ctx.String("role")),
|
|
|
|
SuperAdmin: ctx.Bool("superadmin"),
|
2022-09-30 00:42:19 +02:00
|
|
|
CanLogin: !ctx.Bool("no-login"),
|
2022-10-13 22:11:02 +02:00
|
|
|
WebDAV: ctx.Bool("webdav"),
|
2022-09-30 00:42:19 +02:00
|
|
|
UserAttr: clean.Attr(ctx.String("attr")),
|
2022-10-27 15:47:32 +02:00
|
|
|
BasePath: clean.UserPath(ctx.String("base-path")),
|
|
|
|
UploadPath: clean.UserPath(ctx.String("upload-path")),
|
2022-09-28 09:01:17 +02:00
|
|
|
Password: clean.Password(ctx.String("password")),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name returns the sanitized username in lowercase.
|
|
|
|
func (f *User) Name() string {
|
|
|
|
return clean.Username(f.UserName)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Email returns the sanitized email in lowercase.
|
|
|
|
func (f *User) Email() string {
|
|
|
|
return clean.Email(f.UserEmail)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Role returns the sanitized user role string.
|
|
|
|
func (f *User) Role() string {
|
|
|
|
return clean.Role(f.UserRole)
|
2021-08-18 20:18:39 +02:00
|
|
|
}
|
2021-11-12 09:10:15 +01:00
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
// Attr returns the sanitized user account attributes.
|
|
|
|
func (f *User) Attr() string {
|
|
|
|
return clean.Attr(f.UserAttr)
|
2021-11-12 09:10:15 +01:00
|
|
|
}
|