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

View File

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