Skip to content

Commit 4427b3b

Browse files
committed
Accept mxid on login (#187)
1 parent 3dda4d6 commit 4427b3b

File tree

3 files changed

+33
-31
lines changed

3 files changed

+33
-31
lines changed

config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
2-
"defaultHomeserver": 4,
2+
"defaultHomeserver": 3,
33
"homeserverList": [
4-
"converser.eu",
54
"envs.net",
65
"halogen.city",
76
"kde.org",

src/app/templates/auth/Auth.jsx

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,8 @@ function Homeserver({ onChange }) {
5656
const setupHsConfig = async (servername) => {
5757
setProcess({ isLoading: true, message: 'Looking for homeserver...' });
5858
let baseUrl = null;
59-
try {
60-
baseUrl = await getBaseUrl(servername);
61-
} catch (e) {
62-
baseUrl = e.message;
63-
}
59+
baseUrl = await getBaseUrl(servername);
60+
6461
if (searchingHs !== servername) return;
6562
setProcess({ isLoading: true, message: `Connecting to ${baseUrl}...` });
6663
const tempClient = auth.createTemporaryClient(baseUrl);
@@ -175,31 +172,38 @@ function Login({ loginFlow, baseUrl }) {
175172

176173
const validator = (values) => {
177174
const errors = {};
178-
if (typeIndex === 0 && values.username.length > 0 && values.username.indexOf(':') > -1) {
179-
errors.username = 'Username must contain local-part only';
180-
}
181175
if (typeIndex === 1 && values.email.length > 0 && !isValidInput(values.email, EMAIL_REGEX)) {
182176
errors.email = BAD_EMAIL_ERROR;
183177
}
184178
return errors;
185179
};
186-
const submitter = (values, actions) => auth.login(
187-
baseUrl,
188-
typeIndex === 0 ? normalizeUsername(values.username) : undefined,
189-
typeIndex === 1 ? values.email : undefined,
190-
values.password,
191-
).then(() => {
192-
actions.setSubmitting(true);
193-
window.location.reload();
194-
}).catch((error) => {
195-
let msg = error.message;
196-
if (msg === 'Unknown message') msg = 'Please check your credentials';
197-
actions.setErrors({
198-
password: msg === 'Invalid password' ? msg : undefined,
199-
other: msg !== 'Invalid password' ? msg : undefined,
180+
const submitter = async (values, actions) => {
181+
let userBaseUrl = baseUrl;
182+
let { username } = values;
183+
const mxIdMatch = username.match(/^@(.+):(.+\..+)$/);
184+
if (typeIndex === 0 && mxIdMatch) {
185+
[, username, userBaseUrl] = mxIdMatch;
186+
userBaseUrl = await getBaseUrl(userBaseUrl);
187+
}
188+
189+
return auth.login(
190+
userBaseUrl,
191+
typeIndex === 0 ? normalizeUsername(username) : undefined,
192+
typeIndex === 1 ? values.email : undefined,
193+
values.password,
194+
).then(() => {
195+
actions.setSubmitting(true);
196+
window.location.reload();
197+
}).catch((error) => {
198+
let msg = error.message;
199+
if (msg === 'Unknown message') msg = 'Please check your credentials';
200+
actions.setErrors({
201+
password: msg === 'Invalid password' ? msg : undefined,
202+
other: msg !== 'Invalid password' ? msg : undefined,
203+
});
204+
actions.setSubmitting(false);
200205
});
201-
actions.setSubmitting(false);
202-
});
206+
};
203207

204208
return (
205209
<>

src/util/matrixUtil.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function getBaseUrl(servername) {
2020
if (baseUrl === undefined) throw new Error();
2121
return baseUrl;
2222
} catch (e) {
23-
throw new Error(`${protocol}${servername}`);
23+
return `${protocol}${servername}`;
2424
}
2525
}
2626

@@ -204,11 +204,10 @@ export async function hasDevices(userId) {
204204
const mx = initMatrix.matrixClient;
205205
try {
206206
const usersDeviceMap = await mx.downloadKeys([userId, mx.getUserId()]);
207-
return Object.values(usersDeviceMap).every((userDevices) =>
208-
Object.keys(userDevices).length > 0,
209-
);
207+
return Object.values(usersDeviceMap)
208+
.every((userDevices) => (Object.keys(userDevices).length > 0));
210209
} catch (e) {
211210
console.error("Error determining if it's possible to encrypt to all users: ", e);
212211
return false;
213212
}
214-
}
213+
}

0 commit comments

Comments
 (0)