mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
Refactor out c.RequireSignedIn()
This commit is contained in:
@ -28,7 +28,7 @@ func InitHttpClient() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if !useProxy{
|
||||
if !useProxy {
|
||||
httpClient = &http.Client{}
|
||||
return
|
||||
}
|
||||
@ -57,3 +57,14 @@ func (c *ApiController) ResponseError(error string) {
|
||||
c.Data["json"] = Response{Status: "error", Msg: error}
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
func (c *ApiController) RequireSignedIn() (string, bool) {
|
||||
userId := c.GetSessionUser()
|
||||
if userId == "" {
|
||||
resp := Response{Status: "error", Msg: "Please sign in first"}
|
||||
c.Data["json"] = resp
|
||||
c.ServeJSON()
|
||||
return "", false
|
||||
}
|
||||
return userId, true
|
||||
}
|
||||
|
Reference in New Issue
Block a user