diff --git a/api.go b/api.go index 403254649b..18c5e5c67a 100644 --- a/api.go +++ b/api.go @@ -53,6 +53,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) } diff --git a/auth/auth.go b/auth/auth.go index 159c80f73a..12c9471699 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -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 } diff --git a/auth/auth_test.go b/auth/auth_test.go index ead69e8913..8e7adaef8d 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -34,7 +34,7 @@ func TestLogin(t *testing.T) { if err != nil { t.Fatal(err) } - if status != "Login Succeeded\n" { + if status != "Login Succeeded" { t.Fatalf("Expected status \"Login Succeeded\", found \"%s\" instead", status) } } @@ -55,7 +55,7 @@ func TestCreateAccount(t *testing.T) { t.Fatal(err) } expectedStatus := "Account created. Please use the confirmation link we sent" + - " to your e-mail to activate it.\n" + " to your e-mail to activate it." if status != expectedStatus { t.Fatalf("Expected status: \"%s\", found \"%s\" instead.", expectedStatus, status) } diff --git a/commands.go b/commands.go index 1f3426f900..3d1efe7bf0 100644 --- a/commands.go +++ b/commands.go @@ -316,6 +316,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error { email = cli.authConfig.Email } } else { + password = cli.authConfig.Password email = cli.authConfig.Email } term.RestoreTerminal(oldState) @@ -324,7 +325,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 } @@ -337,7 +345,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 } diff --git a/docs/sources/api/docker_remote_api_v1.2.rst b/docs/sources/api/docker_remote_api_v1.2.rst index 7f57b05624..5448436d75 100644 --- a/docs/sources/api/docker_remote_api_v1.2.rst +++ b/docs/sources/api/docker_remote_api_v1.2.rst @@ -895,9 +895,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