diff --git a/app/partials/login/login.services.js b/app/partials/login/login.services.js
index 8debeed..dd521c0 100644
--- a/app/partials/login/login.services.js
+++ b/app/partials/login/login.services.js
@@ -3,47 +3,12 @@
angular
.module('app.login')
- .factory('Login', Login)
- .factory('GetRol', GetRol)
- .factory('hash', hash)
- .value('algoritmo','SHA-1')
+ .factory('login', login)
.value('user',{})
.value('id',{})
-
- Login.$inject = ['$resource','$rootScope'];
- function Login($resource, $rootScope){
- return $resource('http://'+$rootScope.domainUrl+'/api/VerifyUser');
+ login.$inject = ['$resource','$rootScope'];
+ function login($resource, $rootScope){
+ return $resource('http://'+$rootScope.domainUrl+'/login');
};
-
- GetRol.$inject = ['$resource','$rootScope'];
- function GetRol($resource, $rootScope){
- return $resource('http://'+$rootScope.domainUrl+'/api/User/:id');
- };
-
- hash.$inject = ['algoritmo'];
- function hash(algoritmo){
-
- var hashFunction;
-
- if (algoritmo==="MD5") {
- hashFunction=CryptoJS.MD5;
- } else if (algoritmo==="SHA-1") {
- hashFunction=CryptoJS.SHA1;
- } else if (algoritmo==="SHA-2-256") {
- hashFunction=CryptoJS.SHA256;
- } else if (algoritmo==="SHA-2-512") {
- hashFunction=CryptoJS.SHA512;
- } else {
- throw Error("El tipo de algoritmo no es válido:"+algoritmo);
- }
-
- var hash=function(message) {
- var objHashResult=hashFunction(message);
- var strHashResult=objHashResult.toString(CryptoJS.enc.Base64);
-
- return strHashResult;
- }
- return hash;
- };
-})();
+})();
\ No newline at end of file
diff --git a/app/partials/login/modal/login_modal.html b/app/partials/login/modal/login_modal.html
new file mode 100644
index 0000000..8441a08
--- /dev/null
+++ b/app/partials/login/modal/login_modal.html
@@ -0,0 +1,10 @@
+
+
Error
+
+
+ {{ vm.message }}
+
+
\ No newline at end of file
diff --git a/app/partials/professor/modal/create_professor_modal.html b/app/partials/professor/modal/create_professor_modal.html
index ae039ab..e6e7e91 100644
--- a/app/partials/professor/modal/create_professor_modal.html
+++ b/app/partials/professor/modal/create_professor_modal.html
@@ -2,9 +2,9 @@
Crear Profesor
- {{ mensaje }}
+ {{ vm.mensaje }}
\ No newline at end of file
diff --git a/app/partials/professor/modal/list_professor_modal.html b/app/partials/professor/modal/list_professor_modal.html
index 4036b7f..477d0b1 100644
--- a/app/partials/professor/modal/list_professor_modal.html
+++ b/app/partials/professor/modal/list_professor_modal.html
@@ -2,13 +2,19 @@
Eliminar Profesor
- {{ mensaje }}
+ {{ vm.mensaje }}
\ No newline at end of file
diff --git a/app/partials/professor/modal/update_professor_modal.html b/app/partials/professor/modal/update_professor_modal.html
index f863686..808cc76 100644
--- a/app/partials/professor/modal/update_professor_modal.html
+++ b/app/partials/professor/modal/update_professor_modal.html
@@ -2,11 +2,15 @@
\ No newline at end of file
diff --git a/app/partials/section/modal/delete_section_modal.html b/app/partials/section/modal/delete_section_modal.html
index c6ad3d2..9293fca 100644
--- a/app/partials/section/modal/delete_section_modal.html
+++ b/app/partials/section/modal/delete_section_modal.html
@@ -2,13 +2,19 @@
Eliminar Sección
- {{ mensaje }}
+ {{ vm.mensaje }}
\ No newline at end of file
diff --git a/app/partials/section/modal/student_bt_removal_modal.html b/app/partials/section/modal/student_bt_removal_modal.html
index c045561..df39e59 100644
--- a/app/partials/section/modal/student_bt_removal_modal.html
+++ b/app/partials/section/modal/student_bt_removal_modal.html
@@ -2,13 +2,19 @@
Liberar BT
- {{ mensaje }}
+ {{ vm.mensaje }}
\ No newline at end of file
diff --git a/app/partials/section/modal/update_section_modal.html b/app/partials/section/modal/update_section_modal.html
index 2b7774d..868a1a6 100644
--- a/app/partials/section/modal/update_section_modal.html
+++ b/app/partials/section/modal/update_section_modal.html
@@ -2,13 +2,19 @@
Retirar Estudiante
- {{ mensaje }}
+ {{ vm.mensaje }}
\ No newline at end of file
diff --git a/app/partials/section/section.module.js b/app/partials/section/section.module.js
index 40b26ce..4576886 100644
--- a/app/partials/section/section.module.js
+++ b/app/partials/section/section.module.js
@@ -17,54 +17,33 @@
$urlRouterProvider.otherwise('/SectionList');
$stateProvider
-
.state('SectionList', {
+ parent: 'index',
url: '/SectionList',
views: {
- sidebar: {
- templateUrl: 'partials/sidebar/sidebar.html',
- controller: 'SidebarCtrl'
- },
- navbar: {
- templateUrl: 'partials/sidebar/navbar.html'
- },
- content: {
+ 'content@': {
templateUrl: 'partials/section/section_list.html',
controller: 'SectionListCtrl',
controllerAs: 'vm'
}
}
})
-
.state('SectionCreate', {
+ parent: 'index',
url: '/SectionCreate',
views: {
- sidebar: {
- templateUrl: 'partials/sidebar/sidebar.html',
- controller: 'SidebarCtrl'
- },
- navbar: {
- templateUrl: 'partials/sidebar/navbar.html'
- },
- content: {
+ 'content@': {
templateUrl: 'partials/section/section_create.html',
controller: 'SectionCreateCtrl',
controllerAs: 'vm'
}
}
})
-
- .state('SectionUpdate', {
+ .state('SectionUpdate', {
+ parent: 'index',
url: '/SectionUpdate',
views: {
- sidebar: {
- templateUrl: 'partials/sidebar/sidebar.html',
- controller: 'SidebarCtrl'
- },
- navbar: {
- templateUrl: 'partials/sidebar/navbar.html'
- },
- content: {
+ 'content@': {
templateUrl: 'partials/section/section_update.html',
controller: 'SectionUpdateCtrl',
controllerAs: 'vm'
diff --git a/app/partials/section/section_create.controller.js b/app/partials/section/section_create.controller.js
index a67d62d..2bef9d1 100644
--- a/app/partials/section/section_create.controller.js
+++ b/app/partials/section/section_create.controller.js
@@ -6,16 +6,17 @@
.controller('SectionCreateCtrl', SectionCreateCtrl)
SectionCreateCtrl.$inject =
- ['$scope','$rootScope', '$state', 'professors', '$modal', 'selectedCourse'];
- function SectionCreateCtrl($scope, $rootScope, $state, professors, $modal, selectedCourse){
- var professorid = $rootScope.professorId;
+ ['$scope', '$state', 'professors', '$modal', 'selectedCourse','authentication'];
+ function SectionCreateCtrl($scope, $state, professors, $modal, selectedCourse, authentication){
+ var user = authentication.currentUser();
+ var professorid = user._id;
var vm = this;
vm.course = {};
vm.itExists = false;
vm.selectedCourse = selectedCourse;
vm.submitted = false;
vm.semester, vm.section, vm.materias;
- $rootScope.mensaje = "";
+ vm.mensaje = "";
vm.students = [];
professors.get({ id: professorid },
@@ -47,15 +48,9 @@
};
$scope.modalInstance = $modal.open({
- animation: $rootScope.animationsEnabled,
templateUrl: 'partials/section/modal/create_section_modal.html',
scope: $scope,
- size: 'sm',
- resolve: {
- items: function () {
- return $rootScope.items;
- }
- }
+ size: 'sm'
});
@@ -72,19 +67,17 @@
vm.professor.courses[vm.index].sections.push(vm.package);
professors.update({ id: professorid }, vm.professor,
function(){
- $rootScope.botonOk = true;
- $rootScope.mensaje = "Sección " + vm.name + " creada";
+ vm.botonOk = true;
+ vm.mensaje = "Sección " + vm.name + " creada";
},
function(){
- $rootScope.botonOk = true;
- $rootScope.mensaje = "Error creando la seccion " + vm.name;
+ vm.botonOk = true;
+ vm.mensaje = "Error creando la seccion " + vm.name;
});
}else{
- $rootScope.botonOk = true;
- $rootScope.mensaje = "Sección Duplicada, " + vm.name + " existe en el semestre "+ vm.semester + ".";
+ vm.botonOk = true;
+ vm.mensaje = "Sección Duplicada, " + vm.name + " existe en el semestre "+ vm.semester + ".";
}
- }else{
- vm.submitted = true;
}
};
diff --git a/app/partials/section/section_list.controller.js b/app/partials/section/section_list.controller.js
index 64d2899..ba95a1d 100644
--- a/app/partials/section/section_list.controller.js
+++ b/app/partials/section/section_list.controller.js
@@ -5,10 +5,11 @@
.module('app.section')
.controller('SectionListCtrl', SectionListCtrl)
- SectionListCtrl.$inject = [ '$scope', '$rootScope', '$state', 'professors', '$modal', 'selectedCourse', 'selectedSection'];
- function SectionListCtrl ( $scope, $rootScope, $state, professors, $modal, selectedCourse, selectedSection ){
+ SectionListCtrl.$inject = [ '$scope', '$state', 'professors', '$modal', 'selectedCourse', 'selectedSection', 'authentication'];
+ function SectionListCtrl ( $scope, $state, professors, $modal, selectedCourse, selectedSection, authentication ){
var vm = this;
- var professorid = $rootScope.professorId;
+ var user = authentication.currentUser();
+ var professorid = user._id;
vm.section = [];
vm.professor = null;
@@ -27,60 +28,45 @@
function (){
console.log("Error al obtener los datos.");
- });
-
- /**************************Eliminar Matricula**************************/
- /* En este proceso, primero se llama a un Modal el cual se cerciora que
- el usuario se asegure de eliminar la matricula escogida, el usuario al
- confirmar su decision llama automaticamente a la funcion que hara la
- llamada a servicio que borrara la matricula de la base de datos.
- */
+ });
vm.createSection = function () {
$state.go('SectionCreate');
};
vm.eliminarMatriculaModal = function (index) {
- $rootScope.index = index;
- $rootScope.botonOk = true;
- $rootScope.otroBotonOk = false;
- $rootScope.botonCancelar = true;
- $rootScope.rsplice = false;
+ $scope.index = index;
+ vm.botonOk = true;
+ vm.otroBotonOk = false;
+ vm.botonCancelar = true;
+ vm.rsplice = false;
var name = vm.section[index].name;
- $rootScope.mensaje = "¿Seguro que desea eliminar la sección "+name+"?";
+ vm.mensaje = "¿Seguro que desea eliminar la sección "+name+"?";
$scope.modalInstance = $modal.open({
- animation: $rootScope.animationsEnabled,
templateUrl: '/partials/section/modal/delete_section_modal.html',
scope: $scope,
- size: 'sm',
- resolve: {
- items: function () {
- return "";
- }
- }
+ size: 'sm'
});
};
vm.eliminarMatricula = function (index) {
- $rootScope.botonOk = false;
- $rootScope.otroBotonOk = true;
- $rootScope.botonCancelar = false;
+ vm.botonOk = false;
+ vm.otroBotonOk = true;
+ vm.botonCancelar = false;
var name = vm.section[index].name;
-
vm.professor.courses[vm.index].sections.splice(index, 1);
+
professors.update({ id: professorid }, vm.professor,
function () {
- $rootScope.rsplice = true;
- $rootScope.mensaje = "Sección " + name + " eliminada";
+ vm.rsplice = true;
+ vm.mensaje = "Sección " + name + " eliminada";
},
function () {
- $rootScope.mensaje = "Error eliminando la sección " + name;
+ vm.mensaje = "Error eliminando la sección " + name;
});
};
- /*************************Fin de Eliminar Matricula*******************/
-
vm.modificarMatricula = function (index) {
selectedSection._id = vm.section[index]._id;
selectedCourse.index = vm.index;
diff --git a/app/partials/section/section_list.html b/app/partials/section/section_list.html
index 9f28675..6a88918 100644
--- a/app/partials/section/section_list.html
+++ b/app/partials/section/section_list.html
@@ -12,23 +12,15 @@
-
\ No newline at end of file
diff --git a/app/partials/students/modal/update_students_modal.html b/app/partials/students/modal/update_students_modal.html
index 93e1c2f..ccf09df 100644
--- a/app/partials/students/modal/update_students_modal.html
+++ b/app/partials/students/modal/update_students_modal.html
@@ -2,11 +2,15 @@
Actualizar Estudiante
- {{ mensaje }}
+ {{ vm.mensaje }}
\ No newline at end of file
diff --git a/app/partials/students/student.module.js b/app/partials/students/student.module.js
index a0cb563..1c9a344 100644
--- a/app/partials/students/student.module.js
+++ b/app/partials/students/student.module.js
@@ -18,16 +18,10 @@
$stateProvider
.state('StudentCreate', {
+ parent: 'index',
url: '/StudentCreate',
views: {
- sidebar: {
- templateUrl: 'partials/sidebar/sidebar.html',
- controller: 'SidebarCtrl'
- },
- navbar: {
- templateUrl: 'partials/sidebar/navbar.html'
- },
- content: {
+ 'content@': {
templateUrl: 'partials/students/student_create.html',
controller: 'StudentCreateCtrl',
controllerAs: 'vm'
@@ -35,16 +29,10 @@
}
})
.state('StudentUpdate', {
+ parent: 'index',
url: '/StudentUpdate',
views: {
- sidebar: {
- templateUrl: 'partials/sidebar/sidebar.html',
- controller: 'SidebarCtrl'
- },
- navbar: {
- templateUrl: 'partials/sidebar/navbar.html'
- },
- content: {
+ 'content@': {
templateUrl: 'partials/students/student_update.html',
controller: 'StudentUpdateCtrl',
controllerAs: 'vm'
diff --git a/app/partials/students/student_create.controller.js b/app/partials/students/student_create.controller.js
index 4e9592f..b2f8976 100644
--- a/app/partials/students/student_create.controller.js
+++ b/app/partials/students/student_create.controller.js
@@ -5,15 +5,16 @@
.module('app.student')
.controller('StudentCreateCtrl', StudentCreateCtrl)
- StudentCreateCtrl.$inject = ['$scope', '$rootScope', '$state', 'professors', '$modal', 'selectedSection', 'selectedCourse'];
- function StudentCreateCtrl($scope, $rootScope, $state, professors, $modal, selectedSection, selectedCourse){
+ StudentCreateCtrl.$inject = ['$scope', '$state', 'professors', '$modal', 'selectedSection', 'selectedCourse', 'authentication'];
+ function StudentCreateCtrl($scope, $state, professors, $modal, selectedSection, selectedCourse, authentication){
var vm = this;
var duplicated = false;
- var professorid = $rootScope.professorId;
+ var user = authentication.currentUser();
+ var professorid = user._id;
vm.professor = {};
- $rootScope.mensaje = "";
- $rootScope.actOk = false;
+ vm.mensaje = "";
+ vm.actOk = false;
professors.get({ id: professorid },
function (successResult){
@@ -25,7 +26,6 @@
});
vm.submit = function() {
-
if (vm.data_input_form.$valid){
var person = {
"id": vm.estudiante.Cedula,
@@ -34,18 +34,11 @@
"email": vm.estudiante.Correo
};
- $rootScope.crearEstudianteLoading = true;
- $rootScope.botonOk = false;
+ vm.botonOk = false;
$scope.modalInstance = $modal.open({
- animation: $rootScope.animationsEnabled,
templateUrl: 'partials/students/modal/create_students_modal.html',
scope: $scope,
- size: 'sm',
- resolve: {
- items: function () {
- return $rootScope.items;
- }
- }
+ size: 'sm'
});
angular.forEach (vm.professor.courses[selectedCourse.index].sections[selectedSection.index].students,
@@ -57,24 +50,18 @@
professors.update({ id: professorid }, vm.professor,
function(){
- $rootScope.botonOk = true;
- $rootScope.urlLo = 'actualizarMatricula';
- $rootScope.mensaje = "Estudiante " + vm.estudiante.Apellido + ", " + vm.estudiante.Nombre + " agregado";
- $rootScope.crearEstudianteLoading = false;
+ vm.botonOk = true;
+ vm.mensaje = "Estudiante " + vm.estudiante.Apellido + ", " + vm.estudiante.Nombre + " agregado";
},
function(){
- $rootScope.botonOk = true;
- $rootScope.mensaje = "Error al agregar al estudiante " + vm.estudiante.Apellido + ", " + vm.estudiante.Nombre;
- $rootScope.crearEstudianteLoading = false;
+ vm.botonOk = true;
+ vm.mensaje = "Error al agregar al estudiante " + vm.estudiante.Apellido + ", " + vm.estudiante.Nombre;
});
} else {
- $rootScope.botonOk = true;
- $rootScope.mensaje = "Estudiante con cedula " + vm.estudiante.Cedula + " ya esta en la lista.";
- $rootScope.crearEstudianteLoading = false;
+ vm.botonOk = true;
+ vm.mensaje = "Estudiante con cedula " + vm.estudiante.Cedula + " ya esta en la lista.";
}
- }else{
- vm.submitted = true;
}
}
@@ -87,17 +74,8 @@
$scope.modalInstance.dismiss('cancel');
};
- $rootScope.open = function($event) {
- $event.preventDefault();
- $event.stopPropagation();
-
- $rootScope.opened = true;
- };
-
vm.back = function () {
$state.go('SectionUpdate');
};
-
- return vm;
};
})();
\ No newline at end of file
diff --git a/app/partials/students/student_update.controller.js b/app/partials/students/student_update.controller.js
index 97d7e95..3655e7b 100644
--- a/app/partials/students/student_update.controller.js
+++ b/app/partials/students/student_update.controller.js
@@ -5,14 +5,15 @@
.module('app.student')
.controller('StudentUpdateCtrl', StudentUpdateCtrl)
- StudentUpdateCtrl.$inject = ['$scope', '$rootScope', '$state', 'professors', '$modal', 'selectedSection', 'selectedCourse', 'data'];
- function StudentUpdateCtrl($scope, $rootScope, $state, professors, $modal, selectedSection, selectedCourse, data){
+ StudentUpdateCtrl.$inject = ['$scope', '$state', 'professors', '$modal', 'selectedSection', 'selectedCourse', 'data', 'authentication'];
+ function StudentUpdateCtrl($scope, $state, professors, $modal, selectedSection, selectedCourse, data, authentication){
var vm = this;
- var professorid = $rootScope.professorId;
+ var user = authentication.currentUser();
+ var professorid = user._id;
vm.professor = {};
- $rootScope.mensaje = "";
- $rootScope.actOk = false;
+ vm.mensaje = "";
+ vm.actOk = false;
vm.newMail = null;
vm.student = data.Student
@@ -36,18 +37,11 @@
if (vm.data_input_form.$valid){
vm.student.email = vm.newMail;
- $rootScope.crearEstudianteLoading = true;
- $rootScope.botonOk = false;
+ vm.botonOk = false;
$scope.modalInstance = $modal.open({
- animation: $rootScope.animationsEnabled,
templateUrl: 'partials/students/modal/update_students_modal.html',
scope: $scope,
- size: 'sm',
- resolve: {
- items: function () {
- return $rootScope.items;
- }
- }
+ size: 'sm'
});
vm.professor.courses[selectedCourse.index].sections[selectedSection.index].students.splice(data.Index, 1);
@@ -56,12 +50,12 @@
professors.update({ id: professorid }, vm.professor,
function(){
- $rootScope.botonOk = true;
- $rootScope.mensaje = "Estudiante " + vm.student.lastname + ", " + vm.student.name + " actualizado";
+ vm.botonOk = true;
+ vm.mensaje = "Estudiante " + vm.student.lastname + ", " + vm.student.name + " actualizado";
},
function(){
- $rootScope.botonOk = true;
- $rootScope.mensaje = "Error al actualizar al estudiante " + vm.estudiante.Apellido + ", " + vm.estudiante.Nombre;
+ vm.botonOk = true;
+ vm.mensaje = "Error al actualizar al estudiante " + vm.estudiante.Apellido + ", " + vm.estudiante.Nombre;
});
}
};
diff --git a/app/server.js b/app/server.js
index 52d81a1..3ebccef 100644
--- a/app/server.js
+++ b/app/server.js
@@ -1,16 +1,30 @@
var mongoose = require('mongoose');
var express = require('express');
+var path = require ('path');
+var favicon = require ('serve-favicon');
+var logger = require('morgan');
+var cookieparser = require('cookie-parser');
var app = express();
var db = mongoose.connection;
-//var Professor = require('./models/professor');
+var crypto = require('crypto');
var bodyParser = require('body-parser');
+var jwbt = require('jsonwebtoken');
+var nodemailer = require('nodemailer');
+var transporter = nodemailer.createTransport('smtps://reynaldo.reyes.4@gmail.com:zwvdhyensrwnfipt@smtp.gmail.com');
+var jwt = require('express-jwt');
+var auth = jwt({
+ secret: 'MY_SECRET',
+ userProperty: 'payload'
+});
+
app.use(express.static(__dirname));
app.use(bodyParser.json());
-
-var nodemailer = require('nodemailer');
-
-// create reusable transporter object using the default SMTP transport
-var transporter = nodemailer.createTransport('smtps://reynaldo.reyes.4@gmail.com:zwvdhyensrwnfipt@smtp.gmail.com');
+app.use(function (err, req, res, next) {
+ if (err.name === 'UnauthorizedError') {
+ res.status(401);
+ res.json({"message" : err.name + ": " + err.message});
+ }
+});
db.on('error', console.error);
db.once('open', function() {
@@ -47,21 +61,59 @@ db.once('open', function() {
});
var professorSchema = new mongoose.Schema({
- id: Number,
- name: String,
- lastname: String,
- email: String,
- number: String,
- role: String,
- password: String,
- courses: [courseSchema]
+ id: {
+ type: Number,
+ unique: true,
+ required: true
+ },
+ name: String,
+ lastname: String,
+ email: String,
+ number: String,
+ role: String,
+ hash: String,
+ salt: String,
+ courses: [courseSchema]
});
- var Professor = mongoose.model('Professor', professorSchema);
-
- //Professor CRUD
+ professorSchema.methods.setPassword = function(password){
+ this.salt = crypto.randomBytes(16).toString('hex');
+ this.hash = crypto.pbkdf2Sync(password, this.salt, 1000, 64).toString('hex');
+ };
- app.get('/professors', function(req, res){
+ professorSchema.methods.validPassword = function(password){
+ var hash = crypto.pbkdf2Sync(password, this.salt, 1000, 64).toString('hex');
+ return this.hash === hash;
+ };
+
+ professorSchema.methods.generateJwt = function() {
+ var profile = {
+ _id: this._id,
+ role: this.role
+ };
+ return jwbt.sign(profile, "MY_SECRET", { expiresIn: 18000 });
+ };
+
+ var Professor = mongoose.model('professor', professorSchema);
+
+ var passport = require('passport')
+ , LocalStrategy = require('passport-local').Strategy;
+
+ passport.use(new LocalStrategy({
+ usernameField: 'id'
+ },
+ function(username, password, done) {
+ Professor.findOne({ id: username }, function (err, professor) {
+ if (err) return done(err);
+ if (!professor) return done(null, false, {message: 'professor not found'});
+ if (!professor.validPassword(password)) return done(null, false, {message: 'Password is wrong'});
+ return done(null, professor);
+ });
+ }));
+
+ app.use(passport.initialize());
+
+ app.get('/professors', auth, function(req, res){
console.log('Received GET ALL professors request');
Professor.find(function(err, docs){
//console.log(docs);
@@ -69,7 +121,7 @@ db.once('open', function() {
})
});
- app.get('/professors/:id', function(req, res){
+ app.get('/professors/:id', auth, function(req, res){
console.log('Received GET professor request');
console.log(req.params);
Professor.findById(req.params.id,
@@ -79,7 +131,7 @@ db.once('open', function() {
})
});
- app.post('/professors', function(req, res){
+ app.post('/professors', function(req, res){
console.log('Received ADD professor request');
//console.log(req.body);
@@ -90,35 +142,32 @@ db.once('open', function() {
email: req.body.email,
number: req.body.number,
role: req.body.role,
- password: req.body.password,
- course: [
- { name:"Materia" }
- ]
+ course: [{ name:"Materia" }]
})
+ professor.setPassword(req.body.password);
professor.save(
function(err, docs){
- // setup e-mail data with unicode symbols
- var mailOptions = {
- from: '"Rey Reyes" ', // sender address
- to: req.body.email, // list of receivers
- subject: 'Registro en la aplicación M.A.S.A.',
- text: 'Este es un correo automatizado para informarle que ha sido registrado en la aplicación M.A.S.A. sus credenciales son: '+ req.body.id +' / '+ req.body.password,
- html: 'Este es un correo automatizado para informarle que ha sido registrado en la aplicación M.A.S.A. sus credenciales son: '+ req.body.id +' / '+ req.body.password
- };
-
- // send mail with defined transport object
- transporter.sendMail(mailOptions, function(error, info){
- if(error){
- return console.log(error);
- }
- console.log('Message sent: ' + info.response);
- });
- res.json(docs);
- })
+ // setup e-mail data with unicode symbols
+ var mailOptions = {
+ from: '"Rey Reyes" ', // sender address
+ to: req.body.email, // list of receivers
+ subject: 'Registro en la aplicación M.A.S.A.',
+ text: 'Este es un correo automatizado para informarle que ha sido registrado en la aplicación M.A.S.A. sus credenciales son: '+ req.body.id +' / '+ req.body.password,
+ html: 'Este es un correo automatizado para informarle que ha sido registrado en la aplicación M.A.S.A. sus credenciales son: '+ req.body.id +' / '+ req.body.password
+ };
+ // send mail with defined transport object
+ transporter.sendMail(mailOptions, function(error, info){
+ if(error) return console.log(error);
+ console.log('Message sent: ' + info.response);
+ });
+ var token = professor.generateJwt();
+ res.status(200);
+ res.json({"token" : token});
+ })
});
- app.delete('/professors/:id', function(req, res){
+ app.delete('/professors/:id', auth, function(req, res){
console.log("Received DELETE professor request...");
console.log(req.params);
Professor.findByIdAndRemove(req.params.id,
@@ -128,7 +177,7 @@ db.once('open', function() {
});
});
- app.put('/professors/:id', function(req, res){
+ app.put('/professors/:id', auth, function(req, res){
console.log("Received UPDATE professor request");
console.log("params:" + req.params);
console.log("body:" + req.body);
@@ -147,9 +196,30 @@ db.once('open', function() {
});
});
});
+
+ app.post('/login', function(req, res){
+ passport.authenticate('local', function(err, professor, info){
+ var token;
+ // If Passport throws/catches an error
+ if (err) {
+ res.status(404).json(err);
+ return;
+ }
+ // If a user is found
+ if(professor){
+ token = professor.generateJwt();
+ res.status(200);
+ res.json({
+ "token" : token
+ });
+ // If user is not found
+ } else {
+ res.status(401).json(info);
+ }
+ })(req, res);
+ });
});
mongoose.connect('mongodb://localhost/AttendanceDB');
-
app.listen(3000);
console.log("server running on port 3000");
\ No newline at end of file
diff --git a/package.json b/package.json
index ff09b32..f53d59a 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
- "name": "masa-front",
+ "name": "masa",
"version": "1.0.0",
- "description": "Frontend for M.A.S.A. App.",
+ "description": "NPM Package for M.A.S.A. App.",
"main": "app/index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
@@ -17,8 +17,16 @@
},
"dependencies": {
"body-parser": "latest",
- "express" : "latest",
- "gulp":"latest",
- "mongoose":"latest"
+ "cookie-parser": "^1.4.1",
+ "express": "latest",
+ "express-jwt": "^3.4.0",
+ "favicon": "0.0.2",
+ "gulp": "latest",
+ "jsonwebtoken": "^6.2.0",
+ "mongoose": "latest",
+ "morgan": "^1.7.0",
+ "passport": "^0.3.2",
+ "passport-local": "^1.0.0",
+ "serve-favicon": "^2.3.0"
}
}