2014-03-01 58 views
0

我正在使用流星与铁路由器,我希望应用在用户成功登录时自动进入“仪表板”模板。我该怎么做?这里是我的代码:登录后呈现模板?

的javascript:

// Sign In Template 
Template.signIn.events({ 
    'submit #signInForm': function(e, t) { 
     e.preventDefault(); 

     var signInForm = $(e.currentTarget), 
      email = trimInput(signInForm.find('.email').val().toLowerCase()), 
      password = signInForm.find('.password').val(); 

     if (isNotEmpty(email) && isEmail(email) && isNotEmpty(password) && isValidPassword(password)) { 
      Meteor.loginWithPassword(email, password, function(err) { 
       if (err) { 
        Session.set('alert', 'We\'re sorry but these credentials are not valid.'); 
       } else { 
        Sesson.set('alert', 'Welcome back New Meteorite!'); 


       } 
      }); 
     } 
     return false; 
    }, 
}); 

回答

1

Accounts Entry从大气包可以帮助你做到这一点,更多的视觉吸引力和无缝的方式。

由于documentation描述了一个例子:

Meteor.startup(function() { 
    return AccountsEntry.config({ 
    logo: 'logo.png', 
    privacyUrl: '/privacy-policy', 
    termsUrl: '/terms-of-use', 
    homeRoute: '/', 
    dashboardRoute: '/dashboard', // you have an autoconfigured dashboard route 
    profileRoute: 'profile', 
    passwordSignupFields: 'EMAIL_ONLY', 
    showSignupCode: true 
    }); 
}); 

而且为了保护您的路线,你只需配置:

Route.map(function() { 
    this.route('createPayment', { 
    path: '/create/payment', 
    before: function() { 
     return AccountsEntry.signInRequired(this); 
    } 
    }); 
}); 
1

在成功的情况下,从您的loginWithPassword,你可以叫:

Router.go('dashboard'); 

这是假设你有一个名为dashboard路线。例如:

Router.map(function() { 
    this.route('dashboard', { 
    path: '/user/dashboard', 
    template: 'userDashboard' 
    });