Skip to content

Commit

Permalink
[AdminTL#83] Login: add incremental information when connect from thi…
Browse files Browse the repository at this point in the history
…rd-party
  • Loading branch information
mathben committed Apr 1, 2018
1 parent b341237 commit 8f9d704
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 19 deletions.
17 changes: 9 additions & 8 deletions src/web/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ def get(self):
# use this email to associate
user = self._db.get_user(email=email, force_email_no_password=True)
if user:
user["google_id"] = google_id
self._db.update_user(user)
self._db.add_missing_info_user(user, google_id=google_id, verified_email=verified_email,
given_name=given_name, family_name=family_name,
locale=locale)
else:
user = self._db.create_user(username, email=email, google_id=google_id,
verified_email=verified_email, name=name, given_name=given_name,
Expand Down Expand Up @@ -281,8 +282,8 @@ def get(self):
# use this email to associate
user = self._db.get_user(email=email, force_email_no_password=True)
if user:
user["facebook_id"] = facebook_id
self._db.update_user(user)
self._db.add_missing_info_user(user, facebook_id=facebook_id, given_name=given_name,
family_name=family_name, locale=locale)
else:
user = self._db.create_user(username, name=name, given_name=given_name, family_name=family_name,
locale=locale, email=email, facebook_id=facebook_id)
Expand Down Expand Up @@ -356,8 +357,8 @@ def get(self):
# use this email to associate
user = self._db.get_user(email=email, force_email_no_password=True)
if user:
user["twitter_id"] = twitter_id
self._db.update_user(user)
self._db.add_missing_info_user(user, twitter_id=twitter_id, verified_email=verified_email,
locale=locale)
else:
user = self._db.create_user(username, email=email, name=name, verified_email=verified_email,
locale=locale, twitter_id=twitter_id)
Expand Down Expand Up @@ -647,8 +648,8 @@ def post(self):
return

# Update password
current_user["password"] = self._db.generate_password(password)
self._db.update_user(current_user)
updated_password = self._db.generate_password(password)
self._db.add_missing_info_user(current_user, password=updated_password)

# TODO Need to validate insertion
data = {"status": "Password added."}
Expand Down
60 changes: 49 additions & 11 deletions src/web/py_class/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ def create_user(self, username, email=None, password=None, google_id=None, faceb

# TODO let user create it and not automatic create
empty_character = [{
"habilites": [
{}
],
"technique_maitre": [],
"rituel": [],
"xp_naissance": 6,
"xp_autre": 0,
"character_id": "0f173f629ef64fb190bfcef7b7f85697",
"date_modify": 1520689829.9900929928,
"date_creation": 1520689829.9900929928
}]

data = {"email": email, "username": username, "name": name, "given_name": given_name,
Expand All @@ -76,6 +66,54 @@ def create_user(self, username, email=None, password=None, google_id=None, faceb
eid = self._db_user.insert(data)
return self._db_user.get(eid=eid)

def add_missing_info_user(self, obj_user, password=None, google_id=None, facebook_id=None, twitter_id=None,
name=None, given_name=None, family_name=None, verified_email=False, locale=None,
postal_code=None):
has_update = False

if password and not obj_user.get("password"):
obj_user["password"] = password
has_update = True

if google_id and not obj_user.get("google_id"):
obj_user["google_id"] = google_id
has_update = True

if facebook_id and not obj_user.get("facebook_id"):
obj_user["facebook_id"] = facebook_id
has_update = True

if twitter_id and not obj_user.get("twitter_id"):
obj_user["twitter_id"] = twitter_id
has_update = True

if name and not obj_user.get("name"):
obj_user["name"] = name
has_update = True

if given_name and not obj_user.get("given_name"):
obj_user["given_name"] = given_name
has_update = True

if family_name and not obj_user.get("family_name"):
obj_user["family_name"] = family_name
has_update = True

if verified_email and not obj_user.get("verified_email"):
obj_user["verified_email"] = verified_email
has_update = True

if locale and not obj_user.get("locale"):
obj_user["locale"] = locale
has_update = True

if postal_code and not obj_user.get("postal_code"):
obj_user["postal_code"] = postal_code
has_update = True

if has_update:
self.update_user(obj_user)

def get_all_user(self, user_id=None):
if not user_id:
# get all user list
Expand Down Expand Up @@ -168,7 +206,7 @@ def transform(element):
# TODO validate fields in data
if delete_character_by_id:
del lst_character[i]
else:
elif character_data:
lst_character[i] = character_data
# update last modify date
character_data["date_modify"] = datetime.datetime.utcnow().timestamp()
Expand Down

0 comments on commit 8f9d704

Please sign in to comment.