error with admin login fixed

parent 814c8e69
...@@ -2,11 +2,12 @@ ...@@ -2,11 +2,12 @@
* AdminController which manages the administration login and login * AdminController which manages the administration login and login
* @type {Object} * @type {Object}
*/ */
const bcrypt = require('bcrypt-nodejs');
module.exports = { module.exports = {
// @TODO ¿?¿?
login: function (req, res) { login: function (req, res) {
var bcrypt = require('bcrypt-nodejs');
var email = req.body.email; var email = req.body.email;
var password = req.body.password; var password = req.body.password;
...@@ -15,11 +16,11 @@ module.exports = { ...@@ -15,11 +16,11 @@ module.exports = {
return res.badRequest('No credentials sent'); return res.badRequest('No credentials sent');
// Check email // Check email
admin = sails.config.pictogram.admins.find((a) => a.email == email); var admin = sails.config.pictogram.admins.find((a) => a.email == email);
if (typeof admin == 'undefined') if (typeof admin == 'undefined')
return res.badRequest('User not found'); return res.badRequest('User not found');
// if found, check password in encrypted form // if found, check password in encrypted form
bcrypt.compare(password, admin.password, function (err, match) { bcrypt.compare(password, admin.password, function (err, match) {
if (err) if (err)
return res.serverError('Server error' + err); return res.serverError('Server error' + err);
...@@ -27,15 +28,15 @@ module.exports = { ...@@ -27,15 +28,15 @@ module.exports = {
return res.unauthorized('Invalid password'); return res.unauthorized('Invalid password');
// credentials are valid, return token with max life span // credentials are valid, return token with max life span
delete admin.password; var returned_admin = (JSON.parse(JSON.stringify(admin)));
delete returned_admin.password;
return res.ok({ return res.ok({
token: sailsTokenAuth.issueToken({'isAdmin': true, 'email': email}, sails.config.jwt.expiresInMinutes), token: sailsTokenAuth.issueToken({'isAdmin': true, 'email': email}, sails.config.jwt.expiresInMinutes),
user: admin user: returned_admin
}); });
}); });
}, },
// @TODO 357
logout: function (req, res) { logout: function (req, res) {
delete req.token; delete req.token;
res.ok('Session closed'); res.ok('Session closed');
......
...@@ -1168,7 +1168,8 @@ module.exports = { ...@@ -1168,7 +1168,8 @@ module.exports = {
fs.unlinkSync(path.join(newAvatarDirectory, student.pic)); fs.unlinkSync(path.join(newAvatarDirectory, student.pic));
} }
student.pic = newAvatarFileName; student.pic = newAvatarFileName;
delete student.password;
student.save(function (updateStudentError) { student.save(function (updateStudentError) {
if (updateStudentError) { if (updateStudentError) {
throw updateStudentError; throw updateStudentError;
......
...@@ -2,7 +2,7 @@ var mailerService = require('sails-service-mailer'); ...@@ -2,7 +2,7 @@ var mailerService = require('sails-service-mailer');
module.exports.mailer = function() { module.exports.mailer = function() {
return mailerService('sendmail', { return mailerService('sendmail', {
from: 'no-reply@yottacode.com', from: 'no-reply@pictogramweb.com',
subject: sails.__('notification_from_pictogram'), subject: sails.__('notification_from_pictogram'),
provider: { provider: {
path: '/usr/sbin/sendmail' path: '/usr/sbin/sendmail'
......
/vagrant/arasaac /home/ubuntu/pictogram/sails/arasaac
\ No newline at end of file \ No newline at end of file
...@@ -11,12 +11,12 @@ ...@@ -11,12 +11,12 @@
</div> </div>
<div class="col-xs-4"> <div class="col-xs-4">
<div class="languages-margin text-center text-muted"> <div class="languages-margin text-center text-muted">
Powered by &nbsp; <a href="http://www.yottacode.com"><img src="img/logo_pictogram.png" width="40px" alt="Pictogram" title="Pictogram" /></a> Powered by &nbsp; <a href="http://www.pictogramweb.com"><img src="img/logo_pictogram.png" width="40px" alt="Pictogram" title="Pictogram" /></a>
</div> </div>
</div> </div>
<div class="col-xs-4"> <div class="col-xs-4">
<div class="languages-margin text-right text-muted"> <div class="languages-margin text-right text-muted">
<a href="mailto:soporte@yottacode.com" translate>support</a> | <a href="mailto:soporte@pictogramweb.com" translate>support</a> |
<a href='/app/#/disclaimer' target='_blank' translate>disclaimer</a> <a href='/app/#/disclaimer' target='_blank' translate>disclaimer</a>
</div> </div>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment