Skip to content

Commit

Permalink
route names and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
splendido committed Aug 17, 2015
1 parent 51b87fe commit 1536739
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
34 changes: 19 additions & 15 deletions lib/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -66,22 +66,24 @@ 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!');
}
}
}
};

// 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);
}
}
Expand All @@ -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();
}
}
};

Expand Down
3 changes: 2 additions & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1536739

Please sign in to comment.