title modified

parent 1fa1fb59
...@@ -119,7 +119,7 @@ module.exports = { ...@@ -119,7 +119,7 @@ module.exports = {
* Activate the user account specified * Activate the user account specified
* @param {request} req * @param {request} req
* { * {
* "token": "12398123aas78sf798as7d987234" // Encryted code with supervisor ID * "token": "12398123aas78sf798as7d987234" // Encryted code with supervisor ID, siging role and id_off
* } * }
* @param {response} login view * @param {response} login view
* { * {
...@@ -132,18 +132,59 @@ module.exports = { ...@@ -132,18 +132,59 @@ module.exports = {
* } * }
*/ */
activate: function (req, res) { activate: function (req, res) {
if (!req.params.token) if (!req.params.token)
return res.badRequest("Invalid activation URL"); return res.badRequest("Invalid activation URL");
sailsTokenAuth.verifyToken(req.params.token, function(err, token) { sailsTokenAuth.verifyToken(req.params.token, function(err, token) {
if (err) if (err)
return res.badRequest("Invalid token"); return res.badRequest("Invalid token");
Supervisor.findOne(token).then(function (supervisor) {
Supervisor.findOne(token.id_sup).then(function (supervisor) {
if (!supervisor) if (!supervisor)
throw new Error("Error when looking for user"); throw new Error("Error when looking for user");
supervisor.active = true; supervisor.active = true;
delete supervisor.password; delete supervisor.password;
supervisor.save(); supervisor.save();
return res.view('accountActivated', {sup: supervisor, login_url: 'https://' + req.headers.host + '/app'});
if (token.role == 'tutor_office' || token.role === 'therapist_office') {
Office.findOne(token.id_off)
.then((off) => {
if (!off)
return res.serverError("Office not found: " + err)
// an email has to be sent to office administrators
var message = sails.__({
phrase: token.role + '_request',
locale: supervisor.lang
}, {name: supervisor.name + " " + supervisor.surname, email: supervisor: email});
mailService.mailer()
.send({
to: params.email,
text: message
})
.then(() => {})
.catch((err) => {});
return res.view('accountActivated', {
sup: supervisor,
login_url: 'https://' + req.headers.host + '/app'},
);
})
.catch((err) => {
return res.serverError("Office not found: " + err);
});
} else { // role is with no office, just return message
return res.view('accountActivated', {
sup: supervisor,
login_url: 'https://' + req.headers.host + '/app'},
);
}
}) })
.catch(function (err) { .catch(function (err) {
return res.serverError("Error when activating account " + err); return res.serverError("Error when activating account " + err);
...@@ -213,60 +254,75 @@ module.exports = { ...@@ -213,60 +254,75 @@ module.exports = {
create: function (req, res) { create: function (req, res) {
var params = req.params.all(); var params = req.params.all();
sails.log.debug("Creating supervisor with params " + JSON.stringify(params)); function sendConfirmationMail(cb) {
/* Send email confirmation */
var message = sails.__({
phrase: 'signin_mail',
locale: params.lang || 'es-es'
}) + 'https://' + req.headers.host + '/sup/activate/' + token; // expires in 1 week
sails.log.debug("Sending activation email: \n" + message);
if (params.name && mailService.mailer()
params.surname && .send({
params.gender && to: params.email,
params.password && text: message
params.email) { })
Supervisor.create({ .then(() => {cb();})
name: params.name, .catch((err) => {cb(err);});
surname: params.surname, }
gender: params.gender,
password: params.password,
email: params.email,
pic: sails.config.pictogram.paths.defaultAvatarFileName,
address: params.address || null,
country: params.country || null,
phone: params.phone || null,
lang: params.lang || null,
ttsEngine: params.ttsEngine || null
}).then(function (supervisor) {
if (!supervisor) sails.log.debug("Creating supervisor with params " + JSON.stringify(params));
res.serverError("Supervisor created but returned null");
sails.log.debug("SUPERVISOR: " + JSON.stringify(supervisor)); if (!params.name || !params.surname || !params.gender || !params.password || !params.email )
res.badRequest("Invalid params");
/* Send email confirmation */ var token = sailsTokenAuth.issueToken({
var message = sails.__({ id_sup: supervisor.id,
phrase: 'signin_mail', role: params.role,
locale: params.lang || 'es-es' id_off: params.id_off,
}) + 'https://' + req.headers.host + '/sup/activate/' + sailsTokenAuth.issueToken(supervisor.id, 60*24*7); // expires in 1 week }, 60*24*7); // expires in 1 week
sails.log.debug("Sending activation email: \n" + message);
Supervisor.create({
name: params.name,
surname: params.surname,
gender: params.gender,
password: params.password,
email: params.email,
pic: sails.config.pictogram.paths.defaultAvatarFileName,
address: params.address || null,
country: params.country || null,
phone: params.phone || null,
lang: params.lang || null,
ttsEngine: params.ttsEngine || null,
id_off: params.id_off || null
})
.then(function (supervisor) {
mailService.mailer() if (!supervisor)
.send({ res.serverError("Supervisor created but returned null");
to: params.email,
text: message if (params.role === 'therapist_office' || params.role === 'tutor_office') {
}) sendConfirmationMail((err) => {
.then(() => { if (err) throw err;
res.ok({ return res.ok();
user: supervisor, });
token: sailsTokenAuth.issueToken(supervisor.id) } else if (params.role === 'therapist_nooffice' || params.role === 'tutor_nooffice') {
Office.create(params.office)
.then((off) => {
supervisor.id_off = off.id;
delete supervisor.password;
supervisor.save();
sendConfirmationMail((err) => {
if (err) throw err;
return res.ok();
}); });
}) })
.catch((err) => { .catch(err => {throw err});
res.serverError("Mail could not be sent " + err); } else
}); return res.badRequest("Invalid role");
}).catch(function (err) {
}).catch(function (err) { return res.serverError("Supervisor could not be created: " + err);
res.serverError("Supervisor could not be created: " + err); });
});
} else {
res.badRequest("Invalid params");
}
}, },
/* /*
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<html lang="en" ng-app="dashboardApp"> <html lang="en" ng-app="dashboardApp">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Pictogram Dashboard</title> <title>Pictogram Web</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="css/main.css"> <link rel="stylesheet" href="css/main.css">
<link rel="icon" href="img/logo_pictogram.png" type='image/png'> <link rel="icon" href="img/logo_pictogram.png" type='image/png'>
......
...@@ -100,10 +100,25 @@ function SignInCtrl($scope, ...@@ -100,10 +100,25 @@ function SignInCtrl($scope,
$scope.showdialog = true; $scope.showdialog = true;
if ($scope.formdata.office_idx != -1) {
$scope.formdata.id_off = $scope.offices[$scope.office_idx].id;
delete $scope.formdata.office_idx;
}
if ($scope.formdata.role === 'tutor_nooffice') {
$scope.formdata.office.name: $scope.formdata.name + " " + $scope.formdata.surname,
$scope.formdata.office.address: $scope.formdata.address,
$scope.formdata.office.postal_code: $scope.formdata.postal_code,
$scope.formdata.office.country: $scope.formdata.country,
$scope.formdata.office.contact_person: $scope.formdata.name + " " + $scope.formdata.surname,
$scope.formdata.office.phone: $scope.formdata.phone,
$scope.formdata.office.email: $scope.formdata.email
}
$http $http
.post(config.backend + '/sup', $scope.formdata) .post(config.backend + '/sup', $scope.formdata)
.success(function () { .success(function () {
ngToast.success({ content: $translate.instant('user_created') }); ngToast.success({ content: $translate.instant('user_created', { name: $scope.formdata.name, surname: $scope.formdata.surname }) });
$scope.reset(); $scope.reset();
}) })
.error(function () { .error(function () {
......
...@@ -3,5 +3,7 @@ ...@@ -3,5 +3,7 @@
"A brand new app.": "A brand new app.", "A brand new app.": "A brand new app.",
"notification_from_pictogram": "Notification from Pictogram", "notification_from_pictogram": "Notification from Pictogram",
"signin_mail": "To activate your Pictogram account, click on this link:\n", "signin_mail": "To activate your Pictogram account, click on this link:\n",
"change_password_mail": "To change your password, please click on the following link:\n" "change_password_mail": "To change your password, please click on the following link:\n",
"therapist_office_request": "{{ name }}, with email {{ email }}, is requesting to be linked as therapist to any of your students.",
"tutor_office_request": "{{ name }}, with email {{ email }}, is requesting to be linked as tutor/father/mother to any of your students."
} }
...@@ -3,5 +3,10 @@ ...@@ -3,5 +3,10 @@
"A brand new app.": "Una aplicación de la nueva marca.", "A brand new app.": "Una aplicación de la nueva marca.",
"notification_from_pictogram": "Notificación desde Pictogram", "notification_from_pictogram": "Notificación desde Pictogram",
"signin_mail": "Para activar su cuenta en Pictogram, haga click en el siguiente enlace:\n", "signin_mail": "Para activar su cuenta en Pictogram, haga click en el siguiente enlace:\n",
"change_password_mail": "Para cambiar su contraseña, haga click en el siguiente enlace:\n" "change_password_mail": "Para cambiar su contraseña, haga click en el siguiente enlace:\n",
"welcome_message": "Su cuenta ha sido activada, puede ",
"welcome_title": "Bienvenido a Pictogram",
"login": "acceder",
"therapist_office_request {{ name }} {{ email }}": "El terapeuta {{ name }}, con correo electrónico {{ email }}, pide ser asociado a algún estudiante.",
"tutor_office_request {{ name }} {{ email }}": "El tutor {{ name }}, con correo electrónico {{ email }}, pide ser asociado a algún estudiante."
} }
...@@ -112,6 +112,9 @@ module.exports.pictogram = { ...@@ -112,6 +112,9 @@ module.exports.pictogram = {
}, },
error_codes: { error_codes: {
'DUPLICATED_PICTO': 1 'DUPLICATED_PICTO': 1,
'OFFICE_NOT_FOUND': 2,
'SUPERVISOR_NOT_FOUND': 3,
'STUDENT_NOT_FOUND': 4
} }
}; };
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<html lang="es"> <html lang="es">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Pictogram Dashboard</title> <title>Pictogram Web</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="/app/css/main.css"> <link rel="stylesheet" href="/app/css/main.css">
</head> </head>
......
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