Profile auto-fill improvements

jdbi_and_liquibase
Maxime Dor 7 years ago
parent 1f50fe0c1b
commit 83cb8bfce2

@ -15,7 +15,6 @@ If you installed synapse using the Matrix debian repos:
```
git clone https://github.com/maxidor/matrix-synapse-rest-auth.git
cd matrix-synapse-rest-auth
sudo cp rest_auth_provider.py /usr/lib/python2.6/dist-packages/
sudo cp rest_auth_provider.py /usr/lib/python2.7/dist-packages/
```
@ -26,20 +25,48 @@ password_providers:
- module: "rest_auth_provider.RestAuthProvider"
config:
endpoint: "http://change.me.example.com:12345"
```
Set `endpoint` to the appropriate value.
## Use
1. Install, configure, restart synapse
2. Try to login with a valid username and password for the endpoint configured
## Next steps
### Lowercase username enforcement
If you would like to avoid user creating accounts with upper case letter in their usernames,
use the `enforceLowercase` config item.
It is highly recommended to enable this option to avoid nasty case sensitivity bugs and invites
management on a day-to-day basis.
```
[...]
config:
policy:
registration:
username:
enforceLowercase: false
enforceLowercase: True
```
Replace the `endpoint` value with the appropriate value.
### Profile auto-fill
By default, on first login, the display name is set to the one returned by the backend.
If none is given, the display name is not set.
Upon subsequent login, the display name is not changed.
If you would like to avoid user creating account with upper case letter in their usernames,
use the `enforceLowercase` config item.
If you would like to change the behaviour, you can use the following configuration items:
```
[...]
config:
policy:
registration:
profile:
name: True
login:
profile:
name: False
```
## Use
1. Install, configure, restart synapse
2. Try to login with a valid username and password for the endpoint configured
3PIDs received from the backend are merged with the ones already linked to the account.
## Integrate
To use this module with your backend, you will need to implement a single REST endpoint:
@ -80,4 +107,4 @@ The following JSON answer will be provided:
```
## Support
For community support, use the Matrix room [#matrix-synapse-rest-auth:kamax.io](https://matrix.to/#/#matrix-synapse-rest-auth:kamax.io)
For community support, visit our Matrix room [#matrix-synapse-rest-auth:kamax.io](https://matrix.to/#/#matrix-synapse-rest-auth:kamax.io)

@ -36,6 +36,7 @@ class RestAuthProvider(object):
self.endpoint = config.endpoint
self.regLower = config.regLower
self.config = config
logger.info('Endpoint: %s', self.endpoint)
logger.info('Enforce lowercase username during registration: %s', self.regLower)
@ -60,6 +61,7 @@ class RestAuthProvider(object):
localpart = user_id.split(":", 1)[0][1:]
logger.info("User %s authenticated", user_id)
registration = False
if not (yield self.account_handler.check_user_exists(user_id)):
logger.info("User %s does not exist yet, creating...", user_id)
@ -68,6 +70,7 @@ class RestAuthProvider(object):
defer.returnValue(False)
user_id, access_token = (yield self.account_handler.register(localpart=localpart))
registration = True
logger.info("Registration based on REST data was successful for %s", user_id)
else:
logger.info("User %s already exists, registration skipped", user_id)
@ -77,10 +80,12 @@ class RestAuthProvider(object):
profile = auth["profile"]
store = yield self.account_handler.hs.get_handlers().profile_handler.store
if "display_name" in profile:
if "display_name" in profile and ((registration and self.config.setNameOnRegister) or (self.config.setNameOnLogin)):
display_name = profile["display_name"]
logger.info("Setting display name to '%s' based on profile data", display_name)
yield store.set_profile_displayname(localpart, display_name)
else:
logger.info("Display name was not set because it was not given or policy restricted it")
if "three_pids" in profile:
logger.info("Handling 3PIDs")
@ -114,6 +119,8 @@ class RestAuthProvider(object):
class _RestConfig(object):
endpoint = ''
regLower = False
setNameOnRegister = True
setNameOnLogin = False
rest_config = _RestConfig()
rest_config.endpoint = config["endpoint"]
@ -127,6 +134,24 @@ class RestAuthProvider(object):
# we don't care
pass
try:
rest_config.setNameOnRegister = config['policy']['registration']['profile']['name']
except TypeError:
# we don't care
pass
except KeyError:
# we don't care
pass
try:
rest_config.setNameOnLogin = config['policy']['login']['profile']['name']
except TypeError:
# we don't care
pass
except KeyError:
# we don't care
pass
return rest_config
def _require_keys(config, required):

Loading…
Cancel
Save