working on recaptcha

parent fa6d416d
...@@ -851,7 +851,16 @@ module.exports = { ...@@ -851,7 +851,16 @@ module.exports = {
add_picto: function (req, res) { add_picto: function (req, res) {
var params = req.allParams(); 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) => { .then((student) => {
if (!student) { if (!student) {
sails.log.error(`Student ${params.id_stu} not found`); sails.log.error(`Student ${params.id_stu} not found`);
...@@ -890,7 +899,7 @@ module.exports = { ...@@ -890,7 +899,7 @@ module.exports = {
return res.ok(resp); return res.ok(resp);
}); });
}) })
.catch(err => res.serverError("Error adding picto: " + err)); .catch(err => res.serverError(err));
}, },
/** /**
......
...@@ -97,6 +97,7 @@ ...@@ -97,6 +97,7 @@
"error_deleting_picto": "Error deleting picto", "error_deleting_picto": "Error deleting picto",
"error_downloading_supervisors": "Error downloading supervisors", "error_downloading_supervisors": "Error downloading supervisors",
"error_downloading_offices": "Error downloading offices", "error_downloading_offices": "Error downloading offices",
"error_duplicated_picto": "That picto is already in the vocabulary",
"error_fetching_students": "Error when loading students", "error_fetching_students": "Error when loading students",
"error_only_support_images": "Only images are supported (JPG, PNG or GIF files)", "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", "error_on_request": "The request has not been processed. Please, check your fields",
......
...@@ -100,6 +100,7 @@ ...@@ -100,6 +100,7 @@
"error_deleting_picto": "Error borrando el picto", "error_deleting_picto": "Error borrando el picto",
"error_downloading_supervisors": "Error al descargar los supervisores", "error_downloading_supervisors": "Error al descargar los supervisores",
"error_downloading_offices": "Error al descargar las oficinas", "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_fetching_students": "Error al cargar estudiantes",
"error_only_support_images": "Sólo se soportan imágenes (ficheros JPG, PNG o GIF)", "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.", "error_on_request": "Se ha producido un error. Por favor, compruebe los valores introducidos.",
......
...@@ -8,7 +8,6 @@ var dashboardApp = angular.module('dashboardApp', [ ...@@ -8,7 +8,6 @@ var dashboardApp = angular.module('dashboardApp', [
'dashboardServices', 'dashboardServices',
'dashboardDirectives', 'dashboardDirectives',
'pascalprecht.translate', 'pascalprecht.translate',
'reCAPTCHA', // TODO: delete after testing vsRecaptcha
'vcRecaptcha', 'vcRecaptcha',
'ui.bootstrap', 'ui.bootstrap',
'angularFileUpload', 'angularFileUpload',
...@@ -29,6 +28,17 @@ dashboardApp.constant('CONSTANTS', { ...@@ -29,6 +28,17 @@ dashboardApp.constant('CONSTANTS', {
password_minlength: 8 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 */ /* Toast (notification) configuration */
dashboardApp.config(['ngToastProvider', function (ngToast) { dashboardApp.config(['ngToastProvider', function (ngToast) {
ngToast.configure({ ngToast.configure({
......
...@@ -11,7 +11,8 @@ function SignInCtrl($scope, ...@@ -11,7 +11,8 @@ function SignInCtrl($scope,
$translate, $translate,
config, config,
CONSTANTS, CONSTANTS,
ngToast) { ngToast)
{
$scope.reset = function () { $scope.reset = function () {
$scope.formdata = { $scope.formdata = {
...@@ -30,6 +31,32 @@ function SignInCtrl($scope, ...@@ -30,6 +31,32 @@ function SignInCtrl($scope,
$scope.reset(); $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 // Form submit
$scope.signin = function () { $scope.signin = function () {
// Validate email match // Validate email match
......
<!-- SigningCtrl controls here, see app.js --> <!-- SigningCtrl controls here, see app.js -->
<div ng-controller="RecaptchaCtrl"></div> <!-- add reCaptcha controller -->
<div class="container"> <div class="container">
<div class="row"> <div class="row">
...@@ -79,13 +78,9 @@ ...@@ -79,13 +78,9 @@
</fieldset> </fieldset>
<div class="form-group"> <div class="form-group">
<label>Captcha*</label>
<div <div
vc-recaptcha vc-recaptcha
on-create="recaptcha.setWidgetId(recaptcha.widgetId)" key="6LdLjh0TAAAAANblo_KUGNnmRZuIetOkdjdhj1b6"
on-success="recaptcha.setResponse(recaptcha.response)"
on-expire="recaptcha.cbExpiration()"
lang="recaptcha.lang"
></div> ></div>
</div> </div>
......
...@@ -389,7 +389,10 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -389,7 +389,10 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
}, function () {}); }, function () {});
}) })
.error(function () { .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') }); ngToast.danger({ content: $translate.instant('error_adding_picto') });
}); });
......
...@@ -108,5 +108,9 @@ module.exports.pictogram = { ...@@ -108,5 +108,9 @@ module.exports.pictogram = {
supervisorId supervisorId
); );
} }
},
error_codes: {
'DUPLICATED_PICTO': 1
} }
}; };
...@@ -36,7 +36,6 @@ module.exports = function (grunt) { ...@@ -36,7 +36,6 @@ module.exports = function (grunt) {
'assets/scripts/config.js', 'assets/scripts/config.js',
'assets/scripts/controllers/controllers.js', 'assets/scripts/controllers/controllers.js',
'assets/scripts/controllers/main.js', 'assets/scripts/controllers/main.js',
'assets/scripts/controllers/recaptcha.js',
'assets/scripts/modules/login/controllers/login.js', 'assets/scripts/modules/login/controllers/login.js',
'assets/scripts/modules/login/controllers/login_setting_password.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