Skip to content
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
37 changes: 19 additions & 18 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ var passport = require('passport')
, FacebookStrategy = require('passport-facebook').Strategy;

var routes = require('./routes/index');
var login = require('./routes/login');
var chats = require('./routes/chats');
var users = require('./routes/users');
var posts = require('./routes/posts');
var chat = require('./routes/chat');
var account = require('./routes/account');
var learn = require('./routes/learn');

var app = express();

Expand All @@ -36,7 +37,7 @@ winston.add(winston.transports.File, {
level: 'info'
});

mongoose.connect('mongodb://booklog3:123456@ds053130.mongolab.com:53130/booklog3');
mongoose.connect('mongodb://booklog3:123456@ds047622.mongolab.com:47622/booklog3');
mongoose.connection.on('error', function() {
winston.log('error', 'MongoDB: error');
});
Expand All @@ -45,8 +46,8 @@ mongoose.connection.on('open', function() {
});

var postSchema = new mongoose.Schema({
title : { type: String },
content : { type: String },
title: { type: String },
content: { type: String },
userId: { type: mongoose.Schema.Types.ObjectId, ref: 'user' },
timeCreated: { type: Date, default: Date.now }
});
Expand All @@ -59,13 +60,21 @@ var userSchema = new mongoose.Schema({
facebook: { type: Object, select: false }
});

var lessonSchema = new mongoose.Schema({
lessonName: { type: String, unique: true },
lessonLearn: { type: String, unique: true },
timeCreated: { type: Date, default: Date.now }
});

var Post = mongoose.model('post', postSchema);
var User = mongoose.model('user', userSchema);
var Learn = mongoose.model('learn', lessonSchema);

app.db = {
model: {
Post: Post,
User: User,
Learn: Learn
}
};

Expand Down Expand Up @@ -94,8 +103,9 @@ passport.deserializeUser(function(obj, done) {
});

passport.use(new FacebookStrategy({
clientID: '1559480364270197',
clientSecret: '4d5d1e9389c179142348cbb7044bdab1',
clientID: '410866279063864',
clientSecret: '3887b8914b81d0e778d3b9af10775fb6',
// callbackURL: "http://alwaysladylove.com/auth/facebook/callback"
callbackURL: "/auth/facebook/callback"
},
function(accessToken, refreshToken, profile, done) {
Expand All @@ -113,7 +123,6 @@ passport.use(new FacebookStrategy({

user = doc;
}
console.log(user);

return done(null, user); // verify callback
});
Expand All @@ -124,22 +133,14 @@ passport.use(new FacebookStrategy({
app.use(cors());

app.use('/', routes);
app.use('/', login);
app.use('/', posts);
app.use('/', chats);
app.use('/users', users);
app.use('/account', account);
app.use('/learn', learn);


app.get('/login/facebook',
passport.authenticate('facebook'));

app.get('/auth/facebook/callback',
passport.authenticate('facebook', { failureRedirect: '/login/fail' }),
function(req, res) {
// Successful authentication, redirect home.
res.redirect('/');
});

// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
Expand Down Expand Up @@ -179,4 +180,4 @@ app.use(function(err, req, res, next) {
});


module.exports = app;
module.exports = app;
48 changes: 42 additions & 6 deletions bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,33 @@ var WebSocketServer = require('websocket').server;
* Get port from environment and store in Express.
*/

/**
* Create HTTP server in worker process.
*/
var port = normalizePort(process.env.PORT || '3000');
var server = http.createServer(app);

/*
* WebSocket Section
*/
var wsServer = new WebSocketServer({
httpServer: server,
autoAcceptConnections: false
});

// create WebSocket connections array
app.clients = [];

if (cluster.isMaster) {
console.log('CPUs: ' + cpuCount);

// Create a worker for each CPU
for (var i = 0; i < cpuCount ; i++) {
cluster.fork({PORT: port + i});
cluster.fork({
PORT: port + i
});
}
} else {
/**
* Create HTTP server in worker process.
*/
var port = process.env.PORT;
var server = http.createServer(app);

console.log('HTTP server listening on port ' + port + ' at worker ' + cluster.worker.id);

Expand All @@ -41,6 +53,8 @@ if (cluster.isMaster) {
server.on('error', onError);
server.on('listening', onListening);

wsServer.on('request', onWsRequest);

/*
* WebSocket Section
*/
Expand Down Expand Up @@ -78,6 +92,28 @@ if (cluster.isMaster) {
}


function onWsConnMessage(message) {
if (message.type == 'utf8') {
console.log('Received message: ' + message.utf8Data);
} else if (message.type == 'binary') {
console.log('Received binary data.');
}
}

function onWsConnClose(reasonCode, description) {
console.log(' Peer disconnected with reason: ' + reasonCode);
}

function onWsRequest(request) {
var connection = request.accept('echo-protocol', request.origin);
console.log("WebSocket connection accepted.");

app.clients.push(connection);

connection.on('message', onWsConnMessage);
connection.on('close', onWsConnClose);
}

/**
* Normalize a port into a number, string, or false.
*/
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"passport": "^0.2.2",
"passport-facebook": "^2.0.0",
"serve-favicon": "~2.2.1",
"websocket": "^1.0.21",
"winston": "^1.0.1",
"websocket": "~1.0.21"
"nginx": "0.0.0",
"forever": "~0.15.1"
}
}
14 changes: 14 additions & 0 deletions public/booklog/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ <h4><%= content %></h4>
</div>
</script>

<script type="text/template" id="tmpl-login">
<div class="col-md-4 portfolio-item">
<a href="http://localhost:3000/login/facebook">
<img src="https://cdn0.iconfinder.com/data/icons/yooicons_set01_socialbookmarks/128/social_facebook_box_blue.png"/>
</a>
<a href="">
<img src="https://cdn0.iconfinder.com/data/icons/yooicons_set01_socialbookmarks/128/social_twitter_box_white.png"/>
</a>
<a href="">
<img src="https://cdn0.iconfinder.com/data/icons/yooicons_set01_socialbookmarks/128/social_google_box.png"/>
</a>
</div>
</script>

<nav class="navbar navbar-fixed-top navbar-inverse" role="navigation">
<div class="container">
<div class="navbar-header">
Expand Down
10 changes: 9 additions & 1 deletion public/booklog/javascripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var app = app || {};
**/
app.Message = Backbone.Model.extend({
url: function() {
return 'http://test.booklog.io:3000/1/post'
return 'http://alwaysladylove.com/1/post'
+ ( this.id === null ? '' : '/' + this.id );
},
id: null,
Expand Down Expand Up @@ -77,7 +77,15 @@ app.FormView = Backbone.View.extend({
}
});

app.LoginView = Backbone.View.extend({
el: '#myModal',
render: function(){
this.modal();
}
});

$(document).ready(function(){
app.contentView = new app.ContentView();
app.formView = new app.FormView();
app.loginView = new app.LoginView();
});
62 changes: 59 additions & 3 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,34 @@
<img class="img-responsive dp img-circle" src="http://lorempixel.com/180/180/">
</a>
<h4 class="media-heading"><%= post.title %></h4>
<h6><%= post.timeCreated %></h6>
<button id="subject" data-id="<%= post._id %>" class="btn btn-success">Read More</button>
</div>
<% }); %>
</script>

<script id='post-single' type='text/template'>
<div class="col-md-12 portfolio-item">
<h2 class="media-heading"><%= title %></h2>
<h4><%= content %></h4>
<h2 class="media-heading"><%= title %></h2>
<h6><%= timeCreated %></h6>
<h4><%= content %></h4>
</div>
<div>
<button id="delete" data-id="<%= _id %>" class="btn btn-danger">Delete</button>
</div>
</script>

<script id='tmpl-login' type='text/template'>
<div class="col-md-4 portfolio-item">
<a href="http://localhost:3000/login/facebook">
<img src="https://cdn0.iconfinder.com/data/icons/yooicons_set01_socialbookmarks/128/social_facebook_box_blue.png"/>
</a>
<a href="">
<img src="https://cdn0.iconfinder.com/data/icons/yooicons_set01_socialbookmarks/128/social_twitter_box_white.png"/>
</a>
<a href="">
<img src="https://cdn0.iconfinder.com/data/icons/yooicons_set01_socialbookmarks/128/social_google_box.png"/>
</a>
</div>
</script>

Expand All @@ -58,18 +77,55 @@ <h4><%= content %></h4>
<li><a href="#contact">張貼文章</a>
</li>
</ul>
<ul class='nav navbar-nav navbar-right'>
<li><a href='/login'><span class='glyphicon glyphicon-log-in'></span> Login</a></li>
<!-- Trigger the modal with a button -->
<li><button type='button' class='btn btn-default btn-lg' id='op-modal'><span class="glyphicon glyphicon-log-in"></span> Login</button></li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>

<div class="container">
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">

<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Login</h4>
</div>
<div class="modal-body">
<span>Choose one you love</span><br>
<a href="http://localhost:3000/login/facebook">
<img src="https://cdn0.iconfinder.com/data/icons/yooicons_set01_socialbookmarks/128/social_facebook_box_blue.png"/>
</a>
<a href="">
<img src="https://cdn0.iconfinder.com/data/icons/yooicons_set01_socialbookmarks/128/social_twitter_box_white.png"/>
</a>
<a href="">
<img src="https://cdn0.iconfinder.com/data/icons/yooicons_set01_socialbookmarks/128/social_google_box.png"/>
</a> </div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>

</div>
</div>

</div>

<div class="container">

<div class="row">

<div class="col-lg-12">
<h1 class="page-header">Jollen's 最新文章
<h1 class="page-header">afoo's 最新文章
<small>Showcase Your Work</small>
</h1>
</div>
Expand Down
Loading