diff --git a/lib/client.js b/lib/client.js index fc59de0..703693c 100644 --- a/lib/client.js +++ b/lib/client.js @@ -48,6 +48,8 @@ AT.prototype.texts = { mustBeLoggedIn: "error.accounts.Must be logged in", pwdMismatch: "error.pwdsDontMatch", }, + navSignIn: 'signIn', + navSignOut: 'signOut', info: { emailSent: "info.emailSent", emailVerified: "info.emailVerified", @@ -426,6 +428,12 @@ AT.prototype.linkClick = function(route){ }); }; +AT.prototype.logout = function(){ + Meteor.logout(); + var homeRoutePath = AccountsTemplates.options.homeRoutePath; + if (homeRoutePath) + Router.go(homeRoutePath); +}; AT.prototype.postSubmitRedirect = function(route){ if (AccountsTemplates.avoidRedirect) diff --git a/lib/core.js b/lib/core.js index 2dd7962..1eca1e1 100644 --- a/lib/core.js +++ b/lib/core.js @@ -29,6 +29,8 @@ INFO_PAT = { TEXTS_PAT = { button: Match.Optional(STATE_PAT), errors: Match.Optional(ERRORS_PAT), + navSignIn: Match.Optional(String), + navSignOut: Match.Optional(String), info: Match.Optional(INFO_PAT), optionalField: Match.Optional(String), pwdLink_pre: Match.Optional(String), diff --git a/lib/templates_helpers/at_nav_button.js b/lib/templates_helpers/at_nav_button.js new file mode 100644 index 0000000..6b96b11 --- /dev/null +++ b/lib/templates_helpers/at_nav_button.js @@ -0,0 +1,15 @@ +AT.prototype.atNavButtonHelpers = { + text: function(){ + var key = Meteor.user() ? AccountsTemplates.texts.navSignOut : AccountsTemplates.texts.navSignIn; + return T9n.get(key, markIfMissing=false); + } +}; + +AT.prototype.atNavButtonEvents = { + 'click #at-nav-button': function(event){ + if (Meteor.user()) + AccountsTemplates.logout(); + else + Router.go('atSignIn'); + }, +}; \ No newline at end of file diff --git a/package.js b/package.js index 06fc7b9..979bd71 100644 --- a/package.js +++ b/package.js @@ -45,6 +45,7 @@ Package.on_use(function(api) { "lib/templates_helpers/at_error.js", "lib/templates_helpers/at_form.js", "lib/templates_helpers/at_input.js", + "lib/templates_helpers/at_nav_button.js", "lib/templates_helpers/at_oauth.js", "lib/templates_helpers/at_pwd_form.js", "lib/templates_helpers/at_pwd_form_btn.js",