Fixed some details with the signup flow.

This commit is contained in:
Tim Brandin 2016-03-29 01:28:53 +02:00
parent 2a3ffbd675
commit 629217d131
5 changed files with 32 additions and 26 deletions

View file

@ -1,4 +1,4 @@
import {Accounts} from 'meteor/accounts-base';
import { Accounts } from 'meteor/accounts-base';
import { redirect } from './helpers.js';
/**

View file

@ -18,8 +18,8 @@ export function getLoginServices() {
// requires it.
this.getLoginServices = getLoginServices;
export function loginResultCallback(redirect) {
if (Meteor.isClient){
export function loginResultCallback(redirect, error) {
if (Meteor.isClient) {
if (typeof redirect === 'string'){
window.location.href = redirect;
}
@ -42,25 +42,10 @@ export function validatePassword(password){
}
};
// Helper to dynamically inject react components.
Global = this;
export function Inject(component, ...args) {
return Global[component] ? React.createElement.apply(React.createElement, [Global[component], ...args]) : '';
}
export function redirect(path) {
if (Meteor.isClient) {
if (window.history) {
window.history.replaceState( {} , 'redirect', path );
}
else {
window.location.href = href;
}
}
}
// capitalize = function(str){
// str = str == null ? '' : String(str);
//
// return str.charAt(0).toUpperCase() + str.slice(1);
// };

View file

@ -74,23 +74,29 @@ if (Meteor.isClient){
let doneCallback;
Accounts.onResetPasswordLink(function (token, done) {
Accounts.ui._options.onResetPasswordHook();
Accounts._loginButtonsSession.set("resetPasswordToken", token);
doneCallback = done;
});
Accounts.onEnrollmentLink(function (token, done) {
Accounts.ui._options.onEnrollAccountHook();
Accounts._loginButtonsSession.set("enrollAccountToken", token);
doneCallback = done;
});
Accounts.onEmailVerificationLink(function (token, done) {
Accounts.ui._options.onVerifyEmailHook();
Accounts.verifyEmail(token, function (error) {
if (! error) {
Accounts._loginButtonsSession.set('justVerifiedEmail', true);
Accounts.ui._options.onSignedInHook();
}
done();
// XXX show something if there was an error.
});
});
}

View file

@ -14,6 +14,7 @@ import {
const STATES = {
SIGN_IN: Symbol('SIGN_IN'),
SIGN_UP: Symbol('SIGN_UP'),
SIGN_OUT: Symbol('SIGN_OUT'),
PASSWORD_CHANGE: Symbol('PASSWORD_CHANGE'),
PASSWORD_RESET: Symbol('PASSWORD_RESET')
};
@ -27,7 +28,7 @@ export class LoginForm extends Tracker.Component {
this.state = {
message: '',
waiting: true,
formState: Meteor.user() ? STATES.PASSWORD_CHANGE : STATES.SIGN_IN
formState: Meteor.user() ? STATES.SIGN_OUT : STATES.SIGN_IN
};
// Listen reactively.
@ -179,7 +180,7 @@ export class LoginForm extends Tracker.Component {
const { formState, waiting, user } = this.state;
let loginButtons = [];
if (user) {
if (user && formState == STATES.SIGN_OUT) {
loginButtons.push({
id: 'signOut',
label: t9n('signOut'),
@ -215,6 +216,15 @@ export class LoginForm extends Tracker.Component {
});
}
if (user && formState == STATES.SIGN_OUT && Package['accounts-password']) {
loginButtons.push({
id: 'switchToChangePassword',
label: t9n('changeYourPassword'),
type: 'link',
onClick: this.switchToChangePassword.bind(this)
});
}
if (formState == STATES.SIGN_UP) {
loginButtons.push({
id: 'signUp',
@ -249,6 +259,7 @@ export class LoginForm extends Tracker.Component {
loginButtons.push({
id: 'changePassword',
label: t9n('changePassword'),
type: 'submit',
disabled: waiting,
onClick: this.passwordChange.bind(this)
});
@ -263,7 +274,7 @@ export class LoginForm extends Tracker.Component {
}
showPasswordChangeForm() {
return(getLoginServices().indexOf('password') != -1
return(Package['accounts-password']
&& this.state.formState == STATES.PASSWORD_CHANGE);
}
@ -295,9 +306,13 @@ export class LoginForm extends Tracker.Component {
this.setState({ formState: STATES.PASSWORD_RESET, message: '' });
}
switchToChangePassword() {
this.setState({ formState: STATES.PASSWORD_CHANGE, message: '' });
}
signOut() {
Meteor.logout(() => {
this.setState({ formState: STATES.SIGN_IN });
this.setState({ formState: STATES.SIGN_IN, message: '' });
});
}
@ -350,7 +365,7 @@ export class LoginForm extends Tracker.Component {
this.showMessage(t9n(`error.accounts.${error.reason}`) || t9n("Unknown error"));
}
else {
this.setState({ formState: STATES.PASSWORD_CHANGE, message: '' });
this.setState({ formState: STATES.SIGN_OUT, message: '' });
loginResultCallback(this.props.redirect);
}
});
@ -404,7 +419,7 @@ export class LoginForm extends Tracker.Component {
}
else {
this.setState({
formState: STATES.PASSWORD_CHANGE,
formState: STATES.SIGN_OUT,
message: ''
});
loginResultCallback(this.props.redirect);

View file

@ -7,7 +7,7 @@ Package.describe({
});
Package.onUse(function(api) {
api.versionsFrom('1.3-rc.1');
api.versionsFrom('1.3');
api.use('ecmascript');
api.use('tracker');
api.use('underscore');