Fixed bugs in Client.login

This commit is contained in:
shin- 2013-09-25 18:48:04 +02:00
parent 78481e2159
commit 4c4e66a012
1 changed files with 13 additions and 11 deletions

View File

@ -315,22 +315,24 @@ class Client(requests.Session):
res = self.post(url, None) res = self.post(url, None)
self._raise_for_status(res) self._raise_for_status(res)
def login(self, username, password=None, email=None): def login(self, username, password=None, email=None, registry=None):
url = self._url("/auth") url = self._url("/auth")
res = self.get(url) if registry is None:
json_ = res.json() registry = auth.INDEX_URL
if 'username' in json_ and json_['username'] == username: if getattr(self, '_cfg', None) is None:
return json_ self._cfg = auth.load_config()
authcfg = auth.resolve_authconfig(self._cfg, registry)
if 'username' in authcfg and authcfg['username'] == username:
return authcfg
req_data = { req_data = {
'username': username, 'username': username,
'password': password if password is not None else json_['password'], 'password': password,
'email': email if email is not None else json_['email'] 'email': email
} }
res = self._result(self._post_json(url, req_data), True) res = self._result(self._post_json(url, req_data), True)
try: if res['Status'] == 'Login Succeeded':
self._cfg = auth.load_config() self._cfg['Configs'][registry] = req_data
finally: return res
return res
def logs(self, container): def logs(self, container):
if isinstance(container, dict): if isinstance(container, dict):