-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6ae367d
Showing
216 changed files
with
106,704 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Creado por Marcos R. Guevara para prácticar con node. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var apiKeys = { | ||
facebook: { | ||
'appID' : '116449598774128', | ||
'appSecret' : '5ce4579fcfe2aef20e1b2dda02a9f3bc', | ||
'callbackUrl' : 'http://localhost:3000/user/facebook/callback' | ||
} | ||
}; | ||
module.exports = apiKeys; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
var express = require('express'); | ||
var path = require('path'); | ||
var mailConfig = require('./mailConfig'); | ||
var favicon = require('serve-favicon'); | ||
var logger = require('morgan'); | ||
var cookieParser = require('cookie-parser'); | ||
var bodyParser = require('body-parser'); | ||
var morgan = require('morgan'); | ||
var mongoose = require('mongoose'); | ||
var passport = require('passport'); | ||
var LocalStrategy = require('passport-local').Strategy; | ||
var FacebookStrategy = require('passport-facebook').Strategy; | ||
var socialPassport = require('./controllers/socialPassportController'); | ||
var apiKeys = require('./apiKeys'); | ||
var session = require('express-session'); | ||
var io = require('socket.io'); | ||
|
||
var app = express(); | ||
// var for routes | ||
var index = require('./routes/index'); | ||
var users = require('./routes/users'); | ||
var projects = require('./routes/projects'); | ||
var messages = require('./routes/messages'); | ||
var follows = require('./routes/follows'); | ||
var favs = require('./routes/favs'); | ||
var files = require('./routes/files'); | ||
|
||
// para devolver estado por consola. | ||
app.use(morgan('combined')); | ||
// view engine setup | ||
app.set('views', path.join(__dirname, 'views')); | ||
app.set('view engine', 'jade'); | ||
var Account = require('./models/accounts'); | ||
passport.use(new LocalStrategy(Account.authenticate())); | ||
passport.serializeUser(Account.serializeUser()); | ||
passport.deserializeUser(Account.deserializeUser()); | ||
|
||
//social Login facebook | ||
passport.use(new FacebookStrategy({ | ||
clientID: apiKeys.facebook.appID, | ||
clientSecret: apiKeys.facebook.appSecret, | ||
callbackURL: apiKeys.facebook.callbackUrl, | ||
'profileFields': ['id', 'displayName', 'email', 'name'], | ||
}, socialPassport.facebook )); | ||
|
||
app.use(logger('dev')); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(cookieParser()); | ||
//app.use(multer({dest : "./userFiles/projectImage"})) | ||
|
||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
app.use(require('express-session')({ | ||
secret: 's1crette', | ||
resave: true, | ||
saveUninitialized: true, | ||
cookie: { maxAge : 3600000 } //1 Hour | ||
})); | ||
|
||
app.use(passport.initialize()); | ||
app.use(passport.session()); | ||
//Rutas express | ||
app.use('/', index); | ||
app.use('/user', users); | ||
app.use('/project', projects); | ||
app.use('/message', messages); | ||
app.use('/follow', follows); | ||
app.use('/fav', favs); | ||
app.use('/file', files); | ||
|
||
|
||
// catch 404 and forward to error handler | ||
app.use(function(req, res, next) { | ||
var err = new Error('Not Found'); | ||
err.status = 404; | ||
next(err); | ||
}); | ||
|
||
// error handlers | ||
|
||
// development error handler | ||
// will print stacktrace | ||
if (app.get('env') === 'development') { | ||
app.use(function(err, req, res, next) { | ||
res.status(err.status || 500); | ||
res.render('error', { | ||
message: err.message, | ||
error: err | ||
}); | ||
}); | ||
} | ||
|
||
// production error handler | ||
// no stacktraces leaked to user | ||
app.use(function(err, req, res, next) { | ||
res.status(err.status || 500); | ||
res.render('error', { | ||
message: err.message, | ||
error: {} | ||
}); | ||
}); | ||
|
||
mongoose.connect('mongodb://localhost/archiers'); | ||
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var app = require('../app'); | ||
var debug = require('debug')('archiers:server'); | ||
var http = require('http'); | ||
|
||
/** | ||
* Get port from environment and store in Express. | ||
*/ | ||
|
||
var port = normalizePort(process.env.PORT || '3000'); | ||
app.set('port', port); | ||
|
||
/** | ||
* Create HTTP server. | ||
*/ | ||
|
||
var server = http.createServer(app); | ||
var io = require('socket.io').listen(server); | ||
io.sockets.on('connection', function(){ | ||
console.log('tira coño'); | ||
}); | ||
/** | ||
* Listen on provided port, on all network interfaces. | ||
*/ | ||
server.listen(port); | ||
server.on('error', onError); | ||
server.on('listening', onListening); | ||
|
||
/** | ||
* Normalize a port into a number, string, or false. | ||
*/ | ||
|
||
function normalizePort(val) { | ||
var port = parseInt(val, 10); | ||
|
||
if (isNaN(port)) { | ||
// named pipe | ||
return val; | ||
} | ||
|
||
if (port >= 0) { | ||
// port number | ||
return port; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Event listener for HTTP server "error" event. | ||
*/ | ||
|
||
function onError(error) { | ||
if (error.syscall !== 'listen') { | ||
throw error; | ||
} | ||
|
||
var bind = typeof port === 'string' | ||
? 'Pipe ' + port | ||
: 'Port ' + port; | ||
|
||
// handle specific listen errors with friendly messages | ||
switch (error.code) { | ||
case 'EACCES': | ||
console.error(bind + ' requires elevated privileges'); | ||
process.exit(1); | ||
break; | ||
case 'EADDRINUSE': | ||
console.error(bind + ' is already in use'); | ||
process.exit(1); | ||
break; | ||
default: | ||
throw error; | ||
} | ||
} | ||
|
||
/** | ||
* Event listener for HTTP server "listening" event. | ||
*/ | ||
|
||
function onListening() { | ||
var addr = server.address(); | ||
var bind = typeof addr === 'string' | ||
? 'pipe ' + addr | ||
: 'port ' + addr.port; | ||
debug('Listening on ' + bind); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Marcos R. Guevara |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
var Account = require('../models/accounts'); | ||
var mongoose = require('mongoose'); | ||
var passport = require('passport'); | ||
var fav = require('../models/favs'); | ||
var Project = require('../models/projects'); | ||
module.exports = { | ||
|
||
plain : function (req, res) { | ||
if(!req.user){ | ||
res.redirect('/'); | ||
} | ||
else{ | ||
fav.find(function(err, favs){ | ||
Project.find(function(err, projects){ | ||
Account.find(function(err, users){ | ||
Project.find({'ProjectOwner' : req.user.id }, function(err, ownProjects){ | ||
res.render('fav/resume', { | ||
title : "favoritos", | ||
user : req.user, | ||
listFavs : favs, | ||
listProjects: projects, | ||
listOwnProjects : ownProjects, | ||
listUsers : users, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
}, | ||
newFav : function (req, res){ | ||
if(!req.user){ | ||
res.redirect('/user/login'); | ||
} | ||
var user = req.user; | ||
Project.findById(req.params.id, function(err, project){ | ||
console.log(project); | ||
var saveFav = new fav({ | ||
favUserId : req.user.id, | ||
favProjectId : project.id, | ||
alreadyFav : true, | ||
}); | ||
fav.findOne({favUserId : req.user.id, favProjectId : project.id }, function(err, already){ | ||
console.log(already); | ||
if(already == null){ | ||
saveFav.save(); | ||
} | ||
}); | ||
res.redirect('/project/'+project.id); | ||
}); | ||
}, | ||
removeFav : function (req, res){ | ||
if(!req.user){ | ||
res.redirect('/user/login'); | ||
} | ||
fav.findOne({'favProjectId' : req.params.id, 'favUserId' : req.user.id}, function(err, fav){ | ||
fav.remove(); | ||
res.redirect('/'); | ||
}); | ||
}, | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
var fs = require('fs'); | ||
var filepath = "../public/userFiles/projectImage/"; | ||
var mongoose = require('mongoose'); | ||
var passport = require('passport'); | ||
var Project = require('../models/projects'); | ||
var File = require('../models/files'); | ||
var multer = require('multer'); | ||
|
||
|
||
module.exports = { | ||
|
||
plain : function(req, res){ | ||
if(!req.user){ | ||
res.redirect('/user/login'); | ||
} | ||
File.find({FileOwner : req.user.id}, function(err, files){ | ||
res.render('file/resume',{ | ||
title: "Administrar imágenes y documentos", | ||
user: req.user, | ||
listFiles : files, | ||
}); | ||
}); | ||
|
||
}, | ||
|
||
|
||
/**********/ | ||
|
||
|
||
upload : function(req, res){ | ||
if(!req.user){ | ||
res.redirect('/user/login'); | ||
} | ||
var files = req.files; | ||
var typeOfFile; | ||
var savingFile; | ||
for (file in files){ | ||
console.log(files[file]); | ||
if(files[file].filename != null){ | ||
typeOfFile = "image"; | ||
} | ||
else{ | ||
typeOfFile = "no file"; | ||
}; | ||
savingFile = new File({ | ||
FileOwner : req.user.id, | ||
FileName : files[file].filename, | ||
FileType : typeOfFile, | ||
}); | ||
console.log(savingFile); | ||
savingFile.save(function(err){ | ||
if(err){ | ||
console.log(err); | ||
res.render('project/create', { | ||
title: "La información no es válida, volver a introducir los datos", | ||
}); | ||
} | ||
}); | ||
} | ||
res.redirect('/file'); | ||
}, | ||
|
||
/**********/ | ||
|
||
delete : function (req, res){ | ||
if(!req.user){ | ||
res.redirect('/user/login'); | ||
} | ||
File.findById(req.params.id, function(err, file){ | ||
if(err){ | ||
console.log("error"); | ||
console.log(err); | ||
res.redirect('/file'); | ||
} | ||
if(!err){ | ||
console.log(filepath+file.FileNames); | ||
fs.stat(filepath+file.FileNames, function(err, stat, next){ | ||
if(err == null){ | ||
fs.unlinkSync(filepath+file.FileNames); | ||
} | ||
else{ | ||
next(); | ||
} | ||
}); | ||
|
||
|
||
} | ||
file.remove(function(err){ | ||
if(err){ | ||
console.log(err); | ||
res.redirect('/file'); | ||
} | ||
res.redirect('/file'); | ||
}); | ||
}); | ||
|
||
}, | ||
} |
Oops, something went wrong.