Accept mxid on login (#187)
This commit is contained in:
parent
3dda4d6540
commit
4427b3b291
3 changed files with 33 additions and 31 deletions
|
@ -1,7 +1,6 @@
|
||||||
{
|
{
|
||||||
"defaultHomeserver": 4,
|
"defaultHomeserver": 3,
|
||||||
"homeserverList": [
|
"homeserverList": [
|
||||||
"converser.eu",
|
|
||||||
"envs.net",
|
"envs.net",
|
||||||
"halogen.city",
|
"halogen.city",
|
||||||
"kde.org",
|
"kde.org",
|
||||||
|
|
|
@ -56,11 +56,8 @@ function Homeserver({ onChange }) {
|
||||||
const setupHsConfig = async (servername) => {
|
const setupHsConfig = async (servername) => {
|
||||||
setProcess({ isLoading: true, message: 'Looking for homeserver...' });
|
setProcess({ isLoading: true, message: 'Looking for homeserver...' });
|
||||||
let baseUrl = null;
|
let baseUrl = null;
|
||||||
try {
|
baseUrl = await getBaseUrl(servername);
|
||||||
baseUrl = await getBaseUrl(servername);
|
|
||||||
} catch (e) {
|
|
||||||
baseUrl = e.message;
|
|
||||||
}
|
|
||||||
if (searchingHs !== servername) return;
|
if (searchingHs !== servername) return;
|
||||||
setProcess({ isLoading: true, message: `Connecting to ${baseUrl}...` });
|
setProcess({ isLoading: true, message: `Connecting to ${baseUrl}...` });
|
||||||
const tempClient = auth.createTemporaryClient(baseUrl);
|
const tempClient = auth.createTemporaryClient(baseUrl);
|
||||||
|
@ -175,31 +172,38 @@ function Login({ loginFlow, baseUrl }) {
|
||||||
|
|
||||||
const validator = (values) => {
|
const validator = (values) => {
|
||||||
const errors = {};
|
const errors = {};
|
||||||
if (typeIndex === 0 && values.username.length > 0 && values.username.indexOf(':') > -1) {
|
|
||||||
errors.username = 'Username must contain local-part only';
|
|
||||||
}
|
|
||||||
if (typeIndex === 1 && values.email.length > 0 && !isValidInput(values.email, EMAIL_REGEX)) {
|
if (typeIndex === 1 && values.email.length > 0 && !isValidInput(values.email, EMAIL_REGEX)) {
|
||||||
errors.email = BAD_EMAIL_ERROR;
|
errors.email = BAD_EMAIL_ERROR;
|
||||||
}
|
}
|
||||||
return errors;
|
return errors;
|
||||||
};
|
};
|
||||||
const submitter = (values, actions) => auth.login(
|
const submitter = async (values, actions) => {
|
||||||
baseUrl,
|
let userBaseUrl = baseUrl;
|
||||||
typeIndex === 0 ? normalizeUsername(values.username) : undefined,
|
let { username } = values;
|
||||||
typeIndex === 1 ? values.email : undefined,
|
const mxIdMatch = username.match(/^@(.+):(.+\..+)$/);
|
||||||
values.password,
|
if (typeIndex === 0 && mxIdMatch) {
|
||||||
).then(() => {
|
[, username, userBaseUrl] = mxIdMatch;
|
||||||
actions.setSubmitting(true);
|
userBaseUrl = await getBaseUrl(userBaseUrl);
|
||||||
window.location.reload();
|
}
|
||||||
}).catch((error) => {
|
|
||||||
let msg = error.message;
|
return auth.login(
|
||||||
if (msg === 'Unknown message') msg = 'Please check your credentials';
|
userBaseUrl,
|
||||||
actions.setErrors({
|
typeIndex === 0 ? normalizeUsername(username) : undefined,
|
||||||
password: msg === 'Invalid password' ? msg : undefined,
|
typeIndex === 1 ? values.email : undefined,
|
||||||
other: msg !== 'Invalid password' ? msg : undefined,
|
values.password,
|
||||||
|
).then(() => {
|
||||||
|
actions.setSubmitting(true);
|
||||||
|
window.location.reload();
|
||||||
|
}).catch((error) => {
|
||||||
|
let msg = error.message;
|
||||||
|
if (msg === 'Unknown message') msg = 'Please check your credentials';
|
||||||
|
actions.setErrors({
|
||||||
|
password: msg === 'Invalid password' ? msg : undefined,
|
||||||
|
other: msg !== 'Invalid password' ? msg : undefined,
|
||||||
|
});
|
||||||
|
actions.setSubmitting(false);
|
||||||
});
|
});
|
||||||
actions.setSubmitting(false);
|
};
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -20,7 +20,7 @@ export async function getBaseUrl(servername) {
|
||||||
if (baseUrl === undefined) throw new Error();
|
if (baseUrl === undefined) throw new Error();
|
||||||
return baseUrl;
|
return baseUrl;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`${protocol}${servername}`);
|
return `${protocol}${servername}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,11 +204,10 @@ export async function hasDevices(userId) {
|
||||||
const mx = initMatrix.matrixClient;
|
const mx = initMatrix.matrixClient;
|
||||||
try {
|
try {
|
||||||
const usersDeviceMap = await mx.downloadKeys([userId, mx.getUserId()]);
|
const usersDeviceMap = await mx.downloadKeys([userId, mx.getUserId()]);
|
||||||
return Object.values(usersDeviceMap).every((userDevices) =>
|
return Object.values(usersDeviceMap)
|
||||||
Object.keys(userDevices).length > 0,
|
.every((userDevices) => (Object.keys(userDevices).length > 0));
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error determining if it's possible to encrypt to all users: ", e);
|
console.error("Error determining if it's possible to encrypt to all users: ", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue