mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 04:10:20 +08:00
Add InitDb().
This commit is contained in:
1
main.go
1
main.go
@ -26,6 +26,7 @@ import (
|
||||
|
||||
func main() {
|
||||
object.InitAdapter()
|
||||
object.InitDb()
|
||||
controllers.InitHttpClient()
|
||||
|
||||
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
|
||||
|
49
object/init.go
Normal file
49
object/init.go
Normal file
@ -0,0 +1,49 @@
|
||||
package object
|
||||
|
||||
import "github.com/casdoor/casdoor/util"
|
||||
|
||||
func InitDb() {
|
||||
initBuiltInOrganization()
|
||||
initBuiltInUser()
|
||||
}
|
||||
|
||||
func initBuiltInOrganization() {
|
||||
organization := getOrganization("admin", "built-in")
|
||||
if organization != nil {
|
||||
return
|
||||
}
|
||||
|
||||
organization = &Organization{
|
||||
Owner: "admin",
|
||||
Name: "built-in",
|
||||
CreatedTime: util.GetCurrentTime(),
|
||||
DisplayName: "Built-in Organization",
|
||||
WebsiteUrl: "https://example.com",
|
||||
}
|
||||
AddOrganization(organization)
|
||||
}
|
||||
|
||||
func initBuiltInUser() {
|
||||
user := getUser("built-in", "admin")
|
||||
if user != nil {
|
||||
return
|
||||
}
|
||||
|
||||
user = &User{
|
||||
Owner: "built-in",
|
||||
Name: "admin",
|
||||
CreatedTime: util.GetCurrentTime(),
|
||||
Id: util.GenerateId(),
|
||||
Password: "123",
|
||||
PasswordType: "plain",
|
||||
DisplayName: "Admin",
|
||||
Avatar: "https://casbin.org/img/casbin.svg",
|
||||
Email: "admin@example.com",
|
||||
Phone: "1-12345678",
|
||||
Affiliation: "Example Inc.",
|
||||
Tag: "staff",
|
||||
IsAdmin: true,
|
||||
Github: "",
|
||||
}
|
||||
AddUser(user)
|
||||
}
|
@ -46,12 +46,15 @@ class UserListPage extends React.Component {
|
||||
owner: "admin", // this.props.account.username,
|
||||
name: `user_${this.state.users.length}`,
|
||||
createdTime: moment().format(),
|
||||
password: "123456",
|
||||
password: "123",
|
||||
passwordType: "plain",
|
||||
displayName: `New User - ${this.state.users.length}`,
|
||||
avatar: "https://casbin.org/img/casbin.svg",
|
||||
email: "user@example.com",
|
||||
phone: "1-12345678",
|
||||
affiliation: "Example Inc.",
|
||||
tag: "staff",
|
||||
isAdmin: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user