mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-25 08:20:31 +08:00
refactor: SessionUser -> SessionUsername
Signed-off-by: Kininaru <shiftregister233@outlook.com>
This commit is contained in:
parent
441d69f4ac
commit
ae9ebd2de1
@ -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}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user