From 1536739b01f905c8da5380541a85f09f605984b9 Mon Sep 17 00:00:00 2001 From: Luca Mussi Date: Mon, 17 Aug 2015 10:46:29 +0200 Subject: [PATCH] route names and fixes --- lib/client/client.js | 34 +++++++++++++++++++--------------- lib/core.js | 3 ++- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/client/client.js b/lib/client/client.js index bde5c9f..b65c408 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -52,7 +52,7 @@ AccountsTemplates.setPrevPath = function(newPath) { AccountsTemplates.ensureSignedIn = function(context, redirect) { if (!Meteor.userId()) { // if we're not already on an AT route - if (!_.contains(AccountsTemplates.knownRoutes, context.path)) { + if (!_.contains(AccountsTemplates.knownRoutes, context.route.name)) { AccountsTemplates.setState(AccountsTemplates.options.defaultState, function() { var err = AccountsTemplates.texts.errors.mustBeLoggedIn; @@ -66,7 +66,13 @@ AccountsTemplates.ensureSignedIn = function(context, redirect) { // redirect to defined sign-in route and then redirect back // to original route after successful sign in - redirect('signIn'); + var signInRouteName = AccountsTemplates.getRouteName('signIn'); + if (signInRouteName) { + redirect(signInRouteName); + } + else { + throw Error('[ensureSignedIn] no signIn route configured!'); + } } } }; @@ -74,14 +80,10 @@ AccountsTemplates.ensureSignedIn = function(context, redirect) { // Stores previous path on path change... FlowRouter.triggers.exit([ function(context) { - var isKnownRoute = _.map(AccountsTemplates.knownRoutes, function(path) { - if (!path) { - return false; - } - var known = RegExp(path).test(context.path); - return known; - }); - if (!_.some(isKnownRoute)) { + var routeName = context.route.name; + var knownRoute = _.contains(AccountsTemplates.knownRoutes, routeName); + if (!knownRoute) { + console.log('storing previous path: ' + context.path); AccountsTemplates.setPrevPath(context.path); } } @@ -100,11 +102,13 @@ AccountsTemplates.linkClick = function(route) { }); } - var firstVisibleInput = _.find(this.getFields(), function(f) { - return _.contains(f.visible, route); - }); - if (firstVisibleInput) { - $('input#at-field-' + firstVisibleInput._id).focus(); + if (AccountsTemplates.options.focusFirstInput) { + var firstVisibleInput = _.find(this.getFields(), function(f) { + return _.contains(f.visible, route); + }); + if (firstVisibleInput) { + $('input#at-field-' + firstVisibleInput._id).focus(); + } } }; diff --git a/lib/core.js b/lib/core.js index aee7f84..09d0c5b 100644 --- a/lib/core.js +++ b/lib/core.js @@ -93,10 +93,11 @@ AccountsTemplates.configureRoute = function(route, options) { // Updates the current configuration options = _.defaults(options || {}, this.ROUTE_DEFAULT[route]); + // Store route options this.routes[route] = options; // Known routes are used to filter out previous path for redirects... - AccountsTemplates.knownRoutes.push(options.path); + AccountsTemplates.knownRoutes.push(options.name); if (Meteor.isServer) { // Configures "reset password" email link