cancel button in supervisor signin

parent 1f15a6e1
......@@ -150,14 +150,15 @@ module.exports = {
delete supervisor.password;
supervisor.save();
// an email has to be sent to office administrators
if (token.role == 'tutor_office' || token.role === 'therapist_office') {
Office.findOne(token.id_off)
.populate('admin')
.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
......@@ -165,27 +166,18 @@ module.exports = {
mailService.mailer()
.send({
to: params.email,
to: admin.email,
text: message
})
.then(() => {})
.catch((err) => {});
return res.view('accountActivated', {
welcome_msg1: sails.__({
phrase: 'welcome_msg1',
locale: supervisor.lang
}, {name: supervisor.name}),
welcome_msg2: sails.__({
phrase: 'welcome_msg2',
locale: supervisor.lang
}, {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
}
// welcome message is returned
return res.view('accountActivated', {
welcome_msg1: sails.__({
phrase: 'welcome_msg1',
......@@ -196,7 +188,7 @@ module.exports = {
locale: supervisor.lang
}, {login_url: 'https://' + req.headers.host + '/app'})
});
}
})
.catch(function (err) {
return res.serverError("Error when activating account " + err);
......@@ -265,13 +257,23 @@ module.exports = {
*/
create: function (req, res) {
var params = req.params.all();
var supervisor;
// Send email confirmation
function sendConfirmationMail(cb) {
/* Send email confirmation */
var token = sailsTokenAuth.issueToken({
id_sup: supervisor.id,
role: params.role,
id_off: params.id_off,
}, 60*24*7); // expires in 1 week
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);
mailService.mailer()
......@@ -288,11 +290,6 @@ module.exports = {
if (!params.name || !params.surname || !params.gender || !params.password || !params.email )
res.badRequest("Invalid params");
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,
......@@ -301,18 +298,21 @@ module.exports = {
password: params.password,
email: params.email,
pic: sails.config.pictogram.paths.defaultAvatarFileName,
address: params.address || null,
address: params.address || '',
postal_code: params.postal_code || '',
country: params.country || null,
phone: params.phone || null,
lang: params.lang || null,
phone: params.phone || '',
lang: params.lang || 'es-es',
ttsEngine: params.ttsEngine || null,
id_off: params.id_off || null
})
.then(function (supervisor) {
.then(function (sup) {
if (!supervisor)
if (!sup)
res.serverError("Supervisor created but returned null");
supervisor = sup;
if (params.role === 'therapist_office' || params.role === 'tutor_office') {
sendConfirmationMail((err) => {
if (err) throw err;
......
......@@ -75,9 +75,10 @@ module.exports = {
type: "integer"
},
admin: {
model: 'supervisor',
required: false
//type: 'integer'
columnName: 'admin',
required: true,
type: 'integer',
model: 'Supervisor'
},
// Relación con Teacher. [1 Office to N Teacher]
supervisors: {
......
......@@ -52,6 +52,10 @@ module.exports = {
type: "string",
size: 180
},
postal_code: {
type: "string",
size: 10
},
country: {
type: "string",
size: 2
......
......@@ -101,18 +101,18 @@ function SignInCtrl($scope,
$scope.showdialog = true;
if ($scope.formdata.office_idx != -1) {
$scope.formdata.id_off = $scope.offices[$scope.office_idx].id;
$scope.formdata.id_off = $scope.offices[$scope.formdata.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
$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
......
......@@ -231,7 +231,7 @@
<legend translate>office_center</legend>
<select class="form-control" ng-model="formdata.office_idx" ng-required="formdata.role == 'therapist_office' || formdata.role == 'tutor_office'">
<option selected disabled hidden value="-1">{{ 'select_office' | translate }}</option>
<option ng-repeat="office in offices | orderBy: 'name' track by $index" value="$index"> {{ office.name }} </option>
<option ng-repeat="office in offices | orderBy: 'name' track by $index" ng-value="$index"> {{ office.name }} {{$index}} {{office.id}}</option>
</select>
</div>
......@@ -247,6 +247,7 @@
</div>
<p class="text-center">
<a href="/app/#/login" class="btn btn-default" translate>cancel</a>
<button type="submit" class="btn btn-primary" ng-disabled="signInForm.$invalid" translate>create_account</button>
</p>
......
......@@ -7,5 +7,5 @@
"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.",
"welcome_msg1": "Welcome to Pictogram, {{ name }}!",
"welcome_msg2": "Your account is now active, so you can proceed to <a href=\"{{ login_url }}\">login</a>."
"welcome_msg2": "Your account is now active. You can proceed to <a href=\"{{ login_url }}\">login</a>."
}
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