Browse code

update docs, remove config file on 401

Victor Vieux authored on 2013/06/14 22:38:51
Showing 4 changed files
... ...
@@ -49,6 +49,10 @@ func httpError(w http.ResponseWriter, err error) {
49 49
 		http.Error(w, err.Error(), http.StatusConflict)
50 50
 	} else if strings.HasPrefix(err.Error(), "Impossible") {
51 51
 		http.Error(w, err.Error(), http.StatusNotAcceptable)
52
+	} else if strings.HasPrefix(err.Error(), "Wrong login/password") {
53
+		http.Error(w, err.Error(), http.StatusUnauthorized)
54
+	} else if strings.Contains(err.Error(), "hasn't been activated") {
55
+		http.Error(w, err.Error(), http.StatusForbidden)
52 56
 	} else {
53 57
 		http.Error(w, err.Error(), http.StatusInternalServerError)
54 58
 	}
... ...
@@ -146,7 +146,7 @@ func Login(authConfig *AuthConfig, store bool) (string, error) {
146 146
 
147 147
 	if reqStatusCode == 201 {
148 148
 		status = "Account created. Please use the confirmation link we sent" +
149
-			" to your e-mail to activate it.\n"
149
+			" to your e-mail to activate it."
150 150
 		storeConfig = true
151 151
 	} else if reqStatusCode == 403 {
152 152
 		return "", fmt.Errorf("Login: Your account hasn't been activated. " +
... ...
@@ -165,10 +165,11 @@ func Login(authConfig *AuthConfig, store bool) (string, error) {
165 165
 				return "", err
166 166
 			}
167 167
 			if resp.StatusCode == 200 {
168
-				status = "Login Succeeded\n"
168
+				status = "Login Succeeded"
169 169
 				storeConfig = true
170 170
 			} else if resp.StatusCode == 401 {
171 171
 				if store {
172
+					authConfig.Email = ""
172 173
 					if err := SaveConfig(authConfig); err != nil {
173 174
 						return "", err
174 175
 					}
... ...
@@ -296,16 +296,21 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
296 296
 	if username == "" {
297 297
 		username = cli.authConfig.Username
298 298
 	}
299
-	fmt.Print("Password: ")
300
-	password = readString(os.Stdin, os.Stdout)
299
+	if username != cli.authConfig.Username {
300
+		fmt.Print("Password: ")
301
+		password = readString(os.Stdin, os.Stdout)
301 302
 
302
-	if password == "" {
303
-		return fmt.Errorf("Error : Password Required")
304
-	}
303
+		if password == "" {
304
+			return fmt.Errorf("Error : Password Required")
305
+		}
305 306
 
306
-	fmt.Print("Email (", cli.authConfig.Email, "): ")
307
-	email = readAndEchoString(os.Stdin, os.Stdout)
308
-	if email == "" {
307
+		fmt.Print("Email (", cli.authConfig.Email, "): ")
308
+		email = readAndEchoString(os.Stdin, os.Stdout)
309
+		if email == "" {
310
+			email = cli.authConfig.Email
311
+		}
312
+	} else {
313
+		password = cli.authConfig.Password
309 314
 		email = cli.authConfig.Email
310 315
 	}
311 316
 	term.RestoreTerminal(oldState)
... ...
@@ -314,7 +319,14 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
314 314
 	cli.authConfig.Password = password
315 315
 	cli.authConfig.Email = email
316 316
 
317
-	body, _, err := cli.call("POST", "/auth", cli.authConfig)
317
+	body, statusCode, err := cli.call("POST", "/auth", cli.authConfig)
318
+	if statusCode == 401 {
319
+		cli.authConfig.Username = ""
320
+		cli.authConfig.Password = ""
321
+		cli.authConfig.Email = ""
322
+		auth.SaveConfig(cli.authConfig)
323
+		return err
324
+	}
318 325
 	if err != nil {
319 326
 		return err
320 327
 	}
... ...
@@ -327,7 +339,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
327 327
 	}
328 328
 	auth.SaveConfig(cli.authConfig)
329 329
 	if out2.Status != "" {
330
-		fmt.Print(out2.Status)
330
+		fmt.Println(out2.Status)
331 331
 	}
332 332
 	return nil
333 333
 }
... ...
@@ -877,9 +877,16 @@ Check auth configuration
877 877
         .. sourcecode:: http
878 878
 
879 879
            HTTP/1.1 200 OK
880
+	   Content-Type: application/json
881
+
882
+	   {
883
+		"Status": "Login Succeeded"
884
+	   }
880 885
 
881 886
         :statuscode 200: no error
882 887
         :statuscode 204: no error
888
+        :statuscode 401: unauthorized
889
+        :statuscode 403: forbidden
883 890
         :statuscode 500: server error
884 891
 
885 892