Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Optionally include password hash in createUser endpoint #905

Merged
merged 3 commits into from
Jul 4, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def _submit_captcha(self, ip_addr, private_key, challenge, response):
defer.returnValue(data)

@defer.inlineCallbacks
def get_or_create_user(self, localpart, displayname, duration_seconds):
def get_or_create_user(self, localpart, displayname, duration_seconds, password_hash=None):
"""Creates a new user if the user does not exist,
else revokes all previous access tokens and generates a new one.

Expand Down Expand Up @@ -394,7 +394,7 @@ def get_or_create_user(self, localpart, displayname, duration_seconds):
yield self.store.register(
user_id=user_id,
token=token,
password_hash=None,
password_hash=password_hash,
create_profile_with_localpart=user.localpart,
)
else:
Expand Down
4 changes: 3 additions & 1 deletion synapse/rest/client/v1/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,14 @@ def _do_create(self, user_json):
raise SynapseError(400, "Failed to parse 'duration_seconds'")
if duration_seconds > self.direct_user_creation_max_duration:
duration_seconds = self.direct_user_creation_max_duration
password_hash = user_json["password_hash"].encode("utf-8") if user_json["password_hash"] else None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to do:

... if user_json.get("password_hash") else None

So that it doesn't explode if no password_hash key is present.


handler = self.handlers.registration_handler
user_id, token = yield handler.get_or_create_user(
localpart=localpart,
displayname=displayname,
duration_seconds=duration_seconds
duration_seconds=duration_seconds,
password_hash=password_hash
)

defer.returnValue({
Expand Down