Add codeToResponse().

This commit is contained in:
Yang Luo
2021-03-20 09:11:03 +08:00
parent 18c021b009
commit c8cd37058e
3 changed files with 17 additions and 8 deletions

View File

@ -25,7 +25,7 @@ import (
"github.com/casdoor/casdoor/util"
)
type RegisterForm struct {
type RequestForm struct {
Type string `json:"type"`
Organization string `json:"organization"`
@ -65,7 +65,7 @@ func (c *ApiController) Register() {
return
}
var form RegisterForm
var form RequestForm
err := json.Unmarshal(c.Ctx.Input.RequestBody, &form)
if err != nil {
panic(err)

View File

@ -33,7 +33,7 @@ func (c *ApiController) HandleLoggedIn(userId string) {
func (c *ApiController) Login() {
var resp Response
var form RegisterForm
var form RequestForm
err := json.Unmarshal(c.Ctx.Input.RequestBody, &form)
if err != nil {
panic(err)

View File

@ -69,6 +69,14 @@ func (c *ApiController) DeleteToken() {
c.ServeJSON()
}
func codeToResponse(code *object.Code) Response {
if code.Code == "" {
return Response{Status: "error", Msg: code.Message, Data: code.Code}
} else {
return Response{Status: "ok", Msg: "success", Data: code.Code}
}
}
func (c *ApiController) GetOAuthCode() {
userId := c.GetSessionUser()
clientId := c.Input().Get("clientId")
@ -77,7 +85,8 @@ func (c *ApiController) GetOAuthCode() {
scope := c.Input().Get("scope")
state := c.Input().Get("state")
c.Data["json"] = object.GetOAuthCode(userId, clientId, responseType, redirectUri, scope, state)
code := object.GetOAuthCode(userId, clientId, responseType, redirectUri, scope, state)
c.Data["json"] = codeToResponse(code)
c.ServeJSON()
}