mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 11:20:18 +08:00
Add codeToResponse().
This commit is contained in:
@ -25,7 +25,7 @@ import (
|
|||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RegisterForm struct {
|
type RequestForm struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
|
||||||
Organization string `json:"organization"`
|
Organization string `json:"organization"`
|
||||||
@ -65,7 +65,7 @@ func (c *ApiController) Register() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var form RegisterForm
|
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 {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -138,7 +138,7 @@ func (c *ApiController) UploadAvatar() {
|
|||||||
username := c.GetSessionUser()
|
username := c.GetSessionUser()
|
||||||
userObj := object.GetUser(username)
|
userObj := object.GetUser(username)
|
||||||
|
|
||||||
msg := object.CheckUserLogin(userObj.Owner + "/" + userObj.Name, c.Ctx.Request.Form.Get("password"))
|
msg := object.CheckUserLogin(userObj.Owner+"/"+userObj.Name, c.Ctx.Request.Form.Get("password"))
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
resp = Response{Status: "error", Msg: "Password wrong"}
|
resp = Response{Status: "error", Msg: "Password wrong"}
|
||||||
c.Data["json"] = resp
|
c.Data["json"] = resp
|
||||||
@ -148,14 +148,14 @@ func (c *ApiController) UploadAvatar() {
|
|||||||
|
|
||||||
avatarBase64 := c.Ctx.Request.Form.Get("avatarfile")
|
avatarBase64 := c.Ctx.Request.Form.Get("avatarfile")
|
||||||
index := strings.Index(avatarBase64, ",")
|
index := strings.Index(avatarBase64, ",")
|
||||||
if index < 0 || avatarBase64[0: index] != "data:image/png;base64" {
|
if index < 0 || avatarBase64[0:index] != "data:image/png;base64" {
|
||||||
resp = Response{Status: "error", Msg: "File encoding error"}
|
resp = Response{Status: "error", Msg: "File encoding error"}
|
||||||
c.Data["json"] = resp
|
c.Data["json"] = resp
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dist, _ := base64.StdEncoding.DecodeString(avatarBase64[index + 1:])
|
dist, _ := base64.StdEncoding.DecodeString(avatarBase64[index+1:])
|
||||||
msg = object.UploadAvatar(userObj.Name, dist)
|
msg = object.UploadAvatar(userObj.Name, dist)
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
resp = Response{Status: "error", Msg: msg}
|
resp = Response{Status: "error", Msg: msg}
|
||||||
@ -164,7 +164,7 @@ func (c *ApiController) UploadAvatar() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
userObj.Avatar = object.GetAvatarPath() + userObj.Name + ".png?time=" + strconv.FormatInt(time.Now().UnixNano(), 10)
|
userObj.Avatar = object.GetAvatarPath() + userObj.Name + ".png?time=" + strconv.FormatInt(time.Now().UnixNano(), 10)
|
||||||
object.UpdateUser(userObj.Owner + "/" + userObj.Name, userObj)
|
object.UpdateUser(userObj.Owner+"/"+userObj.Name, userObj)
|
||||||
resp = Response{Status: "ok", Msg: "Successfully set avatar"}
|
resp = Response{Status: "ok", Msg: "Successfully set avatar"}
|
||||||
c.Data["json"] = resp
|
c.Data["json"] = resp
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
|
@ -33,7 +33,7 @@ func (c *ApiController) HandleLoggedIn(userId string) {
|
|||||||
|
|
||||||
func (c *ApiController) Login() {
|
func (c *ApiController) Login() {
|
||||||
var resp Response
|
var resp Response
|
||||||
var form RegisterForm
|
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 {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -69,6 +69,14 @@ func (c *ApiController) DeleteToken() {
|
|||||||
c.ServeJSON()
|
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() {
|
func (c *ApiController) GetOAuthCode() {
|
||||||
userId := c.GetSessionUser()
|
userId := c.GetSessionUser()
|
||||||
clientId := c.Input().Get("clientId")
|
clientId := c.Input().Get("clientId")
|
||||||
@ -77,7 +85,8 @@ func (c *ApiController) GetOAuthCode() {
|
|||||||
scope := c.Input().Get("scope")
|
scope := c.Input().Get("scope")
|
||||||
state := c.Input().Get("state")
|
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()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user