Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
90e450c
feature(module) added clever-email module
GusSa Jan 20, 2014
cdd7947
fix(merge) fixed after merging
Jan 20, 2014
269098b
added ability to send mail in different systems
Jan 21, 2014
21f8ba8
befor testing WIP
Jan 21, 2014
1b5e927
testing email servece WIP
Jan 22, 2014
6d78a36
finished testing for clever-email module
Jan 23, 2014
d8c06e4
fix err in mailer
Jan 23, 2014
24a369a
added UserController.requiresLogin in routing
Jan 23, 2014
2f19b2f
clear package.json
Jan 23, 2014
bde7d27
feature(module) created clever-auth module WIP
Jan 29, 2014
6b8f1df
fix(auth): Strips auth down to what we need and fixes for ORM.
durango Jan 30, 2014
33030e3
fix(orm): Adds ORM fix.
durango Jan 30, 2014
9f0396b
update service and controller and test for it WIP
Jan 31, 2014
25fcd81
updated test for controller WIP
Jan 31, 2014
d2d02da
fix console.log
Jan 31, 2014
1357c84
updated tests for controller and service
Feb 2, 2014
573a74f
deleted unnecessary file
Feb 2, 2014
ee86167
deleted unnecessary file
Feb 2, 2014
82ef841
feature(module) create clever-auth-google module
Feb 4, 2014
9c61be4
added tests and updated cervise, model and controller
Feb 4, 2014
a5f4496
added tests and updated cervise, model and controller
Feb 4, 2014
f3ac568
updated handleLoginJson
Feb 7, 2014
cddf241
feature(module) added clever-auth-github module
Feb 7, 2014
ac15bab
added clever-auth-facebook module and updated clever-auth-github module
Feb 10, 2014
a50f240
added clever-auth-twitter WIP
Feb 10, 2014
bfda062
update controllers clever-auth-twitter - WIP
Feb 10, 2014
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
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ module.exports = function( grunt ) {
unit: {
options: {
require: [ 'chai' ],
reporter: 'spec'
reporter: 'spec',
timeout: 5000
},
src: [ 'tests/unit/*.js' ].concat( getModulePaths( 'tests', 'unit', '*.js' ) )
},
Expand Down
2 changes: 1 addition & 1 deletion lib/config/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var path = require( 'path' );

module.exports = require( path.resolve( [ __dirname, '..', 'config' ].join( path.sep ) ) + path.sep );
module.exports = require( path.resolve( [ __dirname, '..', '..', 'config' ].join( path.sep ) ) + path.sep );
59 changes: 0 additions & 59 deletions modules/auth/module.js

This file was deleted.

27 changes: 0 additions & 27 deletions modules/auth/package.json

This file was deleted.

21 changes: 21 additions & 0 deletions modules/clever-auth-facebook/config/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"clever-auth-facebook": {
"secretKey": "youMustChangeMe",

"redis": {
"host": "localhost",
"port": "6379",
"prefix": "",
"key": ""
},

"facebook": {
"clientId": "247066242129783",
"clientSecret": "b9ee18a9c582994aeac022c2713256ee",
"redirectURIs": "http://localhost:8080/auth/facebook/return"
},

"frontendURL": "http://localhost:9000/"

}
}
121 changes: 121 additions & 0 deletions modules/clever-auth-facebook/controllers/UserFacebookController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
var config = require ( 'config' )[ 'clever-auth-facebook' ]
, passport = require ( 'passport' )
, qs = require ( 'qs' )
, FacebookStrategy = require('passport-facebook').Strategy;

var scope = 'email,user_about_me';

module.exports = function ( UserFacebookService ) {

passport.serializeUser( function ( user, done ) {
done( null, user );
} );

passport.deserializeUser( function ( user, done ) {
done( null, user )
} );

passport.use( new FacebookStrategy(
{
clientID: config.facebook.clientId,
clientSecret: config.facebook.clientSecret,
callbackURL: config.facebook.redirectURIs,
scope: scope
},
function ( accessToken, refreshToken, profile, done ) {

UserFacebookService
.findOrCreate( profile, accessToken )
.then( function( fbUser ) {
return UserFacebookService.authenticate ( fbUser, profile )
})
.then( UserFacebookService.updateAccessedDate )
.then( done.bind( null, null ) )
.fail( done );
}
));


return (require( 'classes' ).Controller).extend (
{
service: UserFacebookService
},
{
listAction: function () {
UserFacebookService.listUsers()
.then( this.proxy( 'handleServiceMessage' ) )
.fail( this.proxy( 'handleException' ) );
}, //tested

getAction: function () {
var fbuId = this.req.params.id;

UserFacebookService
.findUserById( fbuId )
.then( this.proxy( 'handleServiceMessage' ) )
.fail( this.proxy( 'handleException' ) );
}, //tested

deleteAction: function () {
var fbuId = this.req.params.id;

UserFacebookService
.deleteUser( fbuId )
.then( this.proxy( 'handleServiceMessage' ) )
.fail( this.proxy( 'handleException' ) );
}, //tested

loginAction: function () {
var params = {
client_id: config.facebook.clientId,
redirect_uri: config.facebook.redirectURIs,
scope: scope
};

this.send( { url: 'https://www.facebook.com/dialog/oauth?' + qs.stringify( params ) }, 200 );

}, //tested

returnAction: function () {
passport.authenticate( 'facebook', this.proxy( 'handleLocalUser' ) )( this.req, this.res, this.next );
},

handleLocalUser: function ( err, user ) {

if ( err ) return this.handleException( err );

if ( !user ) {
this.res.statusCode = 302;
this.res.setHeader( 'body', {} );
this.res.setHeader( 'Location', config.frontendURL );
this.res.end();
} else {
this.loginUserJson( user );
}
},

loginUserJson: function ( user ) {
this.req.login( user, this.proxy( 'handleLoginJson', user ) );
},

handleLoginJson: function ( user, err ) {
if ( err ) return this.handleException( err );

this.res.statusCode = 302;
this.res.setHeader( 'body', user );
this.res.setHeader( 'Location', config.frontendURL );
this.res.end();
},

handleServiceMessage: function ( obj ) {

if ( obj.statuscode ) {
this.send( obj.message, obj.statuscode );
return;
}

this.send( obj, 200 );
}

} );
};
70 changes: 70 additions & 0 deletions modules/clever-auth-facebook/models/orm/UserFacebookModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
module.exports = function ( sequelize, DataTypes ) {
return sequelize.define( "UserFacebook",
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
validate: {
isEmail: true
}
},
firstname: {
type: DataTypes.STRING,
allowNull: true
},
lastname: {
type: DataTypes.STRING,
allowNull: true
},
facebookid: {
type: DataTypes.STRING,
allowNull: false
},
picture: {
type: DataTypes.STRING,
allowNull: true
},
link: {
type: DataTypes.STRING,
allowNull: true
},
locale: {
type: DataTypes.STRING,
allowNull: true
},
token: {
type: DataTypes.STRING,
allowNull: false
},
accessedAt: {
type: DataTypes.DATE
},
UserId: {
type: DataTypes.INTEGER
}
},
{
paranoid: true,

getterMethods: {
fullName: function () {
return [ this.getDataValue( 'firstname' ), this.getDataValue( 'lastname' )].join( ' ' );
}
},

instanceMethods: {
toJSON: function () {
var values = this.values;
values.fullName = this.fullName;
delete values.token;
return values;
}
}
} );
};
Loading