Skip to content

feat(oauth): remove code according to user prompts #366

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

Merged
merged 3 commits into from
Jul 22, 2014
Merged
Show file tree
Hide file tree
Changes from 2 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: 1 addition & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ var AngularFullstackGenerator = yeoman.generators.Base.extend({
if(answers.mongoose) this.filters.mongoose = true;
if(answers.auth) this.filters.auth = true;
if(answers.oauth) {
if(answers.oauth.length) this.filters['oauth'] = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not this.filters.oauth = true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using an other name before with a -, so the array markup was needed, not anymore now so if you really prefer the dot notation I could switch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum oh and the global syntax of the index.js was this way before but seems to have changed now

answers.oauth.forEach(function(oauthStrategy) {
this.filters[oauthStrategy] = true;
}.bind(this));
Expand Down
20 changes: 10 additions & 10 deletions app/templates/client/app/account(auth)/login/login(css).css
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
.btn-facebook {
<% if (filters.oauth) { %><% if (filters.facebookAuth) { %>.btn-facebook {
color: #fff;
background-color: #3B5998;
border-color: #133783;
}

<% } if (filters.twitterAuth) { %>
.btn-twitter {
color: #fff;
background-color: #2daddc;
border-color: #0271bf;
}

.btn-github {
color: #fff;
background-color: #fafafa;
border-color: #ccc;
}

<% } if (filters.googleAuth) { %>
.btn-google-plus {
color: #fff;
background-color: #dd4b39;
border-color: #c53727;
}
}
<% } %>
.btn-github {
color: #fff;
background-color: #fafafa;
border-color: #ccc;
}<% } %>
5 changes: 2 additions & 3 deletions app/templates/client/app/account(auth)/login/login(html).html
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ <h1>Login</h1>
Register
</a>
</div>

<% if(filters.facebookAuth || filters.twitterAuth || filters.googleAuth) {%>
<% if(filters.oauth) {%>
<hr>
<div><% if(filters.facebookAuth) {%>
<a class="btn btn-facebook" href="" ng-click="loginOauth('facebook')">
Expand All @@ -55,4 +54,4 @@ <h1>Login</h1>
</div>
</div>
<hr>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ div(ng-include='"components/navbar/navbar.html"')
= ' '
a.btn.btn-default.btn-lg.btn-register(href='/signup')
| Register

<% if(filters.facebookAuth || filters.twitterAuth || filters.googleAuth) {%>
<% if(filters.oauth) {%>
hr

div<% if(filters.facebookAuth) {%>
Expand Down
36 changes: 14 additions & 22 deletions app/templates/client/app/account(auth)/login/login(less).less
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
<% if(filters.bootstrap) { %>
// Colors
<% if(filters.bootstrap) { %>// Colors
// --------------------------------------------------

@btnText: #fff;
@btnTextAlt: #000;

@btnTextAlt: #000;<% if (filters.oauth) { %>
<% if (filters.facebookAuth) { %>
@btnFacebookBackground: #3B5998;
@btnFacebookBackgroundHighlight: #133783;

@btnFacebookBackgroundHighlight: #133783;<% } if (filters.twitterAuth) { %>
@btnTwitterBackground: #2daddc;
@btnTwitterBackgroundHighlight: #0271bf;

@btnTwitterBackgroundHighlight: #0271bf;<% } if (filters.googleAuth) { %>
@btnGooglePlusBackground: #dd4b39;
@btnGooglePlusBackgroundHighlight: #c53727;<% } %>
@btnGithubBackground: #fafafa;
@btnGithubBackgroundHighlight: #ccc;

@btnGooglePlusBackground: #dd4b39;
@btnGooglePlusBackgroundHighlight: #c53727;


// Social buttons
// --------------------------------------------------

<% if (filters.facebookAuth) { %>
.btn-facebook {
.button-variant(@btnText; @btnFacebookBackgroundHighlight; @btnFacebookBackgroundHighlight);
}

}<% } if (filters.twitterAuth) { %>
.btn-twitter {
.button-variant(@btnText; @btnTwitterBackground; @btnTwitterBackgroundHighlight);
}

.btn-github {
.button-variant(@btnTextAlt; @btnGithubBackground; @btnGithubBackgroundHighlight);
}

}<% } if (filters.googleAuth) { %>
.btn-google-plus {
.button-variant(@btnText; @btnGooglePlusBackground; @btnGooglePlusBackgroundHighlight);
}<% } %>
}<% } %>
.btn-github {
.button-variant(@btnTextAlt; @btnGithubBackground; @btnGithubBackgroundHighlight);
}<% } %><% } %>
36 changes: 14 additions & 22 deletions app/templates/client/app/account(auth)/login/login(sass).scss
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
<% if(filters.bootstrap) { %>
// Colors
<% if(filters.bootstrap) { %>// Colors
// --------------------------------------------------

$btnText: #fff;
$btnTextAlt: #000;

$btnTextAlt: #000;<% if (filters.oauth) { %>
<% if (filters.facebookAuth) { %>
$btnFacebookBackground: #3B5998;
$btnFacebookBackgroundHighlight: #133783;

$btnFacebookBackgroundHighlight: #133783;<% } if (filters.twitterAuth) { %>
$btnTwitterBackground: #2daddc;
$btnTwitterBackgroundHighlight: #0271bf;

$btnTwitterBackgroundHighlight: #0271bf;<% } if (filters.googleAuth) { %>
$btnGooglePlusBackground: #dd4b39;
$btnGooglePlusBackgroundHighlight: #c53727;<% } %>
$btnGithubBackground: #fafafa;
$btnGithubBackgroundHighlight: #ccc;

$btnGooglePlusBackground: #dd4b39;
$btnGooglePlusBackgroundHighlight: #c53727;


// Social buttons
// --------------------------------------------------

<% if (filters.facebookAuth) { %>
.btn-facebook {
@include button-variant($btnText, $btnFacebookBackgroundHighlight, $btnFacebookBackgroundHighlight);
}

}<% } if (filters.twitterAuth) { %>
.btn-twitter {
@include button-variant($btnText, $btnTwitterBackground, $btnTwitterBackgroundHighlight);
}

.btn-github {
@include button-variant($btnTextAlt, $btnGithubBackground, $btnGithubBackgroundHighlight);
}

}<% } if (filters.googleAuth) { %>
.btn-google-plus {
@include button-variant($btnText, $btnGooglePlusBackground, $btnGooglePlusBackgroundHighlight);
}<% } %>
}<% } %>
.btn-github {
@include button-variant($btnTextAlt, $btnGithubBackground, $btnGithubBackgroundHighlight);
}<% } %><% } %>
20 changes: 10 additions & 10 deletions app/templates/client/app/account(auth)/login/login(stylus).styl
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// Social buttons
<% if (filters.oauth) { %>// Social buttons
// --------------------------------------------------

<% if (filters.facebookAuth) { %>
.btn-facebook
color: #fff;
background-color: #3B5998;
border-color: #133783;

<% } if (filters.twitterAuth) { %>
.btn-twitter
color: #fff;
background-color: #2daddc;
border-color: #0271bf;

.btn-github
color: #fff;
background-color: #fafafa;
border-color: #ccc;

<% } if (filters.googleAuth) { %>
.btn-google-plus
color: #fff;
background-color: #dd4b39;
border-color: #c53727;
border-color: #c53727;
<% } %>
.btn-github
color: #fff;
background-color: #fafafa;
border-color: #ccc;<% } %>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

angular.module '<%= scriptAppName %>'
.controller 'LoginCtrl', ($scope, Auth, $location, $window) ->
.controller 'LoginCtrl', ($scope, Auth, $location<% if(filters.oauth) {%>, $window<% } %>) ->
$scope.user = {}
$scope.errors = {}
$scope.login = (form) ->
Expand All @@ -18,6 +18,6 @@ angular.module '<%= scriptAppName %>'

.catch (err) ->
$scope.errors.other = err.message

<% if(filters.oauth) {%>
$scope.loginOauth = (provider) ->
$window.location.href = '/auth/' + provider
$window.location.href = '/auth/' + provider<% } %>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('<%= scriptAppName %>')
.controller('LoginCtrl', function ($scope, Auth, $location, $window) {
.controller('LoginCtrl', function ($scope, Auth, $location<% if (filters.oauth) { %>, $window<% } %>) {
$scope.user = {};
$scope.errors = {};

Expand All @@ -22,8 +22,8 @@ angular.module('<%= scriptAppName %>')
});
}
};

<% if(filters.oauth) {%>
$scope.loginOauth = function(provider) {
$window.location.href = '/auth/' + provider;
};
};<% } %>
});
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ <h1>Sign up</h1>
Login
</a>
</div>

<% if(filters.facebookAuth || filters.twitterAuth || filters.googleAuth) {%>
<% if(filters.oauth) {%>
<hr>
<div><% if(filters.facebookAuth) {%>
<a class="btn btn-facebook" href="" ng-click="loginOauth('facebook')">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ div(ng-include='"components/navbar/navbar.html"')
a.btn.btn-default.btn-lg.btn-register(href='/login')
| Login


<% if(filters.facebookAuth || filters.twitterAuth || filters.googleAuth) {%>
<% if(filters.oauth) {%>
hr

div<% if(filters.facebookAuth) {%>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

angular.module '<%= scriptAppName %>'
.controller 'SignupCtrl', ($scope, Auth, $location, $window) ->
.controller 'SignupCtrl', ($scope, Auth, $location<% if(filters.oauth) {%>, $window<% } %>) ->
$scope.user = {}
$scope.errors = {}
$scope.register = (form) ->
Expand All @@ -25,6 +25,6 @@ angular.module '<%= scriptAppName %>'
angular.forEach err.errors, (error, field) ->
form[field].$setValidity 'mongoose', false
$scope.errors[field] = error.message

<% if(filters.oauth) {%>
$scope.loginOauth = (provider) ->
$window.location.href = '/auth/' + provider
$window.location.href = '/auth/' + provider<% } %>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('<%= scriptAppName %>')
.controller('SignupCtrl', function ($scope, Auth, $location, $window) {
.controller('SignupCtrl', function ($scope, Auth, $location<% if (filters.oauth) { %>, $window<% } %>) {
$scope.user = {};
$scope.errors = {};

Expand Down Expand Up @@ -30,8 +30,8 @@ angular.module('<%= scriptAppName %>')
});
}
};

<% if(filters.oauth) {%>
$scope.loginOauth = function(provider) {
$window.location.href = '/auth/' + provider;
};
};<% } %>
});
27 changes: 12 additions & 15 deletions app/templates/server/api/user(auth)/user.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var crypto = require('crypto');

var authTypes = ['github', 'twitter', 'facebook', 'google'];
var crypto = require('crypto');<% if(filters.oauth) { %>
var authTypes = ['github', 'twitter', 'facebook', 'google'];<% } %>

var UserSchema = new Schema({
name: String,
Expand All @@ -15,11 +14,11 @@ var UserSchema = new Schema({
},
hashedPassword: String,
provider: String,
salt: String,
facebook: {},
twitter: {},
github: {},
google: {}
salt: String<% if (filters.oauth) { %>,<% if (filters.facebookAuth) { %>
facebook: {},<% } %><% if (filters.twitterAuth) { %>
twitter: {},<% } %><% if (filters.googleAuth) { %>
google: {},<% } %>
github: {}<% } %>
});

/**
Expand Down Expand Up @@ -63,18 +62,16 @@ UserSchema
// Validate empty email
UserSchema
.path('email')
.validate(function(email) {
// if you are authenticating by any of the oauth strategies, don't validate
if (authTypes.indexOf(this.provider) !== -1) return true;
.validate(function(email) {<% if (filters.oauth) { %>
if (authTypes.indexOf(this.provider) !== -1) return true;<% } %>
return email.length;
}, 'Email cannot be blank');

// Validate empty password
UserSchema
.path('hashedPassword')
.validate(function(hashedPassword) {
// if you are authenticating by any of the oauth strategies, don't validate
if (authTypes.indexOf(this.provider) !== -1) return true;
.validate(function(hashedPassword) {<% if (filters.oauth) { %>
if (authTypes.indexOf(this.provider) !== -1) return true;<% } %>
return hashedPassword.length;
}, 'Password cannot be blank');

Expand Down Expand Up @@ -104,7 +101,7 @@ UserSchema
.pre('save', function(next) {
if (!this.isNew) return next();

if (!validatePresenceOf(this.hashedPassword) && authTypes.indexOf(this.provider) === -1)
if (!validatePresenceOf(this.hashedPassword)<% if (filters.oauth) { %> && authTypes.indexOf(this.provider) === -1<% } %>)
next(new Error('Invalid password'));
else
next();
Expand Down
24 changes: 10 additions & 14 deletions app/templates/server/config/_local.env.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@
// This file should not be tracked by git.

module.exports = {
DOMAIN: 'http://localhost:9000',
SESSION_SECRET: "<%= _.slugify(appname) + '-secret' %>",

FACEBOOK_ID: 'app-id',
FACEBOOK_SECRET: 'secret',

TWITTER_ID: 'app-id',
TWITTER_SECRET: 'secret',

GOOGLE_ID: 'app-id',
GOOGLE_SECRET: 'secret',

DOMAIN: 'http://localhost:9000',
SESSION_SECRET: "<%= _.slugify(appname) + '-secret' %>",<% if (filters.facebookAuth) { %>
FACEBOOK_ID: 'app-id',
FACEBOOK_SECRET: 'secret',<% } if (filters.twitterAuth) { %>
TWITTER_ID: 'app-id',
TWITTER_SECRET: 'secret',<% } if (filters.googleAuth) { %>
GOOGLE_ID: 'app-id',
GOOGLE_SECRET: 'secret',<% } %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would vote for preserving previous formatting here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to make some refactoring in server/auth/, could we add:

FACEBOOK_SCOPE: ['email', 'user_about_me'],
GOOGLE_SCOPE: [
      'https://www.googleapis.com/auth/userinfo.profile',
      'https://www.googleapis.com/auth/userinfo.email'
    ]

(For Twitter, there is no scope)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should depend on system (is it even possible on heroku?) ability to set array as an environment variable. Also scope isn't secret, and _local.env.js is excluded from git, so this change would make app migration more difficult (one cannot obtain previously set scope from "developer console").

Regarding Google scope, seems like there are some changes on a horizon and scope should be changed to: scope: ['profile', 'email'].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Right. Any idea where to put scope, @chester1000?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? It's enough to just replace:

[
  'https://www.googleapis.com/auth/userinfo.profile',
  'https://www.googleapis.com/auth/userinfo.email'
]

with

[ 'profile', 'email' ]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, putting them in config/environment/index.js would prevent us from using your trick with just passing reference to them as a first param in {Facebook,Google,Twitter}Strategy.

Sorry, I don't understand this point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully this will remind you ;)

PS. use > for quoting

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I understand. But, it will work and will not prevent using my "trick". I will make a PR to show you.

PS: Thank for the quote. I was seeking the markdown shortcut and didn't find it immediately, so I passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I will preserve the line breaks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Control debug level for modules using visionmedia/debug
// DEBUG: ""
};
DEBUG: ''
};