2022-09-02 21:30:50 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/photoprism/photoprism/internal/acl"
|
|
|
|
"github.com/photoprism/photoprism/pkg/rnd"
|
|
|
|
)
|
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
// Role defaults.
|
|
|
|
const (
|
|
|
|
AdminUserName = "admin"
|
|
|
|
AdminDisplayName = "Admin"
|
|
|
|
GuestDisplayName = "Visitor"
|
|
|
|
)
|
2022-09-02 21:30:50 +02:00
|
|
|
|
|
|
|
// Admin is the default admin user.
|
|
|
|
var Admin = User{
|
|
|
|
ID: 1,
|
2022-09-28 09:01:17 +02:00
|
|
|
UserName: AdminUserName,
|
2022-09-02 21:30:50 +02:00
|
|
|
UserRole: acl.RoleAdmin.String(),
|
2022-09-02 22:55:57 +02:00
|
|
|
DisplayName: AdminDisplayName,
|
2022-09-02 21:30:50 +02:00
|
|
|
SuperAdmin: true,
|
|
|
|
CanLogin: true,
|
2022-09-28 09:01:17 +02:00
|
|
|
CanSync: true,
|
2022-09-02 21:30:50 +02:00
|
|
|
CanInvite: true,
|
|
|
|
InviteToken: rnd.GenerateToken(8),
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnknownUser is an anonymous, public user without own account.
|
|
|
|
var UnknownUser = User{
|
|
|
|
ID: -1,
|
|
|
|
UserUID: "u000000000000001",
|
2022-09-28 09:01:17 +02:00
|
|
|
UserRole: acl.RoleUnauthorized.String(),
|
|
|
|
UserName: "",
|
2022-09-02 22:55:57 +02:00
|
|
|
DisplayName: "",
|
2022-09-02 21:30:50 +02:00
|
|
|
SuperAdmin: false,
|
|
|
|
CanLogin: false,
|
2022-09-28 09:01:17 +02:00
|
|
|
CanSync: false,
|
2022-09-02 21:30:50 +02:00
|
|
|
CanInvite: false,
|
|
|
|
InviteToken: "",
|
|
|
|
}
|
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
// Visitor is a user without own account e.g. for link sharing.
|
|
|
|
var Visitor = User{
|
2022-09-02 21:30:50 +02:00
|
|
|
ID: -2,
|
|
|
|
UserUID: "u000000000000002",
|
2022-09-28 09:01:17 +02:00
|
|
|
UserRole: acl.RoleVisitor.String(),
|
|
|
|
UserName: "",
|
2022-09-02 22:55:57 +02:00
|
|
|
DisplayName: GuestDisplayName,
|
2022-09-02 21:30:50 +02:00
|
|
|
SuperAdmin: false,
|
|
|
|
CanLogin: false,
|
2022-09-28 09:01:17 +02:00
|
|
|
CanSync: false,
|
2022-09-02 21:30:50 +02:00
|
|
|
CanInvite: false,
|
|
|
|
InviteToken: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateDefaultUsers initializes the database with default user accounts.
|
|
|
|
func CreateDefaultUsers() {
|
|
|
|
if user := FirstOrCreateUser(&Admin); user != nil {
|
|
|
|
Admin = *user
|
|
|
|
}
|
|
|
|
|
|
|
|
if user := FirstOrCreateUser(&UnknownUser); user != nil {
|
|
|
|
UnknownUser = *user
|
|
|
|
}
|
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
if user := FirstOrCreateUser(&Visitor); user != nil {
|
|
|
|
Visitor = *user
|
2022-09-02 21:30:50 +02:00
|
|
|
}
|
|
|
|
}
|