Fixed issue with verifying user successfully logged in
This commit is contained in:
parent
b94b156f18
commit
474340b082
41
client.go
41
client.go
|
@ -132,12 +132,38 @@ func (c *Client) getSalts(username string) ([]string, error) {
|
||||||
return gsr.Data.Salts, nil
|
return gsr.Data.Salts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type DataBool struct {
|
||||||
LoggedIn bool `json:"logged_in"`
|
Session bool `json:"session"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginResponse struct {
|
type LoginResponseBool struct {
|
||||||
User User `json:"user"`
|
Data DataBool `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DataString struct {
|
||||||
|
Session string `json:"session"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoginResponseString struct {
|
||||||
|
Data DataString `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func loginResponseSession(body []byte) (string, error) {
|
||||||
|
bodyS := string(body)
|
||||||
|
|
||||||
|
var lrs LoginResponseString
|
||||||
|
err := json.NewDecoder(strings.NewReader(bodyS)).Decode(&lrs)
|
||||||
|
if err == nil {
|
||||||
|
return lrs.Data.Session, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var lrb LoginResponseBool
|
||||||
|
err = json.NewDecoder(strings.NewReader(bodyS)).Decode(&lrb)
|
||||||
|
if err == nil {
|
||||||
|
return "false", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", fmt.Errorf("error decoding login response")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) userLogin(username string, password string, salts []string) error {
|
func (c *Client) userLogin(username string, password string, salts []string) error {
|
||||||
|
@ -165,13 +191,12 @@ func (c *Client) userLogin(username string, password string, salts []string) err
|
||||||
return fmt.Errorf("error reading body bytes: %v", err)
|
return fmt.Errorf("error reading body bytes: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var lr LoginResponse
|
session, err := loginResponseSession(bodyB)
|
||||||
err = json.NewDecoder(strings.NewReader(string(bodyB))).Decode(&lr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error decoding response body from server: %v", err)
|
return fmt.Errorf("error getting login response session: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !lr.User.LoggedIn {
|
if session == "false" {
|
||||||
return fmt.Errorf("failed to log in")
|
return fmt.Errorf("failed to log in")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue