title modified

parent 1fa1fb59
......@@ -119,7 +119,7 @@ module.exports = {
* Activate the user account specified
* @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
* {
......@@ -132,18 +132,59 @@ module.exports = {
* }
*/
activate: function (req, res) {
if (!req.params.token)
return res.badRequest("Invalid activation URL");
sailsTokenAuth.verifyToken(req.params.token, function(err, token) {
if (err)
return res.badRequest("Invalid token");
Supervisor.findOne(token).then(function (supervisor) {
Supervisor.findOne(token.id_sup).then(function (supervisor) {
if (!supervisor)
throw new Error("Error when looking for user");
supervisor.active = true;
delete supervisor.password;
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) {
return res.serverError("Error when activating account " + err);
......@@ -213,60 +254,75 @@ module.exports = {
create: function (req, res) {
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 &&
params.surname &&
params.gender &&
params.password &&
params.email) {
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
}).then(function (supervisor) {
mailService.mailer()
.send({
to: params.email,
text: message
})
.then(() => {cb();})
.catch((err) => {cb(err);});
}
if (!supervisor)
res.serverError("Supervisor created but returned null");
sails.log.debug("Creating supervisor with params " + JSON.stringify(params));
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 message = sails.__({
phrase: 'signin_mail',
locale: params.lang || 'es-es'
}) + 'https://' + req.headers.host + '/sup/activate/' + sailsTokenAuth.issueToken(supervisor.id, 60*24*7); // expires in 1 week
sails.log.debug("Sending activation email: \n" + message);
var token = sailsTokenAuth.issueToken({
id_sup: supervisor.id,
role: params.role,
id_off: params.id_off,
}, 60*24*7); // expires in 1 week
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()
.send({
to: params.email,
text: message
})
.then(() => {
res.ok({
user: supervisor,
token: sailsTokenAuth.issueToken(supervisor.id)
if (!supervisor)
res.serverError("Supervisor created but returned null");
if (params.role === 'therapist_office' || params.role === 'tutor_office') {
sendConfirmationMail((err) => {
if (err) throw err;
return res.ok();
});
} 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) => {
res.serverError("Mail could not be sent " + err);
});
}).catch(function (err) {
res.serverError("Supervisor could not be created: " + err);
});
} else {
res.badRequest("Invalid params");
}
.catch(err => {throw err});
} else
return res.badRequest("Invalid role");
}).catch(function (err) {
return res.serverError("Supervisor could not be created: " + err);
});
},
/*
......
......@@ -2,7 +2,7 @@
<html lang="en" ng-app="dashboardApp">
<head>
<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">
<link rel="stylesheet" href="css/main.css">
<link rel="icon" href="img/logo_pictogram.png" type='image/png'>
......
......@@ -100,10 +100,25 @@ function SignInCtrl($scope,
$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
.post(config.backend + '/sup', $scope.formdata)
.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();
})
.error(function () {
......
......@@ -3,5 +3,7 @@
"A brand new app.": "A brand new app.",
"notification_from_pictogram": "Notification from Pictogram",
"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 @@
"A brand new app.": "Una aplicación de la nueva marca.",
"notification_from_pictogram": "Notificación desde Pictogram",
"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 = {
},
error_codes: {
'DUPLICATED_PICTO': 1
'DUPLICATED_PICTO': 1,
'OFFICE_NOT_FOUND': 2,
'SUPERVISOR_NOT_FOUND': 3,
'STUDENT_NOT_FOUND': 4
}
};
......@@ -2,7 +2,7 @@
<html lang="es">
<head>
<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">
<link rel="stylesheet" href="/app/css/main.css">
</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