mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-01-13 07:12:32 +05:30
#327: fix forgot password behaviour for logged in user
This commit is contained in:
parent
b4bbbe3372
commit
876d3da4ab
@ -46,7 +46,10 @@ export default class BaseAuthBody extends Component {
|
|||||||
});
|
});
|
||||||
|
|
||||||
bindField = this.form.bindField.bind(this.form);
|
bindField = this.form.bindField.bind(this.form);
|
||||||
serialize = this.form.serialize.bind(this.form);
|
|
||||||
|
serialize() {
|
||||||
|
return this.form.serialize();
|
||||||
|
}
|
||||||
|
|
||||||
autoFocus() {
|
autoFocus() {
|
||||||
const fieldId = this.autoFocusField;
|
const fieldId = this.autoFocusField;
|
||||||
|
@ -15,14 +15,13 @@ export default class ForgotPasswordBody extends BaseAuthBody {
|
|||||||
static hasGoBack = true;
|
static hasGoBack = true;
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
isLoginEdit: !(this.context.user.email || this.context.user.username)
|
isLoginEdit: !this.getLogin()
|
||||||
};
|
};
|
||||||
|
|
||||||
autoFocusField = this.state.isLoginEdit ? 'email' : null;
|
autoFocusField = this.state.isLoginEdit ? 'email' : null;
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { user } = this.context;
|
const login = this.getLogin();
|
||||||
const login = user.email || user.username || '';
|
|
||||||
const isLoginEditShown = this.state.isLoginEdit;
|
const isLoginEditShown = this.state.isLoginEdit;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -61,6 +60,22 @@ export default class ForgotPasswordBody extends BaseAuthBody {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
serialize() {
|
||||||
|
const data = super.serialize();
|
||||||
|
|
||||||
|
if (!data.email) {
|
||||||
|
data.email = this.getLogin();
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
getLogin() {
|
||||||
|
const { user, auth } = this.context;
|
||||||
|
|
||||||
|
return auth.login || user.username || user.email || '';
|
||||||
|
}
|
||||||
|
|
||||||
onClickEdit = () => {
|
onClickEdit = () => {
|
||||||
this.setState({
|
this.setState({
|
||||||
isLoginEdit: true
|
isLoginEdit: true
|
||||||
|
@ -10,7 +10,7 @@ export default class ForgotPasswordState extends AbstractState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resolve(context, payload = {}) {
|
resolve(context, payload = {}) {
|
||||||
const login = payload.email || this.getLogin(context);
|
const login = payload.email;
|
||||||
|
|
||||||
context.run('forgotPassword', {login})
|
context.run('forgotPassword', {login})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@ -29,10 +29,4 @@ export default class ForgotPasswordState extends AbstractState {
|
|||||||
reject(context) {
|
reject(context) {
|
||||||
context.setState(new RecoverPasswordState());
|
context.setState(new RecoverPasswordState());
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogin(context) {
|
|
||||||
const {auth} = context.getState();
|
|
||||||
|
|
||||||
return auth.login;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -32,32 +32,8 @@ describe('ForgotPasswordState', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#resolve', () => {
|
describe('#resolve', () => {
|
||||||
it('should call forgotPassword with login', () => {
|
it('should call forgotPassword with email from payload', () => {
|
||||||
const expectedLogin = 'foo@bar.com';
|
const expectedLogin = 'foo@bar.com';
|
||||||
context.getState.returns({
|
|
||||||
auth: {
|
|
||||||
login: expectedLogin
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
expectRun(
|
|
||||||
mock,
|
|
||||||
'forgotPassword',
|
|
||||||
sinon.match({
|
|
||||||
login: expectedLogin
|
|
||||||
})
|
|
||||||
).returns(Promise.resolve());
|
|
||||||
|
|
||||||
state.resolve(context, {});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call forgotPassword with email from payload if any', () => {
|
|
||||||
const expectedLogin = 'foo@bar.com';
|
|
||||||
context.getState.returns({
|
|
||||||
auth: {
|
|
||||||
login: 'should.not@be.used'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
expectRun(
|
expectRun(
|
||||||
mock,
|
mock,
|
||||||
@ -73,16 +49,11 @@ describe('ForgotPasswordState', () => {
|
|||||||
it('should transition to recoverPassword state on success', () => {
|
it('should transition to recoverPassword state on success', () => {
|
||||||
const promise = Promise.resolve();
|
const promise = Promise.resolve();
|
||||||
const expectedLogin = 'foo@bar.com';
|
const expectedLogin = 'foo@bar.com';
|
||||||
context.getState.returns({
|
|
||||||
auth: {
|
|
||||||
login: expectedLogin
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mock.expects('run').twice().returns(promise);
|
mock.expects('run').twice().returns(promise);
|
||||||
expectState(mock, RecoverPasswordState);
|
expectState(mock, RecoverPasswordState);
|
||||||
|
|
||||||
state.resolve(context, {});
|
state.resolve(context, {email: expectedLogin});
|
||||||
|
|
||||||
return promise;
|
return promise;
|
||||||
});
|
});
|
||||||
@ -90,17 +61,12 @@ describe('ForgotPasswordState', () => {
|
|||||||
it('should run setLogin on success', () => {
|
it('should run setLogin on success', () => {
|
||||||
const promise = Promise.resolve();
|
const promise = Promise.resolve();
|
||||||
const expectedLogin = 'foo@bar.com';
|
const expectedLogin = 'foo@bar.com';
|
||||||
context.getState.returns({
|
|
||||||
auth: {
|
|
||||||
login: expectedLogin
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mock.expects('run').withArgs('forgotPassword').returns(promise);
|
mock.expects('run').withArgs('forgotPassword').returns(promise);
|
||||||
expectState(mock, RecoverPasswordState);
|
expectState(mock, RecoverPasswordState);
|
||||||
mock.expects('run').withArgs('setLogin', expectedLogin);
|
mock.expects('run').withArgs('setLogin', expectedLogin);
|
||||||
|
|
||||||
state.resolve(context, {});
|
state.resolve(context, {email: expectedLogin});
|
||||||
|
|
||||||
return promise;
|
return promise;
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user