Improve format.

This commit is contained in:
Yang Luo
2021-09-05 22:09:54 +08:00
parent 9d9a1da07f
commit bd41425039
2 changed files with 15 additions and 21 deletions

View File

@@ -18,7 +18,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"strings"
"github.com/astaxie/beego/context" "github.com/astaxie/beego/context"
"github.com/casbin/casdoor/authz" "github.com/casbin/casdoor/authz"
@@ -53,10 +52,7 @@ func getSubject(ctx *context.Context) (string, string) {
} }
// username == "built-in/admin" // username == "built-in/admin"
tokens := strings.Split(username, "/") return util.GetOwnerAndNameFromId(username)
owner := tokens[0]
name := tokens[1]
return owner, name
} }
func getObject(ctx *context.Context) (string, string) { func getObject(ctx *context.Context) (string, string) {
@@ -67,8 +63,8 @@ func getObject(ctx *context.Context) (string, string) {
if id == "" { if id == "" {
return "", "" return "", ""
} }
tokens := strings.Split(id, "/")
return tokens[0], tokens[1] return util.GetOwnerAndNameFromId(id)
} else { } else {
body := ctx.Input.RequestBody body := ctx.Input.RequestBody

View File

@@ -15,7 +15,7 @@
package routers package routers
import ( import (
"strings" "fmt"
"github.com/astaxie/beego/context" "github.com/astaxie/beego/context"
"github.com/casbin/casdoor/object" "github.com/casbin/casdoor/object"
@@ -45,27 +45,25 @@ func getUserByClientIdSecret(ctx *context.Context) string {
return "" return ""
} }
app := object.GetApplicationByClientId(clientId) application := object.GetApplicationByClientId(clientId)
if app == nil || app.ClientSecret != clientSecret { if application == nil || application.ClientSecret != clientSecret {
return "" return ""
} }
return app.Organization + "/" + app.Name return fmt.Sprintf("%s/%s", application.Organization, application.Name)
} }
func RecordMessage(ctx *context.Context) { func RecordMessage(ctx *context.Context) {
if ctx.Request.URL.Path == "/api/login" { if ctx.Request.URL.Path == "/api/login" {
return return
} }
user := getUser(ctx)
userinfo := strings.Split(user, "/")
if user == "" {
userinfo = append(userinfo, "")
}
record := util.Records(ctx) record := util.Records(ctx)
record.Organization = userinfo[0]
record.Username = userinfo[1] userId := getUser(ctx)
if userId != "" {
record.Organization, record.Username = util.GetOwnerAndNameFromId(userId)
}
object.AddRecord(record) object.AddRecord(record)
} }