Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,13 @@ Renders a change password form. The parameter `spToken` is required in order for
<ChangePasswordForm spToken={this.props.location.query.sptoken} />
```

After the user has changed their password, the default form will show a link the user can click on that takes them
to the login page. If you want to automatcially log the user in after they've changed their password, then add:

```html
<ChangePasswordForm spToken={this.props.location.query.sptoken} autoLogin={true} />
```

Customize the form by providing your own markup.

```html
Expand Down
21 changes: 20 additions & 1 deletion src/components/ChangePasswordForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import ReactMixin from 'react-mixin';
import { History, Link } from 'react-router';

import context from '../context';
import utils from '../utils';
import LoginLink from '../components/LoginLink';
import LoadingText from '../components/LoadingText';
Expand Down Expand Up @@ -92,7 +93,7 @@ export default class ChangePasswordForm extends React.Component {
});
}

UserActions.changePassword(data, (err) => {
UserActions.changePassword(data, (err, acct) => {
if (err) {
if (err.status === 404) {
err.message = 'The reset password token is not valid. Please try resetting your password again.';
Expand All @@ -108,6 +109,13 @@ export default class ChangePasswordForm extends React.Component {
isFormProcessing: false,
isFormSent: true
});

if ( this.props.autoLogin && ( acct && acct.email ) ) {
UserActions.login({ username: acct.email, password: data.password }, ( err ) => {
if ( err ) utils.logWarning('<ChangePasswordForm>', 'Tried to autoLogin, but there was a problem: ' + err.message);
if ( ! err ) this._performRedirect();
});
}
});
};

Expand All @@ -131,6 +139,17 @@ export default class ChangePasswordForm extends React.Component {
}
}

_performRedirect() {
var router = context.getRouter();
var homeRoute = router.getHomeRoute();
var authenticatedHomeRoute = router.getAuthenticatedHomeRoute();
var { location } = this.props;
var passthru = (location && location.state) ? location.state.nextPathname : null;
var redirectTo = this.props.redirectTo || passthru || (authenticatedHomeRoute || {}).path || (homeRoute || {}).path || '/';
console.log( 'redirecting to:', redirectTo );
this.history.pushState(null, redirectTo);
}

_mapFormFieldHandler(element, tryMapField) {
if (element.type === 'input' || element.type === 'textarea') {
if (element.props.type !== 'submit') {
Expand Down