Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

got everyauth integrated

  • Loading branch information...
commit c39f8773c44db5fdddb4c7ad8cc575f0d1c28dd2 2 parents 7c90880 + d81e6bb
@JustinBeckwith JustinBeckwith authored
View
3  .gitignore
@@ -1,2 +1,3 @@
node_modules
-server.js.logs
+server.js.logs
+settings.json
View
5 package.json
@@ -3,7 +3,10 @@
, "version": "0.0.1"
, "private": true
, "dependencies": {
- "express": "2.5.0"
+ "node-uuid": ">= 1.3.3"
+ , "everyauth": ">= 0.2.29"
+ , "nconf": ">= 0.5.1"
+ , "express": ">= 2.5.0"
, "jade": ">= 0.18.0"
, "less": ">= 1.1.5"
, "socket.io": ">=0.8.7"
View
BIN  public/images/facebookLogin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
74 public/stylesheets/style.css
@@ -76,7 +76,8 @@ h5, h6 {
font-size: 1em;
}
/* main layout
-----------------------------------------------------------*/.content-wrapper {
+----------------------------------------------------------*/
+.content-wrapper {
margin: 0 auto;
max-width: 960px;
}
@@ -109,7 +110,8 @@ footer {
height: 100px;
}
/* site title
-----------------------------------------------------------*/.site-title {
+----------------------------------------------------------*/
+.site-title {
color: #c8c8c8;
font-family: Rockwell, Consolas, "Courier New", Courier, monospace;
font-size: 2.3em;
@@ -122,7 +124,8 @@ footer {
text-decoration: none;
}
/* login
-----------------------------------------------------------*/#login {
+----------------------------------------------------------*/
+#login {
display: block;
font-size: .85em;
margin: 20px 0 12px;
@@ -143,12 +146,13 @@ footer {
#login ul {
margin: 0;
}
-#login ul li {
+#login li {
display: inline;
list-style: none;
}
/* menu
-----------------------------------------------------------*/ul#menu {
+----------------------------------------------------------*/
+ul#menu {
font-size: 1.3em;
font-weight: 600;
margin: 0;
@@ -169,7 +173,9 @@ ul#menu li a:hover {
text-decoration: none;
}
/* page elements
-----------------------------------------------------------*//* featured */.featured {
+----------------------------------------------------------*/
+/* featured */
+.featured {
background-color: #fff;
}
.featured .content-wrapper {
@@ -188,7 +194,8 @@ ul#menu li a:hover {
.featured p {
font-size: 1.1em;
}
-/* page titles */hgroup.title {
+/* page titles */
+hgroup.title {
margin-bottom: 10px;
}
hgroup.title h1, hgroup.title h2 {
@@ -198,12 +205,14 @@ hgroup.title h2 {
font-weight: normal;
margin-left: 3px;
}
-/* features */section.feature {
+/* features */
+section.feature {
width: 300px;
float: left;
padding: 10px;
}
-/* ordered list */ol.round {
+/* ordered list */
+ol.round {
list-style-type: none;
padding-left: 0;
}
@@ -220,7 +229,8 @@ ol.round li.two {
ol.round li.three {
background: url("../images/orderedListThree.png") no-repeat;
}
-/* content */article {
+/* content */
+article {
float: left;
width: 70%;
}
@@ -239,7 +249,8 @@ aside ul li {
.label {
font-weight: 700;
}
-/* login page */#loginForm {
+/* login page */
+#loginForm {
border-right: solid 2px #c8c8c8;
float: left;
width: 45%;
@@ -253,7 +264,8 @@ aside ul li {
float: left;
width: 50%;
}
-/* contact */.contact h3 {
+/* contact */
+.contact h3 {
font-size: 1.2em;
}
.contact p {
@@ -263,7 +275,8 @@ aside ul li {
border: 1px solid #333;
margin: 5px 0 0 10px;
}
-/* forms */fieldset {
+/* forms */
+fieldset {
border: none;
margin: 0;
padding: 0;
@@ -305,13 +318,15 @@ fieldset input[type="submit"] {
font-weight: 600;
padding: 7px;
}
-/* ajax login/registration dialog */.modal-popup {
+/* ajax login/registration dialog */
+.modal-popup {
font-size: 0.7em;
}
.modal-popup input[type="text"], .modal-popup input[type="password"] {
width: 90%;
}
-/* info and errors */.message-info {
+/* info and errors */
+.message-info {
border: 1px solid;
clear: both;
padding: 10px 20px;
@@ -332,7 +347,8 @@ fieldset input[type="submit"] {
.error {
color: #e80c4d;
}
-/* styles for validation helpers */.field-validation-error {
+/* styles for validation helpers */
+.field-validation-error {
color: #e80c4d;
font-weight: bold;
}
@@ -374,38 +390,34 @@ a.twitter {
}
/********************
* Mobile Styles *
-********************/@media only screen and (max-width: 850px) {
+********************/
+@media only screen and (max-width: 850px) {
/* header
----------------------------------------------------------*/
header .float-left, header .float-right {
float: none;
}
-
/* logo */
header .site-title {
margin: 10px;
text-align: center;
}
-
/* login */
#login {
font-size: .85em;
margin: 0 0 12px;
text-align: center;
}
-
#login ul {
margin: 5px 0;
padding: 0;
}
-
#login li {
display: inline;
list-style: none;
margin: 0;
padding: 0;
}
-
#login a {
background: none;
color: #999;
@@ -413,100 +425,82 @@ a.twitter {
margin: 2px;
padding: 0;
}
-
#login a:hover {
color: #333;
}
-
/* menu */
nav {
margin-bottom: 5px;
}
-
ul#menu {
margin: 0;
padding: 0;
text-align: center;
}
-
ul#menu li {
margin: 0;
padding: 0;
}
-
/* main layout
----------------------------------------------------------*/
.main-content, .featured + .main-content {
background-position: 10px 0;
}
-
.content-wrapper {
padding-right: 10px;
padding-left: 10px;
}
-
.featured .content-wrapper {
padding: 10px;
}
-
/* page content */
article, aside {
float: none;
width: 100%;
}
-
/* ordered list */
ol.round {
list-style-type: none;
padding-left: 0;
}
-
ol.round li {
padding-left: 10px;
margin: 25px 0;
}
-
ol.round li.one, ol.round li.two, ol.round li.three {
background: none;
}
-
/* features */
section.feature {
float: none;
padding: 10px;
width: auto;
}
-
section.feature img {
color: #999;
content: attr(alt);
font-size: 1.5em;
font-weight: 600;
}
-
/* forms */
fieldset input[type="text"], fieldset input[type="password"] {
width: 90%;
}
-
/* login page */
#loginForm {
border-right: none;
float: none;
width: auto;
}
-
#loginForm .validation-error {
display: block;
margin-left: 15px;
}
-
#socialLoginForm {
margin-left: 0;
float: none;
width: auto;
}
-
/* footer
----------------------------------------------------------*/
footer {
View
18 public/stylesheets/style.less
@@ -149,8 +149,9 @@ footer {
font-size: .85em;
margin: 20px 0 12px;
text-align: right;
+}
- a {
+ #login a {
background-color: #d3dce0;
margin-left: 10px;
margin-right: 3px;
@@ -158,20 +159,21 @@ footer {
text-decoration: none;
}
- a.username {
+ #login a.username {
background: none;
margin-left: 0px;
text-decoration: underline;
}
- ul {
+ #login ul {
margin: 0;
- li {
- display: inline;
- list-style: none;
- }
}
-}
+
+ #login li {
+ display: inline;
+ list-style: none;
+ }
+
/* menu
----------------------------------------------------------*/
View
34 routes/account.js
@@ -1,9 +1,8 @@
-var passport = require('passport');
module.exports = function(app) {
// user account page
- app.get('/account', ensureAuthenticated, function(req, res) {
+ app.get('/account', function(req, res) {
res.render('account/account', { user: req.user });
});
@@ -12,40 +11,9 @@ module.exports = function(app) {
res.render('account/login', { user: req.user });
});
- // post target for login
- app.post('/login',
- passport.authenticate('local', { failureRedirect: '/login' }),
- function(req, res) {
- res.redirect('/');
- });
-
// logout
app.get('/logout', function(req, res) {
- req.logout();
res.redirect('/');
});
-
-
- function ensureAuthenticated(req, res, next) {
- if(req.isAuthenticated()) { return next(); }
- res.redirect('/login')
- }
-
-
-
-
-
- // Redirect the user to Twitter for authentication. When complete, Twitter
- // will redirect the user back to the application at
- // /auth/twitter/callback
- app.get('/auth/twitter', passport.authenticate('twitter'));
-
- // Twitter will redirect the user to this URL after approval. Finish the
- // authentication process by attempting to obtain an access token. If
- // access was granted, the user will be logged in. Otherwise,
- // authentication has failed.
- app.get('/auth/twitter/callback',
- passport.authenticate('twitter', { successRedirect: '/',
- failureRedirect: '/login' }));
}
View
89 server.js
@@ -8,8 +8,67 @@
var express = require('express')
, less = require('less')
, connect = require('connect')
- , passport = require('passport')
- , TwitterStrategy = require('passport-twitter').Strategy;
+ , everyauth = require('everyauth')
+ , nconf = require('nconf');
+
+
+
+
+
+
+/**
+* OAUTH FEDERATED IDENTITY
+* -------------------------------------------------------------------------------------------------
+* allows users to log in and register using OAuth
+**/
+
+
+nconf.file({file: 'settings.json'});
+
+everyauth.debug = true;
+
+// Configure Facebook auth
+var usersById = {},
+ nextUserId = 0,
+ usersByFacebookId = {},
+ usersByTwitId = {};
+
+everyauth.
+ everymodule.
+ findUserById(function (id, callback) {
+ callback(null, usersById[id]);
+ });
+
+everyauth.
+ facebook.
+ appId(nconf.get('facebook:applicationId')).
+ appSecret(nconf.get('facebook:applicationSecret')).
+ findOrCreateUser(
+ function(session, accessToken, accessTokenExtra, fbUserMetadata){
+ return usersByFacebookId[fbUserMetadata.claimedIdentifier] ||
+ (usersByFacebookId[fbUserMetadata.claimedIdentifier] =
+ addUser('facebook', fbUserMetadata));
+ }).
+ redirectPath('/');
+
+everyauth
+ .twitter
+ .consumerKey(nconf.get('twitter:consumerKey'))
+ .consumerSecret(nconf.get('twitter:consumerSecret'))
+ .findOrCreateUser( function (sess, accessToken, accessSecret, twitUser) {
+ return usersByTwitId[twitUser.id] || (usersByTwitId[twitUser.id] = addUser('twitter', twitUser));
+ })
+ .redirectPath('/');
+
+
+function addUser (source, sourceUser) {
+ var user = {id: ++nextUserId, source: sourceUser};
+ usersById[nextUserId] = user;
+ return user;
+}
+
+
+
var app = module.exports = express.createServer();
@@ -26,9 +85,8 @@ app.configure(function() {
app.use(express.methodOverride());
app.use(require('./middleware/locals'));
app.use(express.cookieParser());
- app.use(express.session({ secret: 'keyboard cat' }));
- app.use(passport.initialize());
- app.use(passport.session());
+ app.use(express.session({ secret: 'azure zomg' }));
+ app.use(everyauth.middleware());
app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] }));
app.use(connect.static(__dirname + '/public'));
app.use(app.router);
@@ -50,26 +108,6 @@ app.use(require('./middleware/errorHandler')(errorOptions));
-/**
-* OAUTH FEDERATED IDENTITY
-* -------------------------------------------------------------------------------------------------
-* allows users to log in and register using OAuth
-**/
-
-passport.use(new TwitterStrategy({
- consumerKey: 'HjrVsJgQ4jkx8h7GSdl6w',
- consumerSecret: 'r5IEGTeczmZ43b9SvO9ZcBb0MgTANyL2MQLyqLQ',
- callbackURL: "/auth/twitter/callback"
-},
- function(token, tokenSecret, profile, done) {
- console.log(profile);
- //User.findOrCreate(..., function (err, user) {
- // if (err) { return done(err); }
- // done(null, user);
- //});
- }
-));
-
/**
* ROUTING
@@ -133,6 +171,7 @@ io.sockets.on('connection', function(socket) {
* this starts up the server on the given port
**/
+everyauth.helpExpress(app);
app.listen(process.env.PORT || 3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
View
10 settings.example.json
@@ -0,0 +1,10 @@
+{
+ "facebook": {
+ "applicationId": "{your Facebook app ID}",
+ "applicationSecret": "{your Facebook app secret}"
+ },
+ "twitter": {
+ "consumerKey": "{ your twitter consumer key }",
+ "consumerSecret": "{ your twitter consumer secret }"
+ }
+}
View
8 views/account/login.jade
@@ -26,4 +26,10 @@ section(class="main-content")
form(method="post")
fieldset
legend Log in using another service
- a(href="/auth/twitter") Log in using your Twitter account
+ a.fb_button_medium(href='/auth/facebook', class="button")
+ img(src=base + '/images/facebookLogin.png')
+
+ br
+
+ a(href='/auth/twitter', style='border: 0px')
+ img(style='border: 0px', src='https://si0.twimg.com/images/dev/buttons/sign-in-with-twitter-l.png')
View
1  views/chat.jade
@@ -8,7 +8,6 @@ block javascripts
script(src='/socket.io/socket.io.js')
script(src='/javascripts/chat.js')
-
section(class="main-content")
h3= title
View
16 views/layout.jade
@@ -2,7 +2,7 @@
html
head
- if (typeof(title) == 'undefined')
- title Welcome to WebMatrix
+ title Express Starter Template
- else
title= title
@@ -21,10 +21,16 @@ html
div(class="float-right")
section#login
ul
- li
- a(href="/") Register
- li
- a(href="/login") Log in
+ -if(!everyauth.loggedIn)
+ li
+ a(href="/login") Log in
+ -else
+ -if(everyauth.facebook)
+ li Welcome !{everyauth.facebook.user.first_name} !{everyauth.facebook.user.last_name}!
+ -else if(everyauth.twitter)
+ li Welcome !{everyauth.twitter.user.name}!
+ li
+ a(href="/logout") Logout
nav
ul#menu
li
View
2  views/layout_mobile.jade
@@ -25,7 +25,7 @@ html
nav
ul#menu
li
- a(href="/") Home |
+ a(href="/") Tasks |
li
a(href="/chat") Chat |
li
Please sign in to comment.
Something went wrong with that request. Please try again.