mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 11:20:18 +08:00
refactor: SessionUser -> SessionUsername
Signed-off-by: Kininaru <shiftregister233@outlook.com>
This commit is contained in:
@ -78,8 +78,8 @@ type HumanCheck struct {
|
|||||||
func (c *ApiController) Signup() {
|
func (c *ApiController) Signup() {
|
||||||
var resp Response
|
var resp Response
|
||||||
|
|
||||||
if c.GetSessionUser() != "" {
|
if c.GetSessionUsername() != "" {
|
||||||
c.ResponseErrorWithData("Please sign out first before signing up", c.GetSessionUser())
|
c.ResponseErrorWithData("Please sign out first before signing up", c.GetSessionUsername())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ func (c *ApiController) Signup() {
|
|||||||
|
|
||||||
if application.HasPromptPage() {
|
if application.HasPromptPage() {
|
||||||
// The prompt page needs the user to be signed in
|
// The prompt page needs the user to be signed in
|
||||||
c.SetSessionUser(user.GetId())
|
c.SetSessionUsername(user.GetId())
|
||||||
}
|
}
|
||||||
|
|
||||||
object.DisableVerificationCode(form.Email)
|
object.DisableVerificationCode(form.Email)
|
||||||
@ -181,10 +181,10 @@ func (c *ApiController) Signup() {
|
|||||||
func (c *ApiController) Logout() {
|
func (c *ApiController) Logout() {
|
||||||
var resp Response
|
var resp Response
|
||||||
|
|
||||||
user := c.GetSessionUser()
|
user := c.GetSessionUsername()
|
||||||
util.LogInfo(c.Ctx, "API: [%s] logged out", user)
|
util.LogInfo(c.Ctx, "API: [%s] logged out", user)
|
||||||
|
|
||||||
c.SetSessionUser("")
|
c.SetSessionUsername("")
|
||||||
|
|
||||||
resp = Response{Status: "ok", Msg: "", Data: user}
|
resp = Response{Status: "ok", Msg: "", Data: user}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob
|
|||||||
userId := user.GetId()
|
userId := user.GetId()
|
||||||
resp := &Response{}
|
resp := &Response{}
|
||||||
if form.Type == ResponseTypeLogin {
|
if form.Type == ResponseTypeLogin {
|
||||||
c.SetSessionUser(userId)
|
c.SetSessionUsername(userId)
|
||||||
util.LogInfo(c.Ctx, "API: [%s] signed in", userId)
|
util.LogInfo(c.Ctx, "API: [%s] signed in", userId)
|
||||||
resp = &Response{Status: "ok", Msg: "", Data: userId}
|
resp = &Response{Status: "ok", Msg: "", Data: userId}
|
||||||
} else if form.Type == ResponseTypeCode {
|
} else if form.Type == ResponseTypeCode {
|
||||||
@ -53,7 +53,7 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob
|
|||||||
|
|
||||||
if application.HasPromptPage() {
|
if application.HasPromptPage() {
|
||||||
// The prompt page needs the user to be signed in
|
// The prompt page needs the user to be signed in
|
||||||
c.SetSessionUser(userId)
|
c.SetSessionUsername(userId)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resp = &Response{Status: "error", Msg: fmt.Sprintf("Unknown response type: %s", form.Type)}
|
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.Username != "" {
|
||||||
if form.Type == ResponseTypeLogin {
|
if form.Type == ResponseTypeLogin {
|
||||||
if c.GetSessionUser() != "" {
|
if c.GetSessionUsername() != "" {
|
||||||
resp = &Response{Status: "error", Msg: "Please log out first before signing in", Data: c.GetSessionUser()}
|
resp = &Response{Status: "error", Msg: "Please log out first before signing in", Data: c.GetSessionUsername()}
|
||||||
c.Data["json"] = resp
|
c.Data["json"] = resp
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
@ -315,7 +315,7 @@ func (c *ApiController) Login() {
|
|||||||
}
|
}
|
||||||
//resp = &Response{Status: "ok", Msg: "", Data: res}
|
//resp = &Response{Status: "ok", Msg: "", Data: res}
|
||||||
} else { // form.Method != "signup"
|
} else { // form.Method != "signup"
|
||||||
userId := c.GetSessionUser()
|
userId := c.GetSessionUsername()
|
||||||
if userId == "" {
|
if userId == "" {
|
||||||
resp = &Response{Status: "error", Msg: "The account does not exist", Data: userInfo}
|
resp = &Response{Status: "error", Msg: "The account does not exist", Data: userInfo}
|
||||||
c.Data["json"] = resp
|
c.Data["json"] = resp
|
||||||
|
@ -20,7 +20,7 @@ type ApiController struct {
|
|||||||
beego.Controller
|
beego.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApiController) GetSessionUser() string {
|
func (c *ApiController) GetSessionUsername() string {
|
||||||
user := c.GetSession("username")
|
user := c.GetSession("username")
|
||||||
if user == nil {
|
if user == nil {
|
||||||
return ""
|
return ""
|
||||||
@ -29,7 +29,7 @@ func (c *ApiController) GetSessionUser() string {
|
|||||||
return user.(string)
|
return user.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApiController) SetSessionUser(user string) {
|
func (c *ApiController) SetSessionUsername(user string) {
|
||||||
c.SetSession("username", user)
|
c.SetSession("username", user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ func (c *ApiController) SetPassword() {
|
|||||||
oldPassword := c.Ctx.Request.Form.Get("oldPassword")
|
oldPassword := c.Ctx.Request.Form.Get("oldPassword")
|
||||||
newPassword := c.Ctx.Request.Form.Get("newPassword")
|
newPassword := c.Ctx.Request.Form.Get("newPassword")
|
||||||
|
|
||||||
requestUserId := c.GetSessionUser()
|
requestUserId := c.GetSessionUsername()
|
||||||
if requestUserId == "" {
|
if requestUserId == "" {
|
||||||
c.ResponseError("Please login first.")
|
c.ResponseError("Please login first.")
|
||||||
return
|
return
|
||||||
@ -223,7 +223,7 @@ func (c *ApiController) SetPassword() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.SetSessionUser("")
|
c.SetSessionUsername("")
|
||||||
|
|
||||||
targetUser.Password = newPassword
|
targetUser.Password = newPassword
|
||||||
object.SetUserField(targetUser, "password", targetUser.Password)
|
object.SetUserField(targetUser, "password", targetUser.Password)
|
||||||
|
@ -60,7 +60,7 @@ func (c *ApiController) ResponseErrorWithData(error string, data interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApiController) RequireSignedIn() (string, bool) {
|
func (c *ApiController) RequireSignedIn() (string, bool) {
|
||||||
userId := c.GetSessionUser()
|
userId := c.GetSessionUsername()
|
||||||
if userId == "" {
|
if userId == "" {
|
||||||
resp := Response{Status: "error", Msg: "Please sign in first"}
|
resp := Response{Status: "error", Msg: "Please sign in first"}
|
||||||
c.Data["json"] = resp
|
c.Data["json"] = resp
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
|
|
||||||
func (c *ApiController) getCurrentUser() *object.User {
|
func (c *ApiController) getCurrentUser() *object.User {
|
||||||
var user *object.User
|
var user *object.User
|
||||||
userId := c.GetSessionUser()
|
userId := c.GetSessionUsername()
|
||||||
if userId == "" {
|
if userId == "" {
|
||||||
user = nil
|
user = nil
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user