From e71311b1afad238e38a569ce7bed90f8a27e7f07 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Mon, 15 Feb 2021 10:05:14 +0800 Subject: [PATCH] Add InitDb(). --- main.go | 1 + object/init.go | 49 +++++++++++++++++++++++++++++++++++++++++ web/src/UserListPage.js | 5 ++++- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 object/init.go diff --git a/main.go b/main.go index 84e48b46..d20b2197 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ import ( func main() { object.InitAdapter() + object.InitDb() controllers.InitHttpClient() beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{ diff --git a/object/init.go b/object/init.go new file mode 100644 index 00000000..9c985248 --- /dev/null +++ b/object/init.go @@ -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) +} diff --git a/web/src/UserListPage.js b/web/src/UserListPage.js index faa5bbf8..bfe94fdc 100644 --- a/web/src/UserListPage.js +++ b/web/src/UserListPage.js @@ -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, } }