update docs, remove config file on 401
This commit is contained in:
parent
9cc72ff1a9
commit
90f6bdd6e4
4 changed files with 36 additions and 12 deletions
4
api.go
4
api.go
|
@ -49,6 +49,10 @@ func httpError(w http.ResponseWriter, err error) {
|
|||
http.Error(w, err.Error(), http.StatusConflict)
|
||||
} else if strings.HasPrefix(err.Error(), "Impossible") {
|
||||
http.Error(w, err.Error(), http.StatusNotAcceptable)
|
||||
} else if strings.HasPrefix(err.Error(), "Wrong login/password") {
|
||||
http.Error(w, err.Error(), http.StatusUnauthorized)
|
||||
} else if strings.Contains(err.Error(), "hasn't been activated") {
|
||||
http.Error(w, err.Error(), http.StatusForbidden)
|
||||
} else {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ func Login(authConfig *AuthConfig, store bool) (string, error) {
|
|||
|
||||
if reqStatusCode == 201 {
|
||||
status = "Account created. Please use the confirmation link we sent" +
|
||||
" to your e-mail to activate it.\n"
|
||||
" to your e-mail to activate it."
|
||||
storeConfig = true
|
||||
} else if reqStatusCode == 403 {
|
||||
return "", fmt.Errorf("Login: Your account hasn't been activated. " +
|
||||
|
@ -165,10 +165,11 @@ func Login(authConfig *AuthConfig, store bool) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
if resp.StatusCode == 200 {
|
||||
status = "Login Succeeded\n"
|
||||
status = "Login Succeeded"
|
||||
storeConfig = true
|
||||
} else if resp.StatusCode == 401 {
|
||||
if store {
|
||||
authConfig.Email = ""
|
||||
if err := SaveConfig(authConfig); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
32
commands.go
32
commands.go
|
@ -296,16 +296,21 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
|||
if username == "" {
|
||||
username = cli.authConfig.Username
|
||||
}
|
||||
fmt.Print("Password: ")
|
||||
password = readString(os.Stdin, os.Stdout)
|
||||
if username != cli.authConfig.Username {
|
||||
fmt.Print("Password: ")
|
||||
password = readString(os.Stdin, os.Stdout)
|
||||
|
||||
if password == "" {
|
||||
return fmt.Errorf("Error : Password Required")
|
||||
}
|
||||
if password == "" {
|
||||
return fmt.Errorf("Error : Password Required")
|
||||
}
|
||||
|
||||
fmt.Print("Email (", cli.authConfig.Email, "): ")
|
||||
email = readAndEchoString(os.Stdin, os.Stdout)
|
||||
if email == "" {
|
||||
fmt.Print("Email (", cli.authConfig.Email, "): ")
|
||||
email = readAndEchoString(os.Stdin, os.Stdout)
|
||||
if email == "" {
|
||||
email = cli.authConfig.Email
|
||||
}
|
||||
} else {
|
||||
password = cli.authConfig.Password
|
||||
email = cli.authConfig.Email
|
||||
}
|
||||
term.RestoreTerminal(oldState)
|
||||
|
@ -314,7 +319,14 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
|||
cli.authConfig.Password = password
|
||||
cli.authConfig.Email = email
|
||||
|
||||
body, _, err := cli.call("POST", "/auth", cli.authConfig)
|
||||
body, statusCode, err := cli.call("POST", "/auth", cli.authConfig)
|
||||
if statusCode == 401 {
|
||||
cli.authConfig.Username = ""
|
||||
cli.authConfig.Password = ""
|
||||
cli.authConfig.Email = ""
|
||||
auth.SaveConfig(cli.authConfig)
|
||||
return err
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -327,7 +339,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
|||
}
|
||||
auth.SaveConfig(cli.authConfig)
|
||||
if out2.Status != "" {
|
||||
fmt.Print(out2.Status)
|
||||
fmt.Println(out2.Status)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -877,9 +877,16 @@ Check auth configuration
|
|||
.. sourcecode:: http
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"Status": "Login Succeeded"
|
||||
}
|
||||
|
||||
:statuscode 200: no error
|
||||
:statuscode 204: no error
|
||||
:statuscode 401: unauthorized
|
||||
:statuscode 403: forbidden
|
||||
:statuscode 500: server error
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue