fix: вход принимает короткое имя учётной записи, а не только полный адрес

This commit is contained in:
anor
2026-08-17 16:13:41 +10:00
parent 62224f93ab
commit 4fc05c332e
4 changed files with 28 additions and 4 deletions
+3 -3
View File
@@ -56,15 +56,15 @@ export function Login({ onDone }: { onDone: () => void }) {
</span>
</div>
<label htmlFor="login-mail">Корпоративная почта</label>
<label htmlFor="login-mail">Рабочий логин или почта</label>
<input
id="login-mail"
type="email"
type="text"
autoComplete="username"
autoFocus
value={login}
onChange={(event) => setLogin(event.target.value)}
placeholder="имя@mgcgroup.ru"
placeholder="ykazin или ykazin@mgcgroup.ru"
required
/>
+8 -1
View File
@@ -25,7 +25,14 @@ export function normalizeLogin(value) {
export function findAllowed(login, allowed) {
const normalized = normalizeLogin(login);
if (normalized === '') return null;
return (allowed ?? []).find((item) => normalizeLogin(item) === normalized) ?? null;
const list = allowed ?? [];
const exact = list.find((item) => normalizeLogin(item) === normalized);
if (exact) return exact;
// Короткое имя без домена: людям привычнее вводить «ykazin», а не полный
// адрес. Сверяем с частью до собаки - иначе привычный вход отсекался бы
// ещё до каталога, и человек не понимал бы, почему его не пускают.
if (normalized.includes('@')) return null;
return list.find((item) => normalizeLogin(item).split('@')[0] === normalized) ?? null;
}
// Тридцать дней от входа. Срок не скользящий: панель сама себя опрашивает
+14
View File
@@ -55,3 +55,17 @@ test('короткий ключ подписи не принимается', ()
// иначе ключом станет «пароль123», и метку подделает кто угодно
assert.throws(() => signSession('ykazin@mgcgroup.ru', { key: 'коротко', now: 0 }), /ключ/i);
});
test('короткое имя без домена тоже пускает к проверке', () => {
// человеку привычнее ввести «ykazin»: если отсечь его до каталога,
// он будет получать отказ с верным паролем и не поймёт причины
assert.equal(findAllowed('ykazin', allowed), 'YKazin@mgcgroup.ru');
assert.equal(findAllowed(' YKAZIN ', allowed), 'YKazin@mgcgroup.ru');
assert.equal(findAllowed('asmuslov', allowed), 'ASmuslov@mgcgroup.ru');
});
test('короткое имя постороннего по-прежнему не проходит', () => {
assert.equal(findAllowed('director', allowed), null);
// чужой домен с нашим коротким именем - не наш человек
assert.equal(findAllowed('ykazin@other.ru', allowed), null);
});
+3
View File
@@ -136,6 +136,9 @@ export async function checkPassword({
buildSearchRequest(2, searchBase, [
{ attribute: 'userPrincipalName', value: login },
{ attribute: 'mail', value: login },
// короткое имя без домена: людям привычнее вводить «ykazin»,
// а не полный адрес - на этом спотыкаются в первую очередь
{ attribute: 'sAMAccountName', value: String(login).split('@')[0] },
], ['userPrincipalName', 'mail', 'displayName', 'userAccountControl']),
(message) => message.protocolOp === 0x65, timeoutMs);
const entry = found.find((message) => message.entry)?.entry ?? null;