mirror of
https://github.com/jsbin/jsbin.git
synced 2026-01-18 15:18:04 +00:00
Add github buttons and routes.
This commit is contained in:
parent
7f6c870e20
commit
aeee052d79
31
lib/app.js
31
lib/app.js
@ -14,6 +14,34 @@ var nodemailer = require('nodemailer'),
|
||||
url = require('url'),
|
||||
flattened;
|
||||
|
||||
var passport = require('passport'),
|
||||
GitHubStrategy = require('passport-github').Strategy;
|
||||
|
||||
/**
|
||||
* Passport configuration
|
||||
*/
|
||||
|
||||
passport.serializeUser(function(user, done) {
|
||||
done(null, user);
|
||||
});
|
||||
|
||||
passport.deserializeUser(function(obj, done) {
|
||||
done(null, obj);
|
||||
});
|
||||
|
||||
passport.use(new GitHubStrategy({
|
||||
clientID: options.github.id,
|
||||
clientSecret: options.github.secret
|
||||
},
|
||||
function(accessToken, refreshToken, profile, done) {
|
||||
console.log.apply(console, [].slice.call(arguments));
|
||||
return done(null, {
|
||||
access_token: accessToken,
|
||||
profile: profile
|
||||
});
|
||||
}
|
||||
));
|
||||
|
||||
app.store = store;
|
||||
app.mailer = (function (mail) {
|
||||
var mailTransport = null,
|
||||
@ -147,6 +175,9 @@ app.connect = function (callback) {
|
||||
app.use(middleware.limitContentLength({limit: app.set('max-request-size')}));
|
||||
app.use(express.cookieParser(app.set('session secret')));
|
||||
app.use(express.cookieSession({key: 'jsbin', cookie: {maxAge: 365 * 24 * 60 * 60 * 1000}}));
|
||||
// Passport
|
||||
app.use(passport.initialize());
|
||||
app.use(passport.session());
|
||||
app.use(express.urlencoded());
|
||||
app.use(express.json());
|
||||
app.use(middleware.csrf({ ignore: ['/', /^\/api\//] }));
|
||||
|
||||
@ -2,6 +2,9 @@ var utils = require('../utils'),
|
||||
errors = require('../errors'),
|
||||
Observable = utils.Observable;
|
||||
|
||||
var passport = require('passport'),
|
||||
GitHubStrategy = require('passport-github').Strategy;
|
||||
|
||||
module.exports = Observable.extend({
|
||||
constructor: function SessionHandler(sandbox) {
|
||||
Observable.apply(this, arguments);
|
||||
@ -354,5 +357,37 @@ module.exports = Observable.extend({
|
||||
}
|
||||
|
||||
return url;
|
||||
},
|
||||
|
||||
/**
|
||||
* Github Auth
|
||||
*/
|
||||
|
||||
github: passport.authenticate('github'),
|
||||
|
||||
githubPassportCallback: passport.authenticate('github', { failureRedirect: '/' }),
|
||||
|
||||
githubCallback: function(req, res, next) {
|
||||
var githubUser = req.user;
|
||||
this.models.user.load(req.user.profile.username, function (err, user) {
|
||||
if (err) return next(err);
|
||||
|
||||
// if user but current user not signed in, don't allow them to connect github
|
||||
// if user and the current user is signed in then link the accounts
|
||||
// if no user then this is a new user, create them an account
|
||||
// this.models.user.create({
|
||||
// name: githubUser.profile.username,
|
||||
// }, function (err, id) {});
|
||||
console.log();
|
||||
console.log();
|
||||
console.log.apply(console, [].slice.call(arguments));
|
||||
console.log();
|
||||
console.log();
|
||||
console.log(req.session.user);
|
||||
console.log();
|
||||
console.log();
|
||||
res.redirect('/');
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@ -76,6 +76,10 @@ module.exports = function (app) {
|
||||
app.get('/forgot', sessionHandler.requestToken);
|
||||
app.get('/reset', sessionHandler.resetPassword);
|
||||
|
||||
// GitHub auth
|
||||
app.get('/auth/github', sessionHandler.github);
|
||||
app.get('/auth/github/callback', sessionHandler.githubPassportCallback, sessionHandler.githubCallback);
|
||||
|
||||
// List
|
||||
app.get('/list/:user', binHandler.getUserBins);
|
||||
app.get('/list', binHandler.getUserBins);
|
||||
|
||||
@ -34,7 +34,9 @@
|
||||
"async": "~0.1.22",
|
||||
"lynx": "0.0.11",
|
||||
"file-db": "0.0.2",
|
||||
"underscore": "~1.4.4"
|
||||
"underscore": "~1.4.4",
|
||||
"passport": "~0.1.17",
|
||||
"passport-github": "~0.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"grunt": "~0.4.1",
|
||||
|
||||
@ -54,6 +54,43 @@ textarea:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.btn-github {
|
||||
font-size: 1em;
|
||||
background: #f0f0f0;
|
||||
background: linear-gradient(0deg, #f0f0f0, #fefefe);
|
||||
box-shadow: 0 1px 2px #eee;
|
||||
border: 1px solid #aaa;
|
||||
border-radius: 4px;
|
||||
padding: 6px 10px 5px;
|
||||
cursor: pointer;
|
||||
display: inline;
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
}
|
||||
.btn-github:hover {
|
||||
background: linear-gradient(0deg, #e8e8e8, #f8f8f8);
|
||||
}
|
||||
|
||||
.btn-github img {
|
||||
vertical-align: middle;
|
||||
top: -1px;
|
||||
position: relative;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.login .btn-github {
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.login-splitter {
|
||||
display: block;
|
||||
font-style: italic;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
[hidden],
|
||||
.hidden {
|
||||
display: none !important;
|
||||
|
||||
BIN
public/images/github-32.png
Normal file
BIN
public/images/github-32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
@ -96,6 +96,10 @@
|
||||
<input type=submit value="Update account">
|
||||
<a class="logout" href="#logout">Logout</a>
|
||||
</div>
|
||||
<div>
|
||||
<span class="login-splitter">or</span>
|
||||
<a class="btn-github" href="/auth/github"><img src="{{static}}/images/github-32.png"> Link your Github account</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form action="{{root}}/logout" method="POST" id="logout">
|
||||
@ -138,6 +142,10 @@
|
||||
<input type=submit value="Log in">
|
||||
<a id="lostpass" href="{{root}}/forgot">Reset password</a>
|
||||
</div>
|
||||
<div>
|
||||
<span class="login-splitter">or</span>
|
||||
<a class="btn-github" href="/auth/github"><img src="{{static}}/images/github-32.png"> Sign in with Github</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@ -162,6 +170,10 @@
|
||||
<div>
|
||||
<input type=submit value="Register">
|
||||
</div>
|
||||
<div>
|
||||
<span class="login-splitter">or</span>
|
||||
<a class="btn-github" href="/auth/github"><img src="{{static}}/images/github-32.png"> Register with Github</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user