Make getting started more user-friendly. Fixes #327
This commit is contained in:
@@ -126,41 +126,20 @@ async def login(evt: CommandEvent) -> Optional[Dict]:
|
|||||||
if evt.config["appservice.public.enabled"]:
|
if evt.config["appservice.public.enabled"]:
|
||||||
prefix = evt.config["appservice.public.external"]
|
prefix = evt.config["appservice.public.external"]
|
||||||
url = f"{prefix}/login?token={evt.public_website.make_token(evt.sender.mxid, '/login')}"
|
url = f"{prefix}/login?token={evt.public_website.make_token(evt.sender.mxid, '/login')}"
|
||||||
if allow_matrix_login:
|
|
||||||
if override_sender:
|
|
||||||
return await evt.reply(
|
|
||||||
"This bridge instance allows you to log in inside or outside of Matrix, but "
|
|
||||||
"logging in as another user is only possible via the web interface.\n\n"
|
|
||||||
f"Please visit [the login page]({url}) to log in as "
|
|
||||||
f"[{evt.sender.mxid}](https://matrix.to/#/{evt.sender.mxid}).\n\n")
|
|
||||||
return await evt.reply(
|
|
||||||
"This bridge instance allows you to log in inside or outside Matrix.\n\n"
|
|
||||||
"If you would like to log in within Matrix, please send your phone number or bot "
|
|
||||||
"auth token here.\n"
|
|
||||||
"If you would like to log in outside of Matrix, please visit [the login page]"
|
|
||||||
f"({url}).\n\n"
|
|
||||||
"Logging in outside of Matrix is recommended if you have two-factor authentication "
|
|
||||||
"enabled, because in-Matrix login would save your password in the message history."
|
|
||||||
f"\n\n{nb}")
|
|
||||||
if override_sender:
|
if override_sender:
|
||||||
return await evt.reply(
|
return await evt.reply(f"[Click here to log in]({url}) as "
|
||||||
"This bridge instance does not allow logging in inside Matrix, and logging in as "
|
f"[{evt.sender.mxid}](https://matrix.to/#/{evt.sender.mxid}).")
|
||||||
"another user inside Matrix isn't possible anyway.\n\n"
|
elif allow_matrix_login:
|
||||||
f"Please visit [the login page]({url}) to log in as "
|
return await evt.reply(f"[Click here to log in]({url}). Alternatively, send your phone"
|
||||||
f"[{evt.sender.mxid}](https://matrix.to/#/{evt.sender.mxid}).")
|
f" number (or bot auth token) here to log in.\n\n{nb}")
|
||||||
return await evt.reply(
|
return await evt.reply(f"[Click here to log in]({url}).\n\n{nb}")
|
||||||
"This bridge instance does not allow logging in inside Matrix.\n\n"
|
|
||||||
f"Please visit [the login page]({url}) to log in.\n\n"
|
|
||||||
f"{nb}")
|
|
||||||
elif allow_matrix_login:
|
elif allow_matrix_login:
|
||||||
if override_sender:
|
if override_sender:
|
||||||
return await evt.reply(
|
return await evt.reply(
|
||||||
"This bridge instance does not allow you to log in outside of Matrix. "
|
"This bridge instance does not allow you to log in outside of Matrix. "
|
||||||
"Logging in as another user inside Matrix is not currently possible.")
|
"Logging in as another user inside Matrix is not currently possible.")
|
||||||
return await evt.reply(
|
return await evt.reply("Please send your phone number (or bot auth token) here to start "
|
||||||
"This bridge instance does not allow you to log in outside of Matrix.\n\n"
|
f"the login process.\n\n{nb}")
|
||||||
"Please send your phone number or bot auth token here to start the login process.\n\n"
|
|
||||||
f"{nb}")
|
|
||||||
return await evt.reply("This bridge instance has been configured to not allow logging in.")
|
return await evt.reply("This bridge instance has been configured to not allow logging in.")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -136,12 +136,31 @@ class MatrixHandler:
|
|||||||
|
|
||||||
if not inviter.whitelisted:
|
if not inviter.whitelisted:
|
||||||
await self.az.intent.send_notice(
|
await self.az.intent.send_notice(
|
||||||
room_id, text="",
|
room_id,
|
||||||
html="You are not whitelisted to use this bridge.<br/><br/>"
|
text="You are not whitelisted to use this bridge.\n\n"
|
||||||
"If you are the owner of this bridge, see the "
|
"If you are the owner of this bridge, see the "
|
||||||
"<code>bridge.permissions</code> section in your config file.")
|
"`bridge.permissions` section in your config file.",
|
||||||
|
html="<p>You are not whitelisted to use this bridge.</p>"
|
||||||
|
"<p>If you are the owner of this bridge, see the "
|
||||||
|
"<code>bridge.permissions</code> section in your config file.</p>")
|
||||||
await self.az.intent.leave_room(room_id)
|
await self.az.intent.leave_room(room_id)
|
||||||
|
|
||||||
|
try:
|
||||||
|
is_management = len(await self.az.intent.get_room_members(room_id)) == 2
|
||||||
|
except MatrixRequestError:
|
||||||
|
is_management = False
|
||||||
|
cmd_prefix = self.commands.command_prefix
|
||||||
|
text = html = "Hello, I'm a Telegram bridge bot. "
|
||||||
|
if is_management and inviter.puppet_whitelisted and not await inviter.is_logged_in():
|
||||||
|
text += f"Use `{cmd_prefix} help` for help or `{cmd_prefix} login` to log in."
|
||||||
|
html += (f"Use <code>{cmd_prefix} help</code> for help"
|
||||||
|
f" or <code>{cmd_prefix} login</code> to log in.")
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
text += f"Use `{cmd_prefix} help` for help."
|
||||||
|
html += f"Use <code>{cmd_prefix} help</code> for help."
|
||||||
|
await self.az.intent.send_notice(room_id, text=text, html=html)
|
||||||
|
|
||||||
async def handle_invite(self, room_id: MatrixRoomID, user_id: MatrixUserID,
|
async def handle_invite(self, room_id: MatrixRoomID, user_id: MatrixUserID,
|
||||||
inviter_mxid: MatrixUserID) -> None:
|
inviter_mxid: MatrixUserID) -> None:
|
||||||
self.log.debug(f"{inviter_mxid} invited {user_id} to {room_id}")
|
self.log.debug(f"{inviter_mxid} invited {user_id} to {room_id}")
|
||||||
|
|||||||
@@ -79,7 +79,8 @@ class AuthAPI(abc.ABC):
|
|||||||
try:
|
try:
|
||||||
await user.client.sign_in(phone.strip())
|
await user.client.sign_in(phone.strip())
|
||||||
return self.get_login_response(mxid=user.mxid, state="code", status=200,
|
return self.get_login_response(mxid=user.mxid, state="code", status=200,
|
||||||
message="Code requested successfully.")
|
message="Code requested successfully. Check your SMS "
|
||||||
|
"or Telegram client and enter the code below.")
|
||||||
except PhoneNumberInvalidError:
|
except PhoneNumberInvalidError:
|
||||||
return self.get_login_response(mxid=user.mxid, state="request", status=400,
|
return self.get_login_response(mxid=user.mxid, state="request", status=400,
|
||||||
errcode="phone_number_invalid",
|
errcode="phone_number_invalid",
|
||||||
|
|||||||
@@ -95,8 +95,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
% if state == "request":
|
% if state == "request":
|
||||||
<label for="value">Phone number</label>
|
<label for="value">Phone number</label>
|
||||||
<input type="tel" id="value" name="phone" placeholder="Enter phone number"/>
|
<input type="tel" id="value" name="phone" placeholder="Enter phone number"/>
|
||||||
<button type="submit">Request code</button>
|
<button type="submit">Start</button>
|
||||||
<button class="button-clear" type="button" onclick="switchToBotLogin()">
|
<button class="button-clear float-right" type="button" onclick="switchToBotLogin()">
|
||||||
Use bot token
|
Use bot token
|
||||||
</button>
|
</button>
|
||||||
% elif state == "bot_token":
|
% elif state == "bot_token":
|
||||||
|
|||||||
Reference in New Issue
Block a user