Strip leading @ from password reset input
This commit is contained in:
parent
3509fd1c6e
commit
c19fe9f167
4 changed files with 26 additions and 13 deletions
|
@ -20,6 +20,7 @@ import KVStore from 'soapbox/storage/kv_store';
|
|||
import { getLoggedInAccount, parseBaseURL } from 'soapbox/utils/auth';
|
||||
import sourceCode from 'soapbox/utils/code';
|
||||
import { getFeatures } from 'soapbox/utils/features';
|
||||
import { normalizeUsername } from 'soapbox/utils/input';
|
||||
import { isStandalone } from 'soapbox/utils/state';
|
||||
|
||||
import api, { baseClient } from '../api';
|
||||
|
@ -207,16 +208,6 @@ export const loadCredentials = (token: string, accountUrl: string) =>
|
|||
})
|
||||
.catch(() => dispatch(verifyCredentials(token, accountUrl)));
|
||||
|
||||
/** Trim the username and strip the leading @. */
|
||||
const normalizeUsername = (username: string): string => {
|
||||
const trimmed = username.trim();
|
||||
if (trimmed[0] === '@') {
|
||||
return trimmed.slice(1);
|
||||
} else {
|
||||
return trimmed;
|
||||
}
|
||||
};
|
||||
|
||||
export const logIn = (username: string, password: string) =>
|
||||
(dispatch: AppDispatch) => dispatch(getAuthApp()).then(() => {
|
||||
return dispatch(createUserToken(normalizeUsername(username), password));
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
import snackbar from 'soapbox/actions/snackbar';
|
||||
import { getLoggedInAccount } from 'soapbox/utils/auth';
|
||||
import { parseVersion, TRUTHSOCIAL } from 'soapbox/utils/features';
|
||||
import { normalizeUsername } from 'soapbox/utils/input';
|
||||
|
||||
import api from '../api';
|
||||
|
||||
|
@ -84,15 +85,16 @@ const changePassword = (oldPassword: string, newPassword: string, confirmation:
|
|||
|
||||
const resetPassword = (usernameOrEmail: string) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
const input = normalizeUsername(usernameOrEmail);
|
||||
const state = getState();
|
||||
const v = parseVersion(state.instance.version);
|
||||
|
||||
dispatch({ type: RESET_PASSWORD_REQUEST });
|
||||
|
||||
const params =
|
||||
usernameOrEmail.includes('@')
|
||||
? { email: usernameOrEmail }
|
||||
: { nickname: usernameOrEmail, username: usernameOrEmail };
|
||||
input.includes('@')
|
||||
? { email: input }
|
||||
: { nickname: input, username: input };
|
||||
|
||||
const endpoint =
|
||||
v.software === TRUTHSOCIAL
|
||||
|
|
7
app/soapbox/utils/__tests__/input.test.ts
Normal file
7
app/soapbox/utils/__tests__/input.test.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { normalizeUsername } from '../input';
|
||||
|
||||
test('normalizeUsername', () => {
|
||||
expect(normalizeUsername('@alex')).toBe('alex');
|
||||
expect(normalizeUsername('alex@alexgleason.me')).toBe('alex@alexgleason.me');
|
||||
expect(normalizeUsername('@alex@gleasonator.com')).toBe('alex@gleasonator.com');
|
||||
});
|
13
app/soapbox/utils/input.ts
Normal file
13
app/soapbox/utils/input.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
/** Trim the username and strip the leading @. */
|
||||
const normalizeUsername = (username: string): string => {
|
||||
const trimmed = username.trim();
|
||||
if (trimmed[0] === '@') {
|
||||
return trimmed.slice(1);
|
||||
} else {
|
||||
return trimmed;
|
||||
}
|
||||
};
|
||||
|
||||
export {
|
||||
normalizeUsername,
|
||||
};
|
Loading…
Reference in a new issue