Refactor out c.RequireSignedIn()

This commit is contained in:
Yang Luo
2021-05-17 23:25:28 +08:00
parent 3e41ce0104
commit 947d132362
4 changed files with 32 additions and 30 deletions

View File

@ -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
}