ensure that user is in default-rooms on login
This commit is contained in:
parent
efeed17537
commit
48f83239ef
|
@ -16,6 +16,8 @@ modules:
|
||||||
ppfunurl: "http://local.pixelplanet.url:port"
|
ppfunurl: "http://local.pixelplanet.url:port"
|
||||||
# if true, only mail-verified users can log in
|
# if true, only mail-verified users can log in
|
||||||
verified: true
|
verified: true
|
||||||
|
# rooms that will be automatically joined on login
|
||||||
|
autojoin_rooms: ['#pp_en:pixelplanet.fun', '#pp_int:pixelplanet.fun']
|
||||||
```
|
```
|
||||||
## References
|
## References
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,12 @@
|
||||||
# All the self.api._underline using methods could break on updates
|
# All the self.api._underline using methods could break on updates
|
||||||
#
|
#
|
||||||
|
|
||||||
from typing import Awaitable, Callable, Optional, Tuple
|
from typing import Awaitable, Callable, Optional, Tuple, List
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import synapse
|
import synapse
|
||||||
from synapse import module_api
|
from synapse import module_api
|
||||||
|
from synapse.types import RoomAlias
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -26,11 +27,9 @@ class PPfunAuthProvider:
|
||||||
self.check_verified = config['verified']
|
self.check_verified = config['verified']
|
||||||
else:
|
else:
|
||||||
self.check_verified = False
|
self.check_verified = False
|
||||||
|
if 'autojoin_rooms' in config:
|
||||||
self.credentials = {
|
self.parsed_rooms = False
|
||||||
"bob": "building",
|
self.autojoin_rooms = config["autojoin_rooms"]
|
||||||
"@scoop:matrix.org": "digging",
|
|
||||||
}
|
|
||||||
|
|
||||||
api.register_password_auth_provider_callbacks(
|
api.register_password_auth_provider_callbacks(
|
||||||
check_3pid_auth = self.check_3pid_pass,
|
check_3pid_auth = self.check_3pid_pass,
|
||||||
|
@ -39,6 +38,21 @@ class PPfunAuthProvider:
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# resolve room_aliases to room_ids
|
||||||
|
async def translate_room_aliases_to_ids(
|
||||||
|
self,
|
||||||
|
room_aliases: List[str],
|
||||||
|
) -> List[str]:
|
||||||
|
room_ids = []
|
||||||
|
logger.info('Translating room_aliases to ids')
|
||||||
|
for alias in room_aliases:
|
||||||
|
aliasObject = RoomAlias.from_string(alias)
|
||||||
|
room = await self.api._store.get_association_from_room_alias(aliasObject)
|
||||||
|
if room is not None:
|
||||||
|
logger.info('Map alias %s to room %s', alias, room.room_id)
|
||||||
|
room_ids.append(room.room_id)
|
||||||
|
return room_ids;
|
||||||
|
|
||||||
async def check_credentials(
|
async def check_credentials(
|
||||||
self,
|
self,
|
||||||
query,
|
query,
|
||||||
|
@ -87,11 +101,21 @@ class PPfunAuthProvider:
|
||||||
await registration_handler._register_email_threepid(user_id, threepid_dict, None)
|
await registration_handler._register_email_threepid(user_id, threepid_dict, None)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
async def join_auto_rooms(
|
||||||
|
self,
|
||||||
|
user_id: str,
|
||||||
|
) -> None:
|
||||||
|
if not self.parsed_rooms:
|
||||||
|
self.autojoin_rooms = await self.translate_room_aliases_to_ids(self.autojoin_rooms)
|
||||||
|
self.parsed_rooms = True
|
||||||
|
for room_id in self.autojoin_rooms:
|
||||||
|
await self.api.update_room_membership(user_id, user_id, room_id, 'join')
|
||||||
|
|
||||||
async def login(
|
async def login(
|
||||||
self,
|
self,
|
||||||
ppfun_id,
|
ppfun_id: str,
|
||||||
ppfun_name,
|
ppfun_name: str,
|
||||||
ppfun_email,
|
ppfun_email: str,
|
||||||
) -> Optional[
|
) -> Optional[
|
||||||
Tuple[
|
Tuple[
|
||||||
str,
|
str,
|
||||||
|
@ -114,6 +138,7 @@ class PPfunAuthProvider:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
await self.set_email(user_id, ppfun_email)
|
await self.set_email(user_id, ppfun_email)
|
||||||
|
await self.join_auto_rooms(user_id)
|
||||||
logger.info('User %s logged in via ppfun %s', user_id, ppfun_name)
|
logger.info('User %s logged in via ppfun %s', user_id, ppfun_name)
|
||||||
return user_id, None
|
return user_id, None
|
||||||
|
|
||||||
|
@ -159,7 +184,7 @@ class PPfunAuthProvider:
|
||||||
}
|
}
|
||||||
if username.startswith('@pp_'):
|
if username.startswith('@pp_'):
|
||||||
query['id'] = username[4: username.index(':')]
|
query['id'] = username[4: username.index(':')]
|
||||||
elif username.startswith('pp_') and username.endswith(f':{self.api._server_name}'):
|
elif username.startswith('pp_') and username.endswith(f':{self.api.server_name}'):
|
||||||
query['id'] = username[3: username.index(':')]
|
query['id'] = username[3: username.index(':')]
|
||||||
else:
|
else:
|
||||||
query['name'] = username
|
query['name'] = username
|
||||||
|
|
Loading…
Reference in New Issue
Block a user