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'; import { redirect } from './helpers.js';
/** /**

View file

@ -18,8 +18,8 @@ export function getLoginServices() {
// requires it. // requires it.
this.getLoginServices = getLoginServices; this.getLoginServices = getLoginServices;
export function loginResultCallback(redirect) { export function loginResultCallback(redirect, error) {
if (Meteor.isClient){ if (Meteor.isClient) {
if (typeof redirect === 'string'){ if (typeof redirect === 'string'){
window.location.href = redirect; 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) { export function redirect(path) {
if (Meteor.isClient) { if (Meteor.isClient) {
if (window.history) { if (window.history) {
window.history.replaceState( {} , 'redirect', path ); 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; let doneCallback;
Accounts.onResetPasswordLink(function (token, done) { Accounts.onResetPasswordLink(function (token, done) {
Accounts.ui._options.onResetPasswordHook();
Accounts._loginButtonsSession.set("resetPasswordToken", token); Accounts._loginButtonsSession.set("resetPasswordToken", token);
doneCallback = done; doneCallback = done;
}); });
Accounts.onEnrollmentLink(function (token, done) { Accounts.onEnrollmentLink(function (token, done) {
Accounts.ui._options.onEnrollAccountHook();
Accounts._loginButtonsSession.set("enrollAccountToken", token); Accounts._loginButtonsSession.set("enrollAccountToken", token);
doneCallback = done; doneCallback = done;
}); });
Accounts.onEmailVerificationLink(function (token, done) { Accounts.onEmailVerificationLink(function (token, done) {
Accounts.ui._options.onVerifyEmailHook();
Accounts.verifyEmail(token, function (error) { Accounts.verifyEmail(token, function (error) {
if (! error) { if (! error) {
Accounts._loginButtonsSession.set('justVerifiedEmail', true); Accounts._loginButtonsSession.set('justVerifiedEmail', true);
Accounts.ui._options.onSignedInHook();
} }
done(); done();
// XXX show something if there was an error.
}); });
}); });
} }

View file

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

View file

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