Commit 7ff2205f authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

User: keeping track of email

This will be essential for SSO logins for which the email
is the proper identifier.
parent 3b63c6b045f9
......@@ -24,18 +24,24 @@ class User(object):
name = attr.ib()
id = attr.ib()
heptapod = attr.ib(repr=False)
email = attr.ib(default=None, repr=False)
password = attr.ib(default=None, repr=False)
token = attr.ib(default=None, repr=False)
_webdriver = attr.ib(default=None, repr=False)
_python_gitlab_client = attr.ib(default=None, repr=False)
@classmethod
def create(cls, heptapod, name, password=None, fullname=None, **kw):
def create(cls, heptapod, name,
password=None,
email=None,
fullname=None, **kw):
if password is None:
# requirements on password length are also enforced in the API
password = default_password(name)
if fullname is None:
fullname = name
if email is None:
email = name + '@heptapod.example.net',
resp = requests.post(
'/'.join((heptapod.api_url, 'users')),
......@@ -43,7 +49,7 @@ class User(object):
username=name,
password=password,
reset_password=False,
email=name + '@heptapod.example.net',
email=email,
skip_confirmation=True,
**kw
),
......@@ -51,6 +57,7 @@ class User(object):
)
assert resp.status_code < 300, "User %r creation failed" % name
user = cls(name=name, heptapod=heptapod, password=password,
email=email,
id=resp.json()['id'])
user.store_in_heptapod()
return user
......@@ -101,8 +108,11 @@ class User(object):
return
assert len(found) == 1
user = cls(name=name, id=found[0]['id'], heptapod=heptapod)
return user
details = found[0]
return cls(name=name,
id=details['id'],
email=details['email'],
heptapod=heptapod)
def store_in_heptapod(self):
self.heptapod.users[self.name] = self
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment