2021-02-15 10:05:14 +08:00
|
|
|
package object
|
|
|
|
|
|
|
|
import "github.com/casdoor/casdoor/util"
|
|
|
|
|
|
|
|
func InitDb() {
|
|
|
|
initBuiltInOrganization()
|
|
|
|
initBuiltInUser()
|
2021-02-15 10:32:14 +08:00
|
|
|
initBuiltInApplication()
|
2021-02-15 10:05:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func initBuiltInOrganization() {
|
|
|
|
organization := getOrganization("admin", "built-in")
|
|
|
|
if organization != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
organization = &Organization{
|
2021-05-05 23:32:21 +08:00
|
|
|
Owner: "admin",
|
|
|
|
Name: "built-in",
|
|
|
|
CreatedTime: util.GetCurrentTime(),
|
|
|
|
DisplayName: "Built-in Organization",
|
|
|
|
WebsiteUrl: "https://example.com",
|
|
|
|
PasswordType: "plain",
|
2021-02-15 10:05:14 +08:00
|
|
|
}
|
|
|
|
AddOrganization(organization)
|
|
|
|
}
|
|
|
|
|
|
|
|
func initBuiltInUser() {
|
|
|
|
user := getUser("built-in", "admin")
|
|
|
|
if user != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
user = &User{
|
2021-02-15 22:14:19 +08:00
|
|
|
Owner: "built-in",
|
|
|
|
Name: "admin",
|
|
|
|
CreatedTime: util.GetCurrentTime(),
|
|
|
|
Id: util.GenerateId(),
|
|
|
|
Password: "123",
|
|
|
|
DisplayName: "Admin",
|
|
|
|
Avatar: "https://casbin.org/img/casbin.svg",
|
|
|
|
Email: "admin@example.com",
|
|
|
|
Phone: "1-12345678",
|
|
|
|
Affiliation: "Example Inc.",
|
|
|
|
Tag: "staff",
|
|
|
|
IsAdmin: true,
|
|
|
|
IsGlobalAdmin: true,
|
2021-05-02 12:18:28 +08:00
|
|
|
IsForbidden: false,
|
2021-07-04 12:19:39 +08:00
|
|
|
Properties: make(map[string]string),
|
2021-02-15 10:05:14 +08:00
|
|
|
}
|
|
|
|
AddUser(user)
|
|
|
|
}
|
2021-02-15 10:32:14 +08:00
|
|
|
|
|
|
|
func initBuiltInApplication() {
|
|
|
|
application := getApplication("admin", "app-built-in")
|
|
|
|
if application != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
application = &Application{
|
|
|
|
Owner: "admin",
|
|
|
|
Name: "app-built-in",
|
|
|
|
CreatedTime: util.GetCurrentTime(),
|
|
|
|
DisplayName: "Casdoor",
|
2021-03-21 15:31:31 +08:00
|
|
|
Logo: "https://cdn.casbin.com/logo/logo_1024x256.png",
|
2021-05-28 22:38:12 +08:00
|
|
|
HomepageUrl: "https://casdoor.org",
|
2021-02-15 10:32:14 +08:00
|
|
|
Organization: "built-in",
|
|
|
|
EnablePassword: true,
|
2021-05-28 22:38:12 +08:00
|
|
|
EnableSignUp: true,
|
2021-06-14 21:35:19 +08:00
|
|
|
Providers: []*ProviderItem{},
|
2021-06-16 14:06:41 +08:00
|
|
|
SignupItems: []*SignupItem{},
|
2021-06-06 22:17:35 +08:00
|
|
|
RedirectUris: []string{},
|
2021-05-28 22:38:12 +08:00
|
|
|
ExpireInHours: 168,
|
2021-02-15 10:32:14 +08:00
|
|
|
}
|
|
|
|
AddApplication(application)
|
|
|
|
}
|