mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 04:10:20 +08:00
Use c.ResponseOk() for all places.
This commit is contained in:
@ -174,9 +174,7 @@ func (c *ApiController) Signup() {
|
|||||||
|
|
||||||
util.LogInfo(c.Ctx, "API: [%s] is signed up as new user", userId)
|
util.LogInfo(c.Ctx, "API: [%s] is signed up as new user", userId)
|
||||||
|
|
||||||
resp = Response{Status: "ok", Msg: "", Data: userId}
|
c.ResponseOk(userId)
|
||||||
c.Data["json"] = resp
|
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logout
|
// Logout
|
||||||
@ -193,10 +191,7 @@ func (c *ApiController) Logout() {
|
|||||||
c.SetSessionUsername("")
|
c.SetSessionUsername("")
|
||||||
c.SetSessionData(nil)
|
c.SetSessionData(nil)
|
||||||
|
|
||||||
resp = Response{Status: "ok", Msg: "", Data: user}
|
c.ResponseOk(user)
|
||||||
|
|
||||||
c.Data["json"] = resp
|
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAccount
|
// GetAccount
|
||||||
@ -219,10 +214,8 @@ func (c *ApiController) GetAccount() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
organization := object.GetOrganizationByUser(user)
|
organization := object.GetOrganizationByUser(user)
|
||||||
resp = Response{Status: "ok", Msg: "", Data: user, Data2: organization}
|
|
||||||
|
|
||||||
c.Data["json"] = resp
|
c.ResponseOk(user, organization)
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UploadAvatar
|
// UploadAvatar
|
||||||
@ -265,9 +258,7 @@ func (c *ApiController) UploadAvatar() {
|
|||||||
user.Avatar = fileUrl
|
user.Avatar = fileUrl
|
||||||
object.UpdateUser(user.GetId(), user)
|
object.UpdateUser(user.GetId(), user)
|
||||||
|
|
||||||
resp = Response{Status: "ok", Msg: ""}
|
c.ResponseOk()
|
||||||
c.Data["json"] = resp
|
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHumanCheck ...
|
// GetHumanCheck ...
|
||||||
|
@ -83,8 +83,6 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob
|
|||||||
// @Success 200 {object} controllers.api_controller.Response The Response object
|
// @Success 200 {object} controllers.api_controller.Response The Response object
|
||||||
// @router /update-application [get]
|
// @router /update-application [get]
|
||||||
func (c *ApiController) GetApplicationLogin() {
|
func (c *ApiController) GetApplicationLogin() {
|
||||||
var resp Response
|
|
||||||
|
|
||||||
clientId := c.Input().Get("clientId")
|
clientId := c.Input().Get("clientId")
|
||||||
responseType := c.Input().Get("responseType")
|
responseType := c.Input().Get("responseType")
|
||||||
redirectUri := c.Input().Get("redirectUri")
|
redirectUri := c.Input().Get("redirectUri")
|
||||||
@ -93,12 +91,10 @@ func (c *ApiController) GetApplicationLogin() {
|
|||||||
|
|
||||||
msg, application := object.CheckOAuthLogin(clientId, responseType, redirectUri, scope, state)
|
msg, application := object.CheckOAuthLogin(clientId, responseType, redirectUri, scope, state)
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
resp = Response{Status: "error", Msg: msg, Data: application}
|
c.ResponseError(msg, application)
|
||||||
} else {
|
} else {
|
||||||
resp = Response{Status: "ok", Msg: "", Data: application}
|
c.ResponseOk(application)
|
||||||
}
|
}
|
||||||
c.Data["json"] = resp
|
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setHttpClient(idProvider idp.IdProvider, providerType string) {
|
func setHttpClient(idProvider idp.IdProvider, providerType string) {
|
||||||
@ -117,7 +113,8 @@ func setHttpClient(idProvider idp.IdProvider, providerType string) {
|
|||||||
// @Success 200 {object} controllers.api_controller.Response The Response object
|
// @Success 200 {object} controllers.api_controller.Response The Response object
|
||||||
// @router /login [post]
|
// @router /login [post]
|
||||||
func (c *ApiController) Login() {
|
func (c *ApiController) Login() {
|
||||||
resp := &Response{Status: "null", Msg: ""}
|
resp := &Response{}
|
||||||
|
|
||||||
var form RequestForm
|
var form RequestForm
|
||||||
err := json.Unmarshal(c.Ctx.Input.RequestBody, &form)
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &form)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -51,7 +51,5 @@ func (c *ApiController) Unlink() {
|
|||||||
object.ClearUserOAuthProperties(user, providerType)
|
object.ClearUserOAuthProperties(user, providerType)
|
||||||
|
|
||||||
object.LinkUserAccount(user, providerType, "")
|
object.LinkUserAccount(user, providerType, "")
|
||||||
resp = Response{Status: "ok", Msg: ""}
|
c.ResponseOk()
|
||||||
c.Data["json"] = resp
|
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
@ -157,10 +157,7 @@ func (c *ApiController) GetEmailAndPhone() {
|
|||||||
contentType = "username"
|
contentType = "username"
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = Response{Status: "ok", Msg: "", Data: respUser, Data2: contentType}
|
c.ResponseOk(respUser, contentType)
|
||||||
|
|
||||||
c.Data["json"] = resp
|
|
||||||
c.ServeJSON()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetPassword
|
// SetPassword
|
||||||
|
@ -55,6 +55,20 @@ func InitHttpClient() {
|
|||||||
//println("Response status: %s", resp.Status)
|
//println("Response status: %s", resp.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResponseOk ...
|
||||||
|
func (c *ApiController) ResponseOk(data ...interface{}) {
|
||||||
|
resp := Response{Status: "ok"}
|
||||||
|
switch len(data) {
|
||||||
|
case 2:
|
||||||
|
resp.Data2 = data[1]
|
||||||
|
fallthrough
|
||||||
|
case 1:
|
||||||
|
resp.Data = data[0]
|
||||||
|
}
|
||||||
|
c.Data["json"] = resp
|
||||||
|
c.ServeJSON()
|
||||||
|
}
|
||||||
|
|
||||||
// ResponseError ...
|
// ResponseError ...
|
||||||
func (c *ApiController) ResponseError(error string, data ...interface{}) {
|
func (c *ApiController) ResponseError(error string, data ...interface{}) {
|
||||||
resp := Response{Status: "error", Msg: error}
|
resp := Response{Status: "error", Msg: error}
|
||||||
|
Reference in New Issue
Block a user