Make the login buttons template detect and react to which accounts packages are enabled.

This commit is contained in:
Nick Martin
2012-06-13 22:56:56 -07:00
parent 9e369b9604
commit bbf10bdd14
3 changed files with 39 additions and 21 deletions

View File

@@ -1,10 +1,12 @@
.login-header-email {
#login-buttons .login-header {
float: left;
padding: 2px 7px;
margin: 5px 0px 5px 5px;
}
.login-button {
#login-buttons .login-button {
float:left;
cursor: pointer;

View File

@@ -1,11 +1,16 @@
<template name="login_buttons">
<div id="login-buttons">
{{#if user}}
<div class="login-header-email">{{userName}}</div>
<div class="login-header">{{userName}}</div>
<div class="login-button" id="login-buttons-logout">logout</div>
{{else}}
<div class="login-button" id="login-buttons-fb-login">login using facebook</div>
<div class="login-button" id="login-buttons-google-login">login using google</div>
{{#if services}}
{{#each services}}
<div class="login-button" id="login-buttons-{{name}}">login using {{name}}</div>
{{/each}}
{{else}}
<div class="no-services">No account services configured.</div>
{{/if}}
{{/if}}
</div>
</template>

View File

@@ -1,21 +1,7 @@
(function () {
Template.login_buttons.userEmail = function () {
var user = Meteor.user();
if (!user || !user.emails || !user.emails[0])
return '';
return user.emails[0];
};
Template.login_buttons.userName = function () {
var user = Meteor.user();
if (!user || !user.name)
return '';
return user.name;
};
Template.login_buttons.events = {
'click #login-buttons-fb-login': function () {
'click #login-buttons-Facebook': function () {
try {
Meteor.loginWithFacebook();
} catch (e) {
@@ -26,7 +12,7 @@
}
},
'click #login-buttons-google-login': function () {
'click #login-buttons-Google': function () {
try {
Meteor.loginWithGoogle();
} catch (e) {
@@ -42,4 +28,29 @@
}
};
Template.login_buttons.services = function () {
var ret = [];
if (Meteor.accounts.facebook)
ret.push({name: 'Facebook'});
if (Meteor.accounts.google)
ret.push({name: 'Google'});
return ret;
};
Template.login_buttons.userEmail = function () {
var user = Meteor.user();
if (!user || !user.emails || !user.emails[0])
return '';
return user.emails[0];
};
Template.login_buttons.userName = function () {
var user = Meteor.user();
if (!user || !user.name)
return '';
return user.name;
};
})();