Add provider_item.go

This commit is contained in:
Yang Luo
2021-06-16 00:18:56 +08:00
parent 8bc9163def
commit 7ea469e876
4 changed files with 57 additions and 24 deletions

View File

@ -179,6 +179,13 @@ func (c *ApiController) GetAccount() {
var resp Response
user := object.GetUser(userId)
if user == nil {
resp := Response{Status: "error", Msg: fmt.Sprintf("The user: %s doesn't exist", userId)}
c.Data["json"] = resp
c.ServeJSON()
return
}
organization := object.GetOrganizationByUser(user)
resp = Response{Status: "ok", Msg: "", Data: user, Data2: organization}

View File

@ -54,26 +54,15 @@ func GetApplications(owner string) []*Application {
return applications
}
func (application *Application) GetProviderItem(providerName string) *ProviderItem {
for _, providerItem := range application.Providers {
if providerItem.Name == providerName {
return providerItem
}
}
return nil
}
func getProviderMap(owner string) map[string]*Provider {
providers := GetProviders(owner)
m := map[string]*Provider{}
for _, provider := range providers {
if provider.Category != "OAuth" {
continue
}
//if provider.Category != "OAuth" {
// continue
//}
provider.ClientSecret = ""
provider.ProviderUrl = ""
m[provider.Name] = provider
m[provider.Name] = getMaskedProvider(provider)
}
return m
}

View File

@ -19,15 +19,6 @@ import (
"xorm.io/core"
)
type ProviderItem struct {
Name string `json:"name"`
CanSignUp bool `json:"canSignUp"`
CanSignIn bool `json:"canSignIn"`
CanUnbind bool `json:"canUnbind"`
AlertType string `json:"alertType"`
Provider *Provider `json:"provider"`
}
type Provider struct {
Owner string `xorm:"varchar(100) notnull pk" json:"owner"`
Name string `xorm:"varchar(100) notnull pk" json:"name"`
@ -52,6 +43,19 @@ type Provider struct {
ProviderUrl string `xorm:"varchar(200)" json:"providerUrl"`
}
func getMaskedProvider(provider *Provider) *Provider {
p := &Provider{
Owner: provider.Owner,
Name: provider.Name,
CreatedTime: provider.CreatedTime,
DisplayName: provider.DisplayName,
Category: provider.Category,
Type: provider.Type,
ClientId: provider.ClientId,
}
return p
}
func GetProviders(owner string) []*Provider {
providers := []*Provider{}
err := adapter.Engine.Desc("created_time").Find(&providers, &Provider{Owner: owner})

33
object/provider_item.go Normal file
View File

@ -0,0 +1,33 @@
// 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 object
type ProviderItem struct {
Name string `json:"name"`
CanSignUp bool `json:"canSignUp"`
CanSignIn bool `json:"canSignIn"`
CanUnbind bool `json:"canUnbind"`
AlertType string `json:"alertType"`
Provider *Provider `json:"provider"`
}
func (application *Application) GetProviderItem(providerName string) *ProviderItem {
for _, providerItem := range application.Providers {
if providerItem.Name == providerName {
return providerItem
}
}
return nil
}