FindSomeone: reject invalid user ID
This commit is contained in:
parent
a992b51ac5
commit
b25f3f3e51
|
@ -52,6 +52,11 @@ class UserNotFound(Exception):
|
||||||
user_id: str = field()
|
user_id: str = field()
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class InvalidUserId(Exception):
|
||||||
|
user_id: str = field()
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class InvalidUserInContext(Exception):
|
class InvalidUserInContext(Exception):
|
||||||
user_id: str = field()
|
user_id: str = field()
|
||||||
|
|
|
@ -24,8 +24,8 @@ from nio.crypto import async_generator_from_data
|
||||||
|
|
||||||
from . import __about__, utils
|
from . import __about__, utils
|
||||||
from .errors import (
|
from .errors import (
|
||||||
BadMimeType, InvalidUserInContext, MatrixError, UneededThumbnail,
|
BadMimeType, InvalidUserId, InvalidUserInContext, MatrixError,
|
||||||
UserNotFound,
|
UneededThumbnail, UserNotFound,
|
||||||
)
|
)
|
||||||
from .html_filter import HTML_FILTER
|
from .html_filter import HTML_FILTER
|
||||||
from .models.items import (
|
from .models.items import (
|
||||||
|
@ -479,6 +479,9 @@ class MatrixClient(nio.AsyncClient):
|
||||||
if invite == self.user_id:
|
if invite == self.user_id:
|
||||||
raise InvalidUserInContext(invite)
|
raise InvalidUserInContext(invite)
|
||||||
|
|
||||||
|
if not re.match(r"^@.+:.+", invite):
|
||||||
|
raise InvalidUserId(invite)
|
||||||
|
|
||||||
if isinstance(await self.get_profile(invite), nio.ProfileGetError):
|
if isinstance(await self.get_profile(invite), nio.ProfileGetError):
|
||||||
raise UserNotFound(invite)
|
raise UserNotFound(invite)
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,10 @@ HBox {
|
||||||
if (type === "InvalidUserInContext")
|
if (type === "InvalidUserInContext")
|
||||||
txt = qsTr("You can't invite yourself!")
|
txt = qsTr("You can't invite yourself!")
|
||||||
|
|
||||||
|
if (type === "InvalidUserId")
|
||||||
|
txt = qsTr("Invalid user ID, expected format is " +
|
||||||
|
"@username:homeserver")
|
||||||
|
|
||||||
if (type === "UserNotFound")
|
if (type === "UserNotFound")
|
||||||
txt = qsTr("This user does not exist")
|
txt = qsTr("This user does not exist")
|
||||||
|
|
||||||
|
@ -61,7 +65,7 @@ HBox {
|
||||||
|
|
||||||
HTextField {
|
HTextField {
|
||||||
id: userField
|
id: userField
|
||||||
placeholderText: qsTr("User ID (e.g. @john:matrix.org)")
|
placeholderText: qsTr("User ID (e.g. @bob:matrix.org)")
|
||||||
error: Boolean(errorMessage.text)
|
error: Boolean(errorMessage.text)
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
Loading…
Reference in New Issue
Block a user