diff --git a/controllers/account.go b/controllers/account.go index 61001894..c4e819a8 100644 --- a/controllers/account.go +++ b/controllers/account.go @@ -78,8 +78,8 @@ type HumanCheck struct { func (c *ApiController) Signup() { var resp Response - if c.GetSessionUser() != "" { - c.ResponseErrorWithData("Please sign out first before signing up", c.GetSessionUser()) + if c.GetSessionUsername() != "" { + c.ResponseErrorWithData("Please sign out first before signing up", c.GetSessionUsername()) return } @@ -161,7 +161,7 @@ func (c *ApiController) Signup() { if application.HasPromptPage() { // The prompt page needs the user to be signed in - c.SetSessionUser(user.GetId()) + c.SetSessionUsername(user.GetId()) } object.DisableVerificationCode(form.Email) @@ -181,10 +181,10 @@ func (c *ApiController) Signup() { func (c *ApiController) Logout() { var resp Response - user := c.GetSessionUser() + user := c.GetSessionUsername() util.LogInfo(c.Ctx, "API: [%s] logged out", user) - c.SetSessionUser("") + c.SetSessionUsername("") resp = Response{Status: "ok", Msg: "", Data: user} diff --git a/controllers/auth.go b/controllers/auth.go index 211cc63a..9d34a56b 100644 --- a/controllers/auth.go +++ b/controllers/auth.go @@ -38,7 +38,7 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob userId := user.GetId() resp := &Response{} if form.Type == ResponseTypeLogin { - c.SetSessionUser(userId) + c.SetSessionUsername(userId) util.LogInfo(c.Ctx, "API: [%s] signed in", userId) resp = &Response{Status: "ok", Msg: "", Data: userId} } else if form.Type == ResponseTypeCode { @@ -53,7 +53,7 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob if application.HasPromptPage() { // The prompt page needs the user to be signed in - c.SetSessionUser(userId) + c.SetSessionUsername(userId) } } else { resp = &Response{Status: "error", Msg: fmt.Sprintf("Unknown response type: %s", form.Type)} @@ -108,8 +108,8 @@ func (c *ApiController) Login() { if form.Username != "" { if form.Type == ResponseTypeLogin { - if c.GetSessionUser() != "" { - resp = &Response{Status: "error", Msg: "Please log out first before signing in", Data: c.GetSessionUser()} + if c.GetSessionUsername() != "" { + resp = &Response{Status: "error", Msg: "Please log out first before signing in", Data: c.GetSessionUsername()} c.Data["json"] = resp c.ServeJSON() return @@ -315,7 +315,7 @@ func (c *ApiController) Login() { } //resp = &Response{Status: "ok", Msg: "", Data: res} } else { // form.Method != "signup" - userId := c.GetSessionUser() + userId := c.GetSessionUsername() if userId == "" { resp = &Response{Status: "error", Msg: "The account does not exist", Data: userInfo} c.Data["json"] = resp diff --git a/controllers/base.go b/controllers/base.go index ad0c5e40..6bd2d03e 100644 --- a/controllers/base.go +++ b/controllers/base.go @@ -20,7 +20,7 @@ type ApiController struct { beego.Controller } -func (c *ApiController) GetSessionUser() string { +func (c *ApiController) GetSessionUsername() string { user := c.GetSession("username") if user == nil { return "" @@ -29,7 +29,7 @@ func (c *ApiController) GetSessionUser() string { return user.(string) } -func (c *ApiController) SetSessionUser(user string) { +func (c *ApiController) SetSessionUsername(user string) { c.SetSession("username", user) } diff --git a/controllers/user.go b/controllers/user.go index 477be264..ed1f6a87 100644 --- a/controllers/user.go +++ b/controllers/user.go @@ -170,7 +170,7 @@ func (c *ApiController) SetPassword() { oldPassword := c.Ctx.Request.Form.Get("oldPassword") newPassword := c.Ctx.Request.Form.Get("newPassword") - requestUserId := c.GetSessionUser() + requestUserId := c.GetSessionUsername() if requestUserId == "" { c.ResponseError("Please login first.") return @@ -223,7 +223,7 @@ func (c *ApiController) SetPassword() { return } - c.SetSessionUser("") + c.SetSessionUsername("") targetUser.Password = newPassword object.SetUserField(targetUser, "password", targetUser.Password) diff --git a/controllers/util.go b/controllers/util.go index 4c5c8688..ffbedb5b 100644 --- a/controllers/util.go +++ b/controllers/util.go @@ -60,7 +60,7 @@ func (c *ApiController) ResponseErrorWithData(error string, data interface{}) { } func (c *ApiController) RequireSignedIn() (string, bool) { - userId := c.GetSessionUser() + userId := c.GetSessionUsername() if userId == "" { resp := Response{Status: "error", Msg: "Please sign in first"} c.Data["json"] = resp diff --git a/controllers/verification.go b/controllers/verification.go index 03644554..8d99f331 100644 --- a/controllers/verification.go +++ b/controllers/verification.go @@ -24,7 +24,7 @@ import ( func (c *ApiController) getCurrentUser() *object.User { var user *object.User - userId := c.GetSessionUser() + userId := c.GetSessionUsername() if userId == "" { user = nil } else {