/* Copyright 2015, 2016 OpenMarket Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ 'use strict'; var React = require('react'); import { _t } from '../../../languageHandler'; var sdk = require('../../../index'); var Modal = require("../../../Modal"); var MatrixClientPeg = require('../../../MatrixClientPeg'); var PasswordReset = require("../../../PasswordReset"); module.exports = React.createClass({ displayName: 'ForgotPassword', propTypes: { defaultHsUrl: React.PropTypes.string, defaultIsUrl: React.PropTypes.string, customHsUrl: React.PropTypes.string, customIsUrl: React.PropTypes.string, onLoginClick: React.PropTypes.func, onRegisterClick: React.PropTypes.func, onComplete: React.PropTypes.func.isRequired }, getInitialState: function() { return { enteredHomeserverUrl: this.props.customHsUrl || this.props.defaultHsUrl, enteredIdentityServerUrl: this.props.customIsUrl || this.props.defaultIsUrl, progress: null }; }, submitPasswordReset: function(hsUrl, identityUrl, email, password) { this.setState({ progress: "sending_email" }); this.reset = new PasswordReset(hsUrl, identityUrl); this.reset.resetPassword(email, password).done(() => { this.setState({ progress: "sent_email" }); }, (err) => { this.showErrorDialog(_t('Failed to send email') + ": " + err.message); this.setState({ progress: null }); }); }, onVerify: function(ev) { ev.preventDefault(); if (!this.reset) { console.error("onVerify called before submitPasswordReset!"); return; } this.reset.checkEmailLinkClicked().done((res) => { this.setState({ progress: "complete" }); }, (err) => { this.showErrorDialog(err.message); }); }, onSubmitForm: function(ev) { ev.preventDefault(); if (!this.state.email) { this.showErrorDialog(_t('The email address linked to your account must be entered.')); } else if (!this.state.password || !this.state.password2) { this.showErrorDialog(_t('A new password must be entered.')); } else if (this.state.password !== this.state.password2) { this.showErrorDialog(_t('New passwords must match each other.')); } else { var QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); Modal.createDialog(QuestionDialog, { title: _t('Warning!'), description:
{ _t('Your password has been reset') }.
{ _t('You have been logged out of all devices and will no longer receive push notifications. To re-enable notifications, sign in again on each device') }.