FindSomeone: reject invalid user ID

This commit is contained in:
miruka 2019-12-04 09:59:14 -04:00
parent a992b51ac5
commit b25f3f3e51
3 changed files with 15 additions and 3 deletions

View File

@ -52,6 +52,11 @@ class UserNotFound(Exception):
user_id: str = field()
@dataclass
class InvalidUserId(Exception):
user_id: str = field()
@dataclass
class InvalidUserInContext(Exception):
user_id: str = field()

View File

@ -24,8 +24,8 @@ from nio.crypto import async_generator_from_data
from . import __about__, utils
from .errors import (
BadMimeType, InvalidUserInContext, MatrixError, UneededThumbnail,
UserNotFound,
BadMimeType, InvalidUserId, InvalidUserInContext, MatrixError,
UneededThumbnail, UserNotFound,
)
from .html_filter import HTML_FILTER
from .models.items import (
@ -479,6 +479,9 @@ class MatrixClient(nio.AsyncClient):
if invite == self.user_id:
raise InvalidUserInContext(invite)
if not re.match(r"^@.+:.+", invite):
raise InvalidUserId(invite)
if isinstance(await self.get_profile(invite), nio.ProfileGetError):
raise UserNotFound(invite)

View File

@ -35,6 +35,10 @@ HBox {
if (type === "InvalidUserInContext")
txt = qsTr("You can't invite yourself!")
if (type === "InvalidUserId")
txt = qsTr("Invalid user ID, expected format is " +
"@username:homeserver")
if (type === "UserNotFound")
txt = qsTr("This user does not exist")
@ -61,7 +65,7 @@ HBox {
HTextField {
id: userField
placeholderText: qsTr("User ID (e.g. @john:matrix.org)")
placeholderText: qsTr("User ID (e.g. @bob:matrix.org)")
error: Boolean(errorMessage.text)
Layout.fillWidth: true