Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/login with google #8

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .versions
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,5 @@ space:[email protected]
space:[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
18 changes: 9 additions & 9 deletions git-packages.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"space:base": {
"git":"https://github.com/meteor-space/base.git",
"branch": "develop"
"version": "1d99a64fe51904569742aee13e94b3cae29abdb4"
},
"space:messaging": {
"git":"https://github.com/meteor-space/messaging.git",
"branch": "develop"
"version": "bbaf57c511f7230c662d2ea4473b056148c82787"
},
"space:event-sourcing": {
"git":"https://github.com/meteor-space/event-sourcing.git",
"branch": "develop"
"space:ui": {
"git":"https://github.com/meteor-space/ui.git",
"version": "49651ba1c09b5ba3d410ac2676fb19c48900919c"
},
"space:flux": {
"git":"https://github.com/meteor-space/flux.git",
"branch": "develop"
"version": "fa2d297bda951442e02a41a1762100163471b863"
},
"space:accounts": {
"git":"https://github.com/meteor-space/accounts.git",
"branch": "develop"
"branch": "feature/login-with-google"
},
"space:vo-user": {
"git":"https://github.com/meteor-space/vo-user.git",
"branch": "develop"
"version": "780d1fc7e1c9a969fe8e1ddae06c86fcf9ca19ff"
},
"space:testing": {
"git":"https://github.com/meteor-space/testing.git",
"branch": "develop"
"version": "7a404a8cf8e19b1cd0490dac8025c58046fe10b1"
}
}
11 changes: 6 additions & 5 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ Package.onUse(function(api) {
'coffeescript',
'mongo',
'sha',
'templating',
'tracker',
'ecmascript',
'check',
'accounts-base',
'accounts-password',
'accounts-google',
'service-configuration',
'space:[email protected]',
'space:[email protected]',
'space:flux@0.6.0'
'space:flux@0.7.0'
]);

// MODULES
api.addFiles(['source/server/module.coffee'], 'server');
api.addFiles(['source/client/module.coffee'], 'client');
api.addFiles(['source/server/module.js'], 'server');
api.addFiles(['source/client/module.js'], 'client');

// SHARED
api.addFiles([
Expand All @@ -37,7 +38,7 @@ Package.onUse(function(api) {

// CLIENT
api.addFiles([
'source/client/events.coffee',
'source/client/events.js',
// Stores
'source/client/stores/users-store.js',
'source/client/stores/signups-store.js',
Expand Down
73 changes: 62 additions & 11 deletions source/client/controllers/login-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,73 @@ Space.messaging.Controller.extend(Space.accountsUi, 'LoginController', {
},

_onLoginRequested(event) {
let password = event.password.toString();
this.meteor.loginWithPassword(event.user, password, (error) => {
if (error) {
this.publish(new Space.accountsUi.LoginFailed({
user: event.user,
error: error
}));
} else {
this.publish(new Space.accountsUi.LoginSucceeded({ user: event.user }));

if (!event.loginType.isService()) {
let password = event.password.toString();
this.meteor.loginWithPassword(event.user, password, (error) => {
if (error) {
this.publish(new Space.accountsUi.LoginFailed({
user: event.user,
error: error,
loginType: event.loginType
}));
} else {
this.publish(new Space.accountsUi.LoginSucceeded({
user: event.user,
loginType: event.loginType
}));
}
});
this.publish(new Space.accountsUi.LoginInitiated({
user: event.user,
loginType: event.loginType
}));
} else {
switch(event.loginType.loginType) {
case 'google':
this.meteor.loginWithGoogle({requestPermissions: ['email']}, (error) => {
if (error) {
let errorEvent = new Space.accountsUi.LoginFailed({
error: error,
loginType: event.loginType
});
this.publish(errorEvent);
} else {
this.publish(new Space.accountsUi.LoginSucceeded({
loginType: event.loginType
}));
}
});
this.publish(new Space.accountsUi.LoginInitiated({
loginType: event.loginType
}));
break;
case 'facebook':
this.meteor.loginWithFacebook({requestPermissions: ['email', 'public_profile']}, (error) => {
if (error) {
let errorEvent = new Space.accountsUi.LoginFailed({
error: error,
loginType: event.loginType
});
this.publish(errorEvent);
} else {
this.publish(new Space.accountsUi.LoginSucceeded({
loginType: event.loginType
}));
}
});
this.publish(new Space.accountsUi.LoginInitiated({
loginType: event.loginType
}));
break;
}
});
this.publish(new Space.accountsUi.LoginInitiated({ user: event.user }));
}

},

_onLogoutRequested() {
this.meteor.logout();
this.publish(new Space.accountsUi.LoggedOut());
}

});
54 changes: 0 additions & 54 deletions source/client/events.coffee

This file was deleted.

60 changes: 60 additions & 0 deletions source/client/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Space.messaging.define(Space.messaging.Event, 'Space.accountsUi', {

// SIGNUP

SignupRequested: {
username: Match.Optional(Username),
email: Match.Optional(EmailAddress),
password: Match.Optional(Password),
loginType: LoginType
},

SignupInitiated: {
signupId: Guid
},

SignupRetried: {
signupId: Guid,
},

SignupFailed: {
signupId: Guid,
error: String
},

SignupCompleted: {
signupId: Guid
},

// LOGIN

LoginRequested: {
user: Match.Optional(Match.OneOf(Username, EmailAddress)),
password: Match.Optional(Password),
loginType: LoginType
},

LoginInitiated: {
user: Match.Optional(Match.OneOf(Username, EmailAddress)),
loginType: LoginType
},

LoginFailed: {
user: Match.Optional(Match.OneOf(Username, EmailAddress)),
loginType: LoginType,
error: Match.OneOf(Meteor.Error, ServiceConfiguration.ConfigError)
},

LoginSucceeded: {
user: Match.Optional(Match.OneOf(Username, EmailAddress)),
loginType: LoginType
},

// LOGOUT

LogoutRequested: {},

LoggedOut: {}

});

25 changes: 0 additions & 25 deletions source/client/module.coffee

This file was deleted.

28 changes: 28 additions & 0 deletions source/client/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Space.accountsUi = Space.Module.define('Space.accountsUi', {

requiredModules: [
'Space.flux'
],

stores: [
'Space.accountsUi.SignupsStore',
'Space.accountsUi.LoginStore',
'Space.accountsUi.UsersStore'
],

controllers: [
'Space.accountsUi.LoginController'
],

singletons: [
'Space.accountsUi.SignupsTracker'
],

onInitialize() {
this.injector.map('SHA256').to(SHA256);
this.injector.map('Meteor.user').to(Meteor.user);
this.injector.map('Meteor.users').to(Meteor.users);
this.injector.map('Space.accountsUi.Signups').asStaticValue();
}

});
17 changes: 0 additions & 17 deletions source/server/module.coffee

This file was deleted.

19 changes: 19 additions & 0 deletions source/server/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Space.accountsUi = Space.Module.define('Space.accountsUi', {

requiredModules: [
'Space.accounts'
],

singletons: [
'Space.accountsUi.SignupsPublication'
],

onInitialize() {
this.injector.map('SHA256').to(SHA256);
this.injector.map('Meteor.user').to(Meteor.user);
this.injector.map('Meteor.users').to(Meteor.users);
this.injector.map('Space.accountsUi.Signups').asStaticValue();
}

});