working on recaptcha

parent fa6d416d
......@@ -851,7 +851,16 @@ module.exports = {
add_picto: function (req, res) {
var params = req.allParams();
Student.findOne({ id: params.id_stu })
StuPicto.find({id_pic: params.id_picto})
.then((entries) => {
if (entries && entries.length > 0) {
var err = new Error("Picto already in student's vocabulary");
err.code = sails.config.pictogram.error_codes.DUPLICATED_PICTO;
throw err;
}
return Student.findOne({ id: params.id_stu });
})
.then((student) => {
if (!student) {
sails.log.error(`Student ${params.id_stu} not found`);
......@@ -890,7 +899,7 @@ module.exports = {
return res.ok(resp);
});
})
.catch(err => res.serverError("Error adding picto: " + err));
.catch(err => res.serverError(err));
},
/**
......
......@@ -97,6 +97,7 @@
"error_deleting_picto": "Error deleting picto",
"error_downloading_supervisors": "Error downloading supervisors",
"error_downloading_offices": "Error downloading offices",
"error_duplicated_picto": "That picto is already in the vocabulary",
"error_fetching_students": "Error when loading students",
"error_only_support_images": "Only images are supported (JPG, PNG or GIF files)",
"error_on_request": "The request has not been processed. Please, check your fields",
......
......@@ -100,6 +100,7 @@
"error_deleting_picto": "Error borrando el picto",
"error_downloading_supervisors": "Error al descargar los supervisores",
"error_downloading_offices": "Error al descargar las oficinas",
"error_duplicated_picto": "El picto ya está en este vocabulario",
"error_fetching_students": "Error al cargar estudiantes",
"error_only_support_images": "Sólo se soportan imágenes (ficheros JPG, PNG o GIF)",
"error_on_request": "Se ha producido un error. Por favor, compruebe los valores introducidos.",
......
......@@ -8,7 +8,6 @@ var dashboardApp = angular.module('dashboardApp', [
'dashboardServices',
'dashboardDirectives',
'pascalprecht.translate',
'reCAPTCHA', // TODO: delete after testing vsRecaptcha
'vcRecaptcha',
'ui.bootstrap',
'angularFileUpload',
......@@ -29,6 +28,17 @@ dashboardApp.constant('CONSTANTS', {
password_minlength: 8
});
/* reCaptcha configuration */
dashboardApp.config(['vcRecaptchaServiceProvider', function(vcRecaptchaServiceProvider){
vcRecaptchaServiceProvider.setSiteKey('6LdLjh0TAAAAANblo_KUGNnmRZuIetOkdjdhj1b6');
vcRecaptchaServiceProvider.setTheme('light');
//vcRecaptchaServiceProvider.setStoken('--- YOUR GENERATED SECURE TOKEN ---')
vcRecaptchaServiceProvider.setSize('normal');
//vcRecaptchaServiceProvider.setType('---- audio or image ----')
vcRecaptchaServiceProvider.setLang('es-es');
}]);
/* Toast (notification) configuration */
dashboardApp.config(['ngToastProvider', function (ngToast) {
ngToast.configure({
......
......@@ -11,7 +11,8 @@ function SignInCtrl($scope,
$translate,
config,
CONSTANTS,
ngToast) {
ngToast)
{
$scope.reset = function () {
$scope.formdata = {
......@@ -30,6 +31,32 @@ function SignInCtrl($scope,
$scope.reset();
//
// reCaptcha functions
//
/*
$scope.recaptcha = {
lang : $translate.use(),
response : null,
widgetId : null,
setResponse: function (response) {
console.info('Response available');
$scope.recaptcha.response = response;
},
setWidgetId: function (widgetId) {
console.info('Created widget ID: %s', widgetId);
$scope.recaptcha.widgetId = widgetId;
},
cbExpiration: function() {
console.info('Captcha expired. Resetting response object');
vcRecaptchaService.reload($scope.recaptcha.widgetId);
$scope.recaptcha.response = null;
}
};*/
// Form submit
$scope.signin = function () {
// Validate email match
......
<!-- SigningCtrl controls here, see app.js -->
<div ng-controller="RecaptchaCtrl"></div> <!-- add reCaptcha controller -->
<div class="container">
<div class="row">
......@@ -79,13 +78,9 @@
</fieldset>
<div class="form-group">
<label>Captcha*</label>
<div
vc-recaptcha
on-create="recaptcha.setWidgetId(recaptcha.widgetId)"
on-success="recaptcha.setResponse(recaptcha.response)"
on-expire="recaptcha.cbExpiration()"
lang="recaptcha.lang"
key="6LdLjh0TAAAAANblo_KUGNnmRZuIetOkdjdhj1b6"
></div>
</div>
......
......@@ -389,8 +389,11 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
}, function () {});
})
.error(function () {
ngToast.danger({ content: $translate.instant('error_adding_picto') });
.error(function (err) {
if (err.code && err.code == 1) // codes are in sails/config/pictogram.js
ngToast.danger({ content: $translate.instant('error_duplicated_picto') });
else
ngToast.danger({ content: $translate.instant('error_adding_picto') });
});
// not needed
......@@ -440,7 +443,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
}
}
});
};
// Add new listener to the event
......
......@@ -108,5 +108,9 @@ module.exports.pictogram = {
supervisorId
);
}
},
error_codes: {
'DUPLICATED_PICTO': 1
}
};
......@@ -36,7 +36,6 @@ module.exports = function (grunt) {
'assets/scripts/config.js',
'assets/scripts/controllers/controllers.js',
'assets/scripts/controllers/main.js',
'assets/scripts/controllers/recaptcha.js',
'assets/scripts/modules/login/controllers/login.js',
'assets/scripts/modules/login/controllers/login_setting_password.js',
......
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