diff --git a/client/src/actions/user-actions.js b/client/src/actions/user-actions.js index 3fb1714c..dc9cd0b6 100644 --- a/client/src/actions/user-actions.js +++ b/client/src/actions/user-actions.js @@ -4,6 +4,7 @@ const UserActions = Reflux.createActions([ 'checkLoginStatus', 'login', 'logout', + 'sendRecover', 'recoverPassword' ]); diff --git a/client/src/app/main/main-home/main-home-page-login-widget.js b/client/src/app/main/main-home/main-home-page-login-widget.js index fb2a0eb1..ff8cf267 100644 --- a/client/src/app/main/main-home/main-home-page-login-widget.js +++ b/client/src/app/main/main-home/main-home-page-login-widget.js @@ -24,6 +24,7 @@ let MainHomePageLoginWidget = React.createClass({ return { sideToShow: 'front', loginFormErrors: {}, + recoverFormErrors: {}, recoverSent: false }; }, @@ -60,16 +61,16 @@ let MainHomePageLoginWidget = React.createClass({ renderPasswordRecovery() { return ( -
+
- +
- +
{this.renderRecoverStatus()}
@@ -94,10 +95,8 @@ let MainHomePageLoginWidget = React.createClass({ UserActions.login(formState); }, - handleForgotPasswordSubmit() { - this.setState({ - recoverSent: true - }); + handleForgotPasswordSubmit(formState) { + UserActions.sendRecover(formState); }, handleLoginFormErrorsValidation(errors) { @@ -106,6 +105,12 @@ let MainHomePageLoginWidget = React.createClass({ }); }, + handleRecoverFormErrorsValidation(errors) { + this.setState({ + recoverFormErrors: errors + }); + }, + handleForgotPasswordClick() { this.setState({ sideToShow: 'back' @@ -125,9 +130,26 @@ let MainHomePageLoginWidget = React.createClass({ password: i18n('ERROR_PASSWORD') } }, function () { - this.refs.loginForm.refs.password.focus() + this.refs.loginForm.refs.password.focus(); }.bind(this)); } + + if (event === 'SEND_RECOVER_FAIL') { + this.setState({ + recoverFormErrors: { + email: i18n('EMAIL_NOT_EXIST') + } + }, function () { + this.refs.recoverForm.refs.email.focus(); + }.bind(this)); + + } + + if (event === 'SEND_RECOVER_SUCCESS') { + this.setState({ + recoverSent: true + }); + } }, moveFocusToCurrentSide() { diff --git a/client/src/data/fixtures/user-fixtures.js b/client/src/data/fixtures/user-fixtures.js index f0f8128e..b17b4842 100644 --- a/client/src/data/fixtures/user-fixtures.js +++ b/client/src/data/fixtures/user-fixtures.js @@ -47,6 +47,25 @@ module.exports = [ }; } }, + { + path: 'user/send-recover-password', + time: 100, + response: function (data) { + + if (data.email.length > 10) { + return { + status: 'success', + data: {} + }; + } else { + return { + status: 'fail', + message: 'Email not exists', + data: {} + }; + } + } + }, { path: 'user/recover-password', time: 100, diff --git a/client/src/data/languages/en.js b/client/src/data/languages/en.js index ea2f2ce1..41d85727 100644 --- a/client/src/data/languages/en.js +++ b/client/src/data/languages/en.js @@ -4,11 +4,13 @@ export default { 'SIGN_UP': 'Sign up', 'FORGOT_PASSWORD': 'Forgot your password?', 'RECOVER_PASSWORD': 'Recover Password', - 'RECOVER_SENT': 'An email with password recover instructions has been sent.', + 'RECOVER_SENT': 'An email with recover instructions has been sent.', 'NEW_PASSWORD': 'New password', 'REPEAT_NEW_PASSWORD': 'Repeat new password', 'VALID_RECOVER': 'Password recovered successfully', 'INVALID_RECOVER': 'Invalid recover data', + 'BACK_LOGIN_FORM': 'Back to login form', + 'EMAIL_NOT_EXIST': 'Email does not exist', //ERRORS 'ERROR_EMPTY': 'Invalid value', diff --git a/client/src/lib-app/validations/email-validator.js b/client/src/lib-app/validations/email-validator.js index ef4b7e45..9cba77b8 100644 --- a/client/src/lib-app/validations/email-validator.js +++ b/client/src/lib-app/validations/email-validator.js @@ -3,7 +3,7 @@ import Validator from 'lib-app/validations/validator'; class EmailValidator extends Validator { validate(value, form) { - if (!value.length) return this.getError('ERROR_EMPTY'); + if (value.length < 6) return this.getError('ERROR_EMAIL'); if (value.indexOf('@') === -1) return this.getError('ERROR_EMAIL'); } } diff --git a/client/src/stores/user-store.js b/client/src/stores/user-store.js index d9e020da..07ae890a 100644 --- a/client/src/stores/user-store.js +++ b/client/src/stores/user-store.js @@ -14,6 +14,7 @@ const UserStore = Reflux.createStore({ this.listenTo(UserActions.login, this.loginUser); this.listenTo(UserActions.logout, this.logoutUser); this.listenTo(UserActions.recoverPassword, this.recoverPassword); + this.listenTo(UserActions.sendRecover, this.sendRecoverPassword); }, initSession() { @@ -54,13 +55,24 @@ const UserStore = Reflux.createStore({ }); }, + sendRecoverPassword(recoverData) { + return API.call({ + path: 'user/send-recover-password', + data: recoverData + }).then(() => { + this.trigger('SEND_RECOVER_SUCCESS'); + }, () => { + this.trigger('SEND_RECOVER_FAIL') + }); + }, + recoverPassword(recoverData) { return API.call({ path: 'user/recover-password', data: recoverData }).then(() => { this.trigger('VALID_RECOVER'); - //setTimeout(CommonActions.loggedOut, 2000); + setTimeout(CommonActions.loggedOut, 1000); }, () => { this.trigger('INVALID_RECOVER') });