casnode/casdoor/user.go

83 lines
1.7 KiB
Go
Raw Normal View History

// Copyright 2021 The casbin Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package casdoor
2022-09-29 00:37:37 +08:00
import "github.com/casdoor/casdoor-go-sdk/casdoorsdk"
2022-09-29 00:37:37 +08:00
func GetUsers() []*casdoorsdk.User {
if adapter != nil {
return getUsers()
} else {
2022-09-29 00:37:37 +08:00
users, err := casdoorsdk.GetUsers()
if err != nil {
panic(err)
}
return users
}
}
2022-09-29 00:37:37 +08:00
func GetSortedUsers(sorter string, limit int) []*casdoorsdk.User {
if adapter != nil {
return getSortedUsers(sorter, limit)
} else {
2022-09-29 00:37:37 +08:00
users, err := casdoorsdk.GetSortedUsers(sorter, limit)
if err != nil {
panic(err)
}
2021-08-28 11:26:44 +08:00
return users
2021-08-28 11:26:44 +08:00
}
}
func GetUserCount() int {
if adapter != nil {
return getUserCount()
} else {
2022-09-29 00:37:37 +08:00
count, err := casdoorsdk.GetUserCount("")
if err != nil {
panic(err)
}
2021-08-28 11:26:44 +08:00
return count
2021-08-28 11:26:44 +08:00
}
}
func GetOnlineUserCount() int {
if adapter != nil {
return getOnlineUserCount()
} else {
2022-09-29 00:37:37 +08:00
count, err := casdoorsdk.GetUserCount("1")
if err != nil {
panic(err)
}
return count
}
}
2021-08-28 11:26:44 +08:00
2022-09-29 00:37:37 +08:00
func GetUserByEmail(email string) *casdoorsdk.User {
if adapter != nil {
return getUserByEmail(email)
2021-08-28 11:26:44 +08:00
} else {
2022-09-29 00:37:37 +08:00
user, err := casdoorsdk.GetUserByEmail(email)
if err != nil {
panic(err)
}
return user
2021-08-28 11:26:44 +08:00
}
}