Commit a5650948 authored by Vytor Calixto's avatar Vytor Calixto 👾
Browse files

Bad commit: um monte de coisa de uma vez

parent 3e7342ab
......@@ -86,7 +86,7 @@
width: 100%; }
.half {
width: 50%; }
width: 48%; }
.one-third {
width: 33%; }
......@@ -103,6 +103,18 @@
.inline-block {
display: inline-block; }
.flex {
display: flex; }
.no-wrap {
flex-wrap: nowrap; }
.space-around {
justify-content: space-around; }
.stretch {
align-items: stretch; }
.button, .icon-button {
color: white !important;
border: none;
......
.card,.search-bar{box-sizing:border-box}.clickable,a:hover{cursor:pointer}@font-face{font-family:Montserrat;font-style:normal;font-weight:400;src:local('Montserrat-Regular'),url(https://fonts.gstatic.com/s/montserrat/v6/zhcz-_WihjSQC0oHJ9TCYC3USBnSvpkopQaUR-2r7iU.ttf) format('truetype')}@font-face{font-family:Merriweather;font-style:normal;font-weight:400;src:local('Merriweather'),url(https://fonts.gstatic.com/s/merriweather/v8/RFda8w1V0eDZheqfcyQ4EInF5uFdDttMLvmWuJdhhgs.ttf) format('truetype')}.clearfix:after,.clearfix:before,.header:after,.header:before,.list .list-item:after,.list .list-item:before{display:block;clear:both;content:''}.normal{background-color:#39628d}.dark,header{background-color:#1E2251}.darker{background-color:#1a1a1a}.button:active,.icon-button:active,.light{background-color:#bfdede}.lighter,body{background-color:#F5F5F5}.red,footer{background-color:#EE3437}.error{background-color:#EE3437!important}.inactive{background-color:grey}.float-right{float:right}.float-left{float:left}.margin{margin:20px}.no-margin{margin:0}.margin-vertical{margin-top:20px;margin-bottom:20px}.margin-horizontal{margin-left:20px;margin-right:20px}.padding{padding:20px}.no-padding{padding:0}.padding-vertical{padding-top:20px;padding-bottom:20px}.padding-horizontal{padding-left:20px;padding-right:20px}.text-center{text-align:center}.text-left{text-align:left}.text-right{text-align:right}.center-vertical{margin:auto 0}.center-block{display:table;margin:auto}.full{width:100%}.half{width:50%}.one-third{width:33%}.two-thirds{width:66%}.one-quarter{width:25%}.three-quarters{width:75%}.inline-block{display:inline-block}.button,.icon-button{color:#fff!important;border:none;border-radius:2px;font-size:110%;padding:5px;margin-top:10px;margin-bottom:10px;-webkit-transition:background-color .2s ease;-moz-transition:background-color .2s ease;-ms-transition:background-color .2s ease;-o-transition:background-color .2s ease;transition:background-color .2s ease}footer,header,header a,header a:hover{color:#fff}.button:hover,.icon-button:hover{cursor:pointer;text-decoration:none}.button:active,.icon-button:active{-webkit-transition:background-color .2s ease-out;-moz-transition:background-color .2s ease-out;-ms-transition:background-color .2s ease-out;-o-transition:background-color .2s ease-out;transition:background-color .2s ease-out}.button:focus,.icon-button:focus{outline:0}.float-button{position:relative;top:-1.3em}.icon-button{border-radius:0;font-family:FontAwesome;font-size:1.5em;position:relative;top:1.5px;left:-6px;color:#fff;padding:6px;-webkit-transition:background-color .2s ease-in-out;-moz-transition:background-color .2s ease-in-out;-ms-transition:background-color .2s ease-in-out;-o-transition:background-color .2s ease-in-out;transition:background-color .2s ease-in-out}body,footer a:hover{color:#1a1a1a}.button-circle{border-radius:50%}.list .list-title{padding:20px;text-align:center}.list .list-item{margin:0;padding:20px;border-top:1px solid #ccc}ul.list{list-style-type:none;padding:0;margin:0}.card{padding:20px;box-shadow:0 1px 2px #aaa;background:#fff;margin-bottom:20px}.card>.card{box-shadow:0 2px 5px #aaa}.card-list{padding:0}.page-wrap{margin-bottom:4em}.page-wrap:after{content:"";display:block}.header form,.header h2,.header nav,.uploadInfo{display:inline-block}.sticky{position:absolute;bottom:0;width:100%;height:4em}.header nav,html{position:relative}html{min-height:100%}body{font-family:Merriweather,serif;padding-bottom:4em;text-align:center;margin:0}a{color:#39628d;text-decoration:none}a:hover{text-decoration:underline;color:#1E2251}form{margin:0 auto}header,nav{font-family:Montserrat,sans-serif}header{box-shadow:1px 1px 3px rgba(0,0,0,.6);padding:5px 0}header h3{font-weight:100}footer{padding:20px 0}footer a{color:inherit}.index{background-image:url(../imgs/Farol.png);background-position:center center;background-size:contain;background-repeat:no-repeat;margin-top:20px;padding-top:20%}.index h1{margin:0;font-family:Montserrat,sans-serif;font-size:5em;text-transform:uppercase;color:#1E2251;text-shadow:-1px -1px 0 #F5F5F5,1px -1px 0 #F5F5F5,-1px 1px 0 #F5F5F5,1px 1px 0 #F5F5F5}.search-bar{background-color:rgba(255,255,255,.9);box-shadow:inset 0 1px 3px #ddd;font-size:1.3em;padding:5px;border:1px solid #bfdede}.search-bar:focus{border:1px solid #39628d;outline:0}.search-bar::-webkit-search-cancel-button{-webkit-appearance:none}.search-bar::-webkit-search-cancel-button:after{font-family:FontAwesome;content:'\f00d';color:#EE3437}.uploadInfo{box-shadow:2px 2px 15px rgba(0,0,0,.4);background-color:#fff;width:200px;margin:5px 15px}.uploadThumb{max-width:100%}.thumb{height:75px;border:1px solid #bfdede;margin:10px 5px 0 0}.header{text-align:left;padding:0}.header nav{height:100%;bottom:0}.header form .search-bar{width:25pc}.header h2{padding:20px 20px 0}.header h2 a{color:#fff;text-decoration:none}.header h2 a:hover{text-decoration:underline}.warning{border:1px solid #EE3437}.hover-shadow{box-shadow:0 0 0 rgba(0,0,0,.6);-webkit-transition:box-shadow .2s ease-in-out;-moz-transition:box-shadow .2s ease-in-out;-ms-transition:box-shadow .2s ease-in-out;-o-transition:box-shadow .2s ease-in-out;transition:box-shadow .2s ease-in-out}.hover-shadow:hover{box-shadow:2px 2px 5px rgba(0,0,0,.6);-webkit-transition:box-shadow .2s ease-in-out;-moz-transition:box-shadow .2s ease-in-out;-ms-transition:box-shadow .2s ease-in-out;-o-transition:box-shadow .2s ease-in-out;transition:box-shadow .2s ease-in-out}
\ No newline at end of file
.card,.search-bar{box-sizing:border-box}.clickable,a:hover{cursor:pointer}@font-face{font-family:Montserrat;font-style:normal;font-weight:400;src:local('Montserrat-Regular'),url(https://fonts.gstatic.com/s/montserrat/v6/zhcz-_WihjSQC0oHJ9TCYC3USBnSvpkopQaUR-2r7iU.ttf) format('truetype')}@font-face{font-family:Merriweather;font-style:normal;font-weight:400;src:local('Merriweather'),url(https://fonts.gstatic.com/s/merriweather/v8/RFda8w1V0eDZheqfcyQ4EInF5uFdDttMLvmWuJdhhgs.ttf) format('truetype')}.clearfix:after,.clearfix:before,.header:after,.header:before,.list .list-item:after,.list .list-item:before{display:block;clear:both;content:''}.normal{background-color:#39628d}.dark,header{background-color:#1E2251}.darker{background-color:#1a1a1a}.button:active,.icon-button:active,.light{background-color:#bfdede}.lighter,body{background-color:#F5F5F5}.red,footer{background-color:#EE3437}.error{background-color:#EE3437!important}.inactive{background-color:grey}.float-right{float:right}.float-left{float:left}.margin{margin:20px}.no-margin{margin:0}.margin-vertical{margin-top:20px;margin-bottom:20px}.margin-horizontal{margin-left:20px;margin-right:20px}.padding{padding:20px}.no-padding{padding:0}.padding-vertical{padding-top:20px;padding-bottom:20px}.padding-horizontal{padding-left:20px;padding-right:20px}.text-center{text-align:center}.text-left{text-align:left}.text-right{text-align:right}.center-vertical{margin:auto 0}.center-block{display:table;margin:auto}.full{width:100%}.half{width:48%}.one-third{width:33%}.two-thirds{width:66%}.one-quarter{width:25%}.three-quarters{width:75%}.inline-block{display:inline-block}.flex{display:flex}.no-wrap{flex-wrap:nowrap}.space-around{justify-content:space-around}.stretch{align-items:stretch}.button,.icon-button{color:#fff!important;border:none;border-radius:2px;font-size:110%;padding:5px;margin-top:10px;margin-bottom:10px;-webkit-transition:background-color .2s ease;-moz-transition:background-color .2s ease;-ms-transition:background-color .2s ease;-o-transition:background-color .2s ease;transition:background-color .2s ease}footer,header,header a,header a:hover{color:#fff}.button:hover,.icon-button:hover{cursor:pointer;text-decoration:none}.button:active,.icon-button:active{-webkit-transition:background-color .2s ease-out;-moz-transition:background-color .2s ease-out;-ms-transition:background-color .2s ease-out;-o-transition:background-color .2s ease-out;transition:background-color .2s ease-out}.button:focus,.icon-button:focus{outline:0}.float-button{position:relative;top:-1.3em}.icon-button{border-radius:0;font-family:FontAwesome;font-size:1.5em;position:relative;top:1.5px;left:-6px;color:#fff;padding:6px;-webkit-transition:background-color .2s ease-in-out;-moz-transition:background-color .2s ease-in-out;-ms-transition:background-color .2s ease-in-out;-o-transition:background-color .2s ease-in-out;transition:background-color .2s ease-in-out}body,footer a:hover{color:#1a1a1a}.button-circle{border-radius:50%}.list .list-title{padding:20px;text-align:center}.list .list-item{margin:0;padding:20px;border-top:1px solid #ccc}ul.list{list-style-type:none;padding:0;margin:0}.card{padding:20px;box-shadow:0 1px 2px #aaa;background:#fff;margin-bottom:20px}.card>.card{box-shadow:0 2px 5px #aaa}.card-list{padding:0}.page-wrap{margin-bottom:4em}.page-wrap:after{content:"";display:block}.header form,.header h2,.header nav,.uploadInfo{display:inline-block}.sticky{position:absolute;bottom:0;width:100%;height:4em}.header nav,html{position:relative}html{min-height:100%}body{font-family:Merriweather,serif;padding-bottom:4em;text-align:center;margin:0}a{color:#39628d;text-decoration:none}a:hover{text-decoration:underline;color:#1E2251}form{margin:0 auto}header,nav{font-family:Montserrat,sans-serif}header{box-shadow:1px 1px 3px rgba(0,0,0,.6);padding:5px 0}header h3{font-weight:100}footer{padding:20px 0}footer a{color:inherit}.index{background-image:url(../imgs/Farol.png);background-position:center center;background-size:contain;background-repeat:no-repeat;margin-top:20px;padding-top:20%}.index h1{margin:0;font-family:Montserrat,sans-serif;font-size:5em;text-transform:uppercase;color:#1E2251;text-shadow:-1px -1px 0 #F5F5F5,1px -1px 0 #F5F5F5,-1px 1px 0 #F5F5F5,1px 1px 0 #F5F5F5}.search-bar{background-color:rgba(255,255,255,.9);box-shadow:inset 0 1px 3px #ddd;font-size:1.3em;padding:5px;border:1px solid #bfdede}.search-bar:focus{border:1px solid #39628d;outline:0}.search-bar::-webkit-search-cancel-button{-webkit-appearance:none}.search-bar::-webkit-search-cancel-button:after{font-family:FontAwesome;content:'\f00d';color:#EE3437}.uploadInfo{box-shadow:2px 2px 15px rgba(0,0,0,.4);background-color:#fff;width:200px;margin:5px 15px}.uploadThumb{max-width:100%}.thumb{height:75px;border:1px solid #bfdede;margin:10px 5px 0 0}.header{text-align:left;padding:0}.header nav{height:100%;bottom:0}.header form .search-bar{width:25pc}.header h2{padding:20px 20px 0}.header h2 a{color:#fff;text-decoration:none}.header h2 a:hover{text-decoration:underline}.warning{border:1px solid #EE3437}.hover-shadow{box-shadow:0 0 0 rgba(0,0,0,.6);-webkit-transition:box-shadow .2s ease-in-out;-moz-transition:box-shadow .2s ease-in-out;-ms-transition:box-shadow .2s ease-in-out;-o-transition:box-shadow .2s ease-in-out;transition:box-shadow .2s ease-in-out}.hover-shadow:hover{box-shadow:2px 2px 5px rgba(0,0,0,.6);-webkit-transition:box-shadow .2s ease-in-out;-moz-transition:box-shadow .2s ease-in-out;-ms-transition:box-shadow .2s ease-in-out;-o-transition:box-shadow .2s ease-in-out;transition:box-shadow .2s ease-in-out}
\ No newline at end of file
......@@ -2,15 +2,15 @@ $padding: 20px;
$margin: 20px;
.float-right{
float: right;
float: right;
}
.float-left{
float: left;
float: left;
}
.margin{
margin: $margin;
margin: $margin;
}
.no-margin{
......@@ -71,7 +71,7 @@ $margin: 20px;
}
.half{
width: 50%;
width: 48%;
}
.one-third{
......@@ -96,4 +96,20 @@ $margin: 20px;
.clearfix{
@extend %clearfix;
}
\ No newline at end of file
}
.flex{
display: flex;
}
.no-wrap{
flex-wrap: nowrap;
}
.space-around{
justify-content: space-around;
}
.stretch{
align-items: stretch;
}
<!DOCTYPE html>
<html>
<% include ../partials/head %>
<body>
<% include ../partials/admin-header %>
<section class="page-wrap">
<div class="card text-left margin">
<p><a href="/admin/uploads">
<% if (pendentes == 1) { %>
Existe <%= pendentes %> upload pendente.
<% } else { %>
Existem <%= pendentes %> uploads pendentes.
<% } %>
</a></p>
</div>
</section>
<% include ../partials/footer %>
</body>
</html>
<!DOCTYPE html>
<html>
<% include ../partials/head %>
<body>
<% include ../partials/admin-header %>
<% if (message.length > 0) { %>
<div class="card margin"><%= message %></div>
<% } %>
<section class="page-wrap margin card">
<h1><%= materia.codigo %> - <%= materia.nome %></h1>
<form method="post">
<label for="codigo">Código: </label>
<input type="text" name="codigo" value="<%= materia.codigo %>">
<br>
<label for="nome">Nome: </label>
<input type="text" name="nome" value="<%= materia.nome %>">
<br>
<input type="submit" name="submit" value="Enviar" class="button normal">
<a href="/admin/materias" class="button red">Cancelar</a>
</form>
</section>
<% include ../partials/footer %>
</body>
</html>
<!DOCTYPE html>
<html>
<% include ../partials/head %>
<body>
<% include ../partials/admin-header %>
<section class="page-wrap">
<% if (message.length > 0) { %>
<div class="card margin"><%= message %></div>
<% } %>
<div class="card card-list margin">
<ul class="list">
<h2 class="list-title">Matérias</h2>
<input type="search" name="filter" class="search-bar margin-vertical two-thirds" placeholder="Busca" />
<li class="list-item text-left">
<span>Nova matéria:</span>
<form method="post">
<input type="text" name="codigo" ng-model="codigo" placeholder="Código" required/>
<input type="text" name="nome" ng-model="nome" placeholder="Nome" required/>
<button type="submit" class="button dark hover-shadow float-right">
<i class="fa fa-plus fa-fw"></i>
</button>
</form>
</li>
<% for(var i=0; i < materias.length; i++) { %>
<li class="list-item text-left">
<%= materias[i].codigo %> - <%= materias[i].nome %>
<div class="float-right">
<a href="/admin/materias/<%= materias[i]._id %>" class="button normal hover-shadow">
<i class="fa fa-edit fa-fw"></i>
</a>
<a href="/admin/materias/delete/<%= materias[i]._id %>" class="button red hover-shadow">
<i class="fa fa-close fa-fw"></i>
</a>
</div>
</li>
<% } %>
<% if (materias.length == 0) { %>
<li class="list-item">Não há matérias cadastradas.</li>
<% } %>
</ul>
</div>
</section>
<% include ../partials/footer %>
</body>
</html>
<!DOCTYPE html>
<html>
<% include ../partials/head %>
<body>
<% include ../partials/admin-header %>
<section class="page-wrap">
<div class="card card-list margin clearfix">
<ul class="list">
<h2 class="list-title">Arquivos pendentes</h2>
<% for(var i=0; i < uploads.length; i++) { %>
<li class="list-item text-left">
<%= uploads[i].tipo %> <%= uploads[i].substitutiva%> <%= uploads[i].numero %> <%= uploads[i].materia %>
<br>Upload feito por <%= uploads[i].usuario.nome%>
</li>
<% } %>
<% if(uploads.length == 0) { %>
<li>
Não há uploads pendentes.
</li>
<% } %>
</ul>
</div>
</section>
<% include ../partials/footer %>
</body>
</html>
<header class="header">
<h2 class="no-margin float-left">
<span class="fa">&#xf13d;</span> <a href="/">Farol - Moderação</a>
</h2>
<nav class="float-right padding">
<a href="/admin/" class="padding">Home</a>
<a href="/admin/uploads" class="padding">Uploads</a>
<a href="/admin/materias" class="padding">Materias</a>
<a href="/admin/professores" class="padding">Professores</a>
<% if (user.admin) { %>
<a href="/admin/usuarios" class="padding">Usuarios</a>
<% } %>
</nav>
</header>
<!DOCTYPE html>
<html>
<% include partials/head %>
<body>
<% include partials/basic-header %>
<section class="card clearfix margin">
<h1>Upload</h1>
<div>
<form method="post" enctype="multipart/form-data">
<input type="file" name="arquivo">
<br>
<input type="text" name="materia" placeholder="Matéria" required>
<br>
<input type="text" name="professor" placeholder="Professor" required>
<br>
<input type="text" name="numero" placeholder="numero">
<br>
<input type="number" name="ano" placeholder="Ano" value="2015">
<br>
<input type="number" name="semestre" placeholder="Semestre" value="1">
<br>
<label for="substitutiva">Substitutiva?</label>
<input type="checkbox" name="substitutiva">
<br>
<label for="provaTrabalho">Prova?</label>
<input type="checkbox" name="provaTrabalho" required>
<br>
<input type="submit" value="Enviar" class="button normal">
</form>
</div>
</section>
<% include partials/footer %>
</body>
</html>
<!DOCTYPE html>
<html>
<% include partials/head %>
<body>
<% include partials/basic-header %>
<section class="margin page-wrap card">
<div class="flex no-wrap space-around stretch">
<div class="half">
<img src="<%= arquivo.path %>" style="width:100%">
</div>
<div>
<h3>Informações</h3>
<%= arquivo.materia %> - <%= arquivo.professor %>
<br>
<% if(arquivo.prova) { %> Prova <% } else { %> Trabalho <% } %>
<%= arquivo.numero %> - <%= arquivo.ano %>/<%= arquivo.semestre %>
</div>
</div>
</section>
<% include partials/footer %>
</body>
</html>
......@@ -17,11 +17,14 @@ var log = require('./log')(module)
var oauth2 = require('./auth/oauth2')
var rotas = require('./routes/routes')
var admin = require('./routes/admin/admin')
var materias = require('./routes/admin/materias')
var api = require('./routes/api/api')
var usuarios = require('./routes/api/usuarios')
var materias = require('./routes/api/materias')
var professores = require('./routes/api/professores')
var arquivos = require('./routes/api/arquivos')
var usuariosRest = require('./routes/api/usuarios')
var materiasRest = require('./routes/api/materias')
var professoresRest = require('./routes/api/professores')
var arquivosRest = require('./routes/api/arquivos')
var app = express()
......@@ -43,6 +46,8 @@ app.use(flash())
// Rotas da aplicação
app.use('/', rotas)
app.use('/admin', admin)
app.use('/admin/materias', materias)
// Pasta pública onde ficam os uploads
app.use('/uploads', express.static('uploads'))
......@@ -50,10 +55,10 @@ app.use('/uploads', express.static('uploads'))
// Rotas da API REST
app.use('/api/*', cors())
app.use('/api/', api)
app.use('/api/u', usuarios)
app.use('/api/materias', materias)
app.use('/api/professores', professores)
app.use('/api/arquivos', arquivos)
app.use('/api/u', usuariosRest)
app.use('/api/materias', materiasRest)
app.use('/api/professores', professoresRest)
app.use('/api/arquivos', arquivosRest)
app.use('/api/oauth/token', oauth2.token)
// catch 404 and forward to error handler
......@@ -70,6 +75,7 @@ app.use(function(req, res, next){
app.use(function(err, req, res, next){
res.status(err.status || 500)
log.error('%s %d %s', req.method, res.statusCode, err.message)
log.error(err)
res.json({
error: err.message
})
......
......@@ -33,7 +33,7 @@ var Arquivo = new Schema({
type: String,
required: true
},
// Aprovado ou pendente
// aprovado ou pendente
status: {
type: String,
default: 'pendente'
......
......@@ -36,11 +36,13 @@ module.exports = {
isLoggedIn: function() {
return function(req, res, next) {
if(req.isAuthenticated()) {
delete req.user.hashedPassword
delete req.user.salt
return next()
}
req.flash('loginMessage', 'Você precisa estar logado para acessar essa página')
res.redirect('/login')
res.redirect('/login?url='+req.originalUrl)
}
}
}
var express = require('express')
var passport = require('passport')
var router = express.Router()
var libs = process.cwd() + '/libs/'
var role = require(libs + 'role')
var Usuario = require(libs + 'model/usuario')
var Arquivo = require(libs + 'model/arquivo')
var Materia = require(libs + 'model/materia')
router.use(role.isLoggedIn())
router.get('/', function(req, res) {
Arquivo.count({}, function(err, count) {
if(err) {
console.log(err.message)
} else {
res.render('admin', {user: req.user, pendentes: count})
}
})
})
router.get('/uploads', function(req, res) {
Arquivo.find({status: 'pendente'})
.populate('materia')
.populate('professor')
.populate('usuario')
.exec(function(err, arquivos) {
if(!err) {
return res.render('uploads', {user: req.user , uploads: arquivos})
} else {
// TODO: redirecionar para página de erro
}
})
})
module.exports = router
var express = require('express')
var passport = require('passport')
var router = express.Router()
var libs = process.cwd() + '/libs/'
var role = require(libs + 'role')
var Usuario = require(libs + 'model/usuario')
var Arquivo = require(libs + 'model/arquivo')
var Materia = require(libs + 'model/materia')
router.use(role.isLoggedIn())
router.get('/', function(req, res) {
Arquivo.count({}, function(err, count) {
if(err) {
console.log(err.message)
} else {
res.render('admin/admin', {user: req.user, pendentes: count})
}
})
})
router.get('/uploads', function(req, res) {
Arquivo.find({status: 'pendente'})
.populate('materia')
.populate('professor')
.populate('usuario')
.exec(function(err, arquivos) {
if(!err) {
return res.render('admin/uploads', {user: req.user , uploads: arquivos})
} else {
// TODO: redirecionar para página de erro
}
})
})
module.exports = router
var express = require('express')
var passport = require('passport')
var router = express.Router()
var libs = process.cwd() + '/libs/'
var role = require(libs + 'role')
var Materia = require(libs + 'model/materia')
router.use(role.isLoggedIn())
router.get('/', function(req, res) {
Materia.find()
.sort([['nome', 'ascending']])
.exec(function(err, materias) {
if(!err) {
return res.render('admin/materias', {user: req.user, materias: materias, message: req.flash('materiasMessage')})
}
})
})
router.post('/', function(req, res) {
var materia = new Materia()
materia.codigo = req.body.codigo
materia.nome = req.body.nome
materia.save(function(err) {
if(!err) {
res.redirect('/admin/materias')
} else {
req.flash('materiasMessage', 'Erro ao salvar a matéria')
res.redirect('/admin/materias')
}
})
})
router.get('/:id', function(req, res) {
Materia.findById(req.params.id, function(err, materia) {
if(!materia) {
// TODO: redirecionar para 404
res.redirect('/')
}
if(!err) {
res.render('admin/materiaDetails', {user: req.user, materia: materia, message: req.flash('materiaDetailsMessage')})
} else {
// TODO: redirecionar para 500
res.redirect('/')
}
})
})
router.post('/:id', function(req, res) {
Materia.findById(req.params.id, function(err, materia) {
if(!materia) {
// TODO: redirecionar para 404
res.redirect('/admin/materia/'+req.params.id)
}
materia.codigo = req.body.codigo
materia.nome = req.body.nome
materia.save(function(err) {
if(!err) {
req.flash('materiasMessage', 'Matéria salva com sucesso')
res.redirect('/admin/materias')
} else {
// TODO: redirecionar para 500
res.redirect('/')
}
})
})
})
router.get('/delete/:id', function(req, res) {
Materia.findByIdAndRemove(req.params.id, function(err, materia) {
if(!materia) {
// TODO: redirecionar para 500
res.redirect('/')
}
req.flash('materiasMessage', 'Matéria removida com sucesso')
res.redirect('/admin/materias')
})
})
module.exports = router
var express = require('express')
var passport = require('passport')
var router = express.Router()
var multer = require('multer')
var crypto = require('crypto')
var path = require('path')
var storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null, 'uploads/')
},
filename: function(req, file, cb) {
crypto.pseudoRandomBytes(16, function(err, raw) {
cb(null, raw.toString('hex') + Date.now() + path.extname(file.originalname))
})
}
})
var fileFilter = function(req, file, cb) {
if(file.mimetype === 'image/jpg' ||
file.mimetype === 'image/jpeg' ||
file.mimetype === 'image/png' ||
file.mimetype === 'application/pdf') {
cb(null, true)
return
}
var err = new Error('Invalid file')
err.status = 400
cb(err)
}
var upload = multer({storage: storage, fileFilter: fileFilter})
var fs = require('fs')
var libs = process.cwd() + '/libs/'
......@@ -20,10 +48,12 @@ router.get('/login', function(req, res) {
})
router.post('/login', passport.authenticate('local-login', {
successRedirect: '/',
failureRedirect: '/login',