Refactor the record code.

This commit is contained in:
Gucheng Wang
2021-11-07 16:51:16 +08:00
parent 0e71e603ac
commit 77fffcacac
7 changed files with 78 additions and 112 deletions

View File

@ -195,10 +195,9 @@ func (c *ApiController) Login() {
application := object.GetApplication(fmt.Sprintf("admin/%s", form.Application))
resp = c.HandleLoggedIn(application, user, &form)
record := util.Records(c.Ctx)
record := object.NewRecord(c.Ctx)
record.Organization = application.Organization
record.Username = user.Name
object.AddRecord(record)
}
} else if form.Provider != "" {
@ -260,10 +259,9 @@ func (c *ApiController) Login() {
resp = c.HandleLoggedIn(application, user, &form)
record := util.Records(c.Ctx)
record := object.NewRecord(c.Ctx)
record.Organization = application.Organization
record.Username = user.Name
object.AddRecord(record)
} else {
// Sign up via OAuth
@ -306,10 +304,9 @@ func (c *ApiController) Login() {
resp = c.HandleLoggedIn(application, user, &form)
record := util.Records(c.Ctx)
record := object.NewRecord(c.Ctx)
record.Organization = application.Organization
record.Username = user.Name
object.AddRecord(record)
}
//resp = &Response{Status: "ok", Msg: "", Data: res}

View File

@ -15,8 +15,6 @@
package controllers
import (
"encoding/json"
"github.com/astaxie/beego/utils/pagination"
"github.com/casbin/casdoor/object"
"github.com/casbin/casdoor/util"
@ -50,12 +48,14 @@ func (c *ApiController) GetRecords() {
// @Success 200 {array} object.Records The Response object
// @router /get-records-filter [post]
func (c *ApiController) GetRecordsByFilter() {
var record object.Records
err := json.Unmarshal(c.Ctx.Input.RequestBody, &record)
body := string(c.Ctx.Input.RequestBody)
record := &object.Record{}
err := util.JsonToStruct(body, record)
if err != nil {
panic(err)
}
c.Data["json"] = object.GetRecordsByField(&record)
c.Data["json"] = object.GetRecordsByField(record)
c.ServeJSON()
}