mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 10:45:47 +08:00
Improve CheckUserLogin().
This commit is contained in:
parent
7b32207443
commit
5b1b8662ac
@ -32,7 +32,8 @@ func codeToResponse(code *object.Code) *Response {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ApiController) HandleLoggedIn(userId string, form *RequestForm) *Response {
|
||||
func (c *ApiController) HandleLoggedIn(user *object.User, form *RequestForm) *Response {
|
||||
userId := user.GetId()
|
||||
resp := &Response{}
|
||||
if form.Type == ResponseTypeLogin {
|
||||
c.SetSessionUser(userId)
|
||||
@ -105,14 +106,13 @@ func (c *ApiController) Login() {
|
||||
}
|
||||
}
|
||||
|
||||
userId := fmt.Sprintf("%s/%s", form.Organization, form.Username)
|
||||
password := form.Password
|
||||
msg := object.CheckUserLogin(userId, password)
|
||||
user, msg := object.CheckUserLogin(form.Organization, form.Username, password)
|
||||
|
||||
if msg != "" {
|
||||
resp = &Response{Status: "error", Msg: msg, Data: ""}
|
||||
} else {
|
||||
resp = c.HandleLoggedIn(userId, &form)
|
||||
resp = c.HandleLoggedIn(user, &form)
|
||||
}
|
||||
} else if form.Provider != "" {
|
||||
application := object.GetApplication(fmt.Sprintf("admin/%s", form.Application))
|
||||
@ -153,8 +153,8 @@ func (c *ApiController) Login() {
|
||||
}
|
||||
|
||||
if form.Method == "signup" {
|
||||
userId := object.GetUserIdByField(application, provider.Type, userInfo.Username)
|
||||
if userId != "" {
|
||||
user := object.GetUserByField(application.Organization, provider.Type, userInfo.Username)
|
||||
if user != nil {
|
||||
//if object.IsForbidden(userId) {
|
||||
// c.forbiddenAccountResp(userId)
|
||||
// return
|
||||
@ -165,7 +165,7 @@ func (c *ApiController) Login() {
|
||||
// object.LinkMemberAccount(userId, "avatar", avatar)
|
||||
//}
|
||||
|
||||
resp = c.HandleLoggedIn(userId, &form)
|
||||
resp = c.HandleLoggedIn(user, &form)
|
||||
} else {
|
||||
//if userId := object.GetUserIdByField(application, "email", userInfo.Email); userId != "" {
|
||||
// resp = c.HandleLoggedIn(userId, &form)
|
||||
|
@ -55,26 +55,19 @@ func CheckUserSignup(organization string, username string, password string, disp
|
||||
}
|
||||
}
|
||||
|
||||
func CheckUserLogin(userId string, password string) string {
|
||||
if !HasUser(userId) {
|
||||
return "username does not exist, please sign up first"
|
||||
func CheckUserLogin(organization string, username string, password string) (*User, string) {
|
||||
user := GetUserByField(organization, "name", username)
|
||||
if user == nil {
|
||||
return nil, "username does not exist, please sign up first"
|
||||
}
|
||||
|
||||
if !IsPasswordCorrect(userId, password) {
|
||||
return "password incorrect"
|
||||
if user.Password != password {
|
||||
return nil, "password incorrect"
|
||||
}
|
||||
|
||||
return ""
|
||||
return user, ""
|
||||
}
|
||||
|
||||
func (user *User) getId() string {
|
||||
func (user *User) GetId() string {
|
||||
return fmt.Sprintf("%s/%s", user.Owner, user.Name)
|
||||
}
|
||||
|
||||
func GetUserIdByField(application *Application, field string, value string) string {
|
||||
user := GetUserByField(application.Organization, field, value)
|
||||
if user != nil {
|
||||
return user.getId()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user