From b87cd4e276cd0ef3c90e78cddd0b8b87e52e5ede Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Tue, 24 Jan 2017 10:23:09 +0100 Subject: Move instances of Client.resetPassword() in components to an action (#5167) --- webapp/actions/user_actions.jsx | 22 ++++++++++++++++++++++ webapp/components/password_reset_form.jsx | 7 +++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/webapp/actions/user_actions.jsx b/webapp/actions/user_actions.jsx index 201a648f9..3f9715cd5 100644 --- a/webapp/actions/user_actions.jsx +++ b/webapp/actions/user_actions.jsx @@ -12,11 +12,14 @@ import {getChannelMembersForUserIds} from 'actions/channel_actions.jsx'; import {loadStatusesForProfilesList, loadStatusesForProfilesMap} from 'actions/status_actions.jsx'; import {getDirectChannelName} from 'utils/utils.jsx'; + import * as AsyncClient from 'utils/async_client.jsx'; import Client from 'client/web_client.jsx'; import {ActionTypes, Preferences} from 'utils/constants.jsx'; +import {browserHistory} from 'react-router/es6'; + export function switchFromLdapToEmail(email, password, token, ldapPassword, onSuccess, onError) { Client.ldapToEmail( email, @@ -578,3 +581,22 @@ export function verifyEmail(uid, hid, success, error) { } ); } + +export function resetPassword(code, password, success, error) { + Client.resetPassword( + code, + password, + () => { + browserHistory.push('/login?extra=' + ActionTypes.PASSWORD_CHANGE); + + if (success) { + success(); + } + }, + (err) => { + if (error) { + error(err); + } + } + ); +} diff --git a/webapp/components/password_reset_form.jsx b/webapp/components/password_reset_form.jsx index b37e07f2d..c6fe2525f 100644 --- a/webapp/components/password_reset_form.jsx +++ b/webapp/components/password_reset_form.jsx @@ -2,12 +2,12 @@ // See License.txt for license information. import ReactDOM from 'react-dom'; -import Client from 'client/web_client.jsx'; import * as Utils from 'utils/utils.jsx'; import Constants from 'utils/constants.jsx'; import {FormattedMessage} from 'react-intl'; -import {browserHistory} from 'react-router/es6'; + +import {resetPassword} from 'actions/user_actions.jsx'; import React from 'react'; @@ -42,12 +42,11 @@ class PasswordResetForm extends React.Component { error: null }); - Client.resetPassword( + resetPassword( this.props.location.query.code, password, () => { this.setState({error: null}); - browserHistory.push('/login?extra=' + Constants.PASSWORD_CHANGE); }, (err) => { this.setState({error: err.message}); -- cgit v1.2.3-1-g7c22