mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-27 23:40:28 +05:30
#327: allow restore-password access for everyone. Update auth.login state, after forgot-password submit
This commit is contained in:
parent
258c0a7a5f
commit
b4bbbe3372
@ -10,8 +10,13 @@ export default class ForgotPasswordState extends AbstractState {
|
||||
}
|
||||
|
||||
resolve(context, payload = {}) {
|
||||
context.run('forgotPassword', {login: payload.email || this.getLogin(context)})
|
||||
.then(() => context.setState(new RecoverPasswordState()))
|
||||
const login = payload.email || this.getLogin(context);
|
||||
|
||||
context.run('forgotPassword', {login})
|
||||
.then(() => {
|
||||
context.run('setLogin', login);
|
||||
context.setState(new RecoverPasswordState());
|
||||
})
|
||||
.catch((err = {}) =>
|
||||
err.errors || logger.warn('Error requesting password recoverage', err)
|
||||
);
|
||||
|
@ -6,16 +6,10 @@ import CompleteState from './CompleteState';
|
||||
|
||||
export default class RecoverPasswordState extends AbstractState {
|
||||
enter(context) {
|
||||
const {auth} = context.getState();
|
||||
|
||||
if (auth.login) {
|
||||
const url = context.getRequest().path.includes('/recover-password')
|
||||
? context.getRequest().path
|
||||
: '/recover-password';
|
||||
context.navigate(url);
|
||||
} else {
|
||||
context.setState(new CompleteState());
|
||||
}
|
||||
const url = context.getRequest().path.includes('/recover-password')
|
||||
? context.getRequest().path
|
||||
: '/recover-password';
|
||||
context.navigate(url);
|
||||
}
|
||||
|
||||
resolve(context, payload) {
|
||||
|
@ -79,13 +79,31 @@ describe('ForgotPasswordState', () => {
|
||||
}
|
||||
});
|
||||
|
||||
mock.expects('run').returns(promise);
|
||||
mock.expects('run').twice().returns(promise);
|
||||
expectState(mock, RecoverPasswordState);
|
||||
|
||||
state.resolve(context, {});
|
||||
|
||||
return promise;
|
||||
});
|
||||
|
||||
it('should run setLogin on success', () => {
|
||||
const promise = Promise.resolve();
|
||||
const expectedLogin = 'foo@bar.com';
|
||||
context.getState.returns({
|
||||
auth: {
|
||||
login: expectedLogin
|
||||
}
|
||||
});
|
||||
|
||||
mock.expects('run').withArgs('forgotPassword').returns(promise);
|
||||
expectState(mock, RecoverPasswordState);
|
||||
mock.expects('run').withArgs('setLogin', expectedLogin);
|
||||
|
||||
state.resolve(context, {});
|
||||
|
||||
return promise;
|
||||
});
|
||||
});
|
||||
|
||||
describe('#reject', () => {
|
||||
|
@ -26,9 +26,6 @@ describe('RecoverPasswordState', () => {
|
||||
describe('#enter', () => {
|
||||
it('should navigate to /recover-password', () => {
|
||||
const expectedPath = '/recover-password';
|
||||
context.getState.returns({
|
||||
auth: {login: 'foo'}
|
||||
});
|
||||
|
||||
context.getRequest.returns({path: expectedPath});
|
||||
|
||||
@ -39,9 +36,6 @@ describe('RecoverPasswordState', () => {
|
||||
|
||||
it('should navigate to /recover-password/key', () => {
|
||||
const expectedPath = '/recover-password/sasx5AS4d61';
|
||||
context.getState.returns({
|
||||
auth: {login: 'foo'}
|
||||
});
|
||||
|
||||
context.getRequest.returns({path: expectedPath});
|
||||
|
||||
@ -49,16 +43,6 @@ describe('RecoverPasswordState', () => {
|
||||
|
||||
state.enter(context);
|
||||
});
|
||||
|
||||
it('should transition to complete if not guest', () => {
|
||||
context.getState.returns({
|
||||
auth: {}
|
||||
});
|
||||
|
||||
expectState(mock, CompleteState);
|
||||
|
||||
state.enter(context);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#resolve', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user