diff --git a/Gruntfile.js b/Gruntfile.js index 5e07fd01..41cad943 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -19,7 +19,7 @@ 'use strict'; var pkg = require('./package.json'); -var AV_CONFIG_VERSION = '103111.6'; +var AV_CONFIG_VERSION = '103111.7'; //Using exclusion patterns slows down Grunt significantly //instead of creating a set of patterns like '**/*.js' and '!**/node_modules/**' @@ -195,10 +195,10 @@ module.exports = function (grunt) { options: { remove: ['script[data-remove!="false"]','link[data-remove!="false"]'], append: [ - {selector:'body',html:''}, + {selector:'body',html:''}, {selector:'body',html:''}, - {selector:'body',html:''}, - {selector:'body',html:''}, + {selector:'body',html:''}, + {selector:'body',html:''}, {selector:'head',html:''} ] }, @@ -228,9 +228,9 @@ module.exports = function (grunt) { 'temp/libnocompat.js': ['<%= dom_munger.data.libnocompatjs %>'], 'temp/lib.js': ['<%= dom_munger.data.libjs %>'], 'temp/app.js': ['<%= dom_munger.data.appjs %>','<%= ngtemplates.main.dest %>'], - 'dist/avConfig-v103111.6.js': ['avConfig.js'], - 'dist/avThemes-v103111.6.js': ['avThemes.js'], - 'dist/avPlugins-v103111.6.js': ['plugins/**/*.js'] + 'dist/avConfig-v103111.7.js': ['avConfig.js'], + 'dist/avThemes-v103111.7.js': ['avThemes.js'], + 'dist/avPlugins-v103111.7.js': ['plugins/**/*.js'] } } }, @@ -262,10 +262,10 @@ module.exports = function (grunt) { beautify: true }, files: { - 'dist/appCommon-v103111.6.js': 'temp/app.js', - 'dist/libCommon-v103111.6.js': 'temp/lib.js', - 'dist/libnocompat-v103111.6.js': 'temp/libnocompat.js', - 'dist/libcompat-v103111.6.js': 'temp/libcompat.js', + 'dist/appCommon-v103111.7.js': 'temp/app.js', + 'dist/libCommon-v103111.7.js': 'temp/lib.js', + 'dist/libnocompat-v103111.7.js': 'temp/libnocompat.js', + 'dist/libcompat-v103111.7.js': 'temp/libcompat.js', 'dist/avWidgets.js': 'avWidgets.js', "dist/locales/moment/es.js": "bower_components/moment/lang/es.js", diff --git a/avConfig.js b/avConfig.js index 09a025fa..872154b6 100644 --- a/avConfig.js +++ b/avConfig.js @@ -20,7 +20,7 @@ * in this same file, which you might want to edit and tune if needed. */ -var AV_CONFIG_VERSION = '103111.6'; +var AV_CONFIG_VERSION = '103111.7'; var avConfigData = { // the base url path for ajax requests, for example for sending ballots or diff --git a/avRegistration/fields/code-field-directive/code-field-directive.html b/avRegistration/fields/code-field-directive/code-field-directive.html index 5ee8bce0..5f328574 100644 --- a/avRegistration/fields/code-field-directive/code-field-directive.html +++ b/avRegistration/fields/code-field-directive/code-field-directive.html @@ -19,7 +19,7 @@ required />

- + 0) { @@ -66,18 +70,43 @@ angular.module('avRegistration') var telInput = angular.element(document.getElementById(inputName)); return telInput.intlTelInput("isValidNumber"); } + + function isValidEmail(email) { + var pattern = Patterns.get('email'); + return null !== email.match(pattern); + } scope.resendAuthCode = function(field) { - if (scope.sendingData || !_.contains(["sms", "sms-otp"], scope.method)) { + if (scope.sendingData || !_.contains(["email", "sms", "sms-otp"], scope.method)) { return; } + var data = {}; - if (scope.telIndex === -1) { - return; - } + // sms or sms-otp + if (_.contains(["sms", "sms-otp"], scope.method)) { + + if (scope.telIndex === -1) { + return; + } + + if (!isValidTel("input" + scope.telIndex)) { + return; + } + + data['tlf'] = scope.telField.value; + } else if ("email" === scope.method) { // email + if (-1 === scope.emailIndex) { + return; + } + var email = scope.email; + if (null === email) { + email = scope.login_fields[scope.emailIndex].value; + } + if (!isValidEmail(email)) { + return; + } - if (!isValidTel("input" + scope.telIndex)) { - return; + data['email'] = email; } // reset code field, as we are going to send a new one @@ -85,13 +114,14 @@ angular.module('avRegistration') field.value = ""; } - var data = {}; - data['tlf'] = scope.telField.value; - scope.sendingData = true; Authmethod.resendAuthCode(data, autheventid) .success(function(rcvData) { - scope.telField.disabled = true; + if (_.contains(["sms", "sms-otp"], scope.method)) { + scope.telField.disabled = true; + } else if ("email" === scope.method) { + scope.login_fields[scope.emailIndex].disabled = true; + } scope.currentFormStep = 1; $timeout(scope.sendingDataTimeout, 3000); }) @@ -186,7 +216,23 @@ angular.module('avRegistration') scope.registrationAllowed = (authevent['census'] === 'open'); scope.login_fields = Authmethod.getLoginFields(authevent); scope.telIndex = -1; + scope.emailIndex = -1; scope.telField = null; + scope.allowUserResend = (function () { + var ret = false; + var href = $location.path(); + var adminMatch = href.match(/^\/admin\//); + var electionsMatch = href.match(/^\/(elections|election)\/([0-9]+)\//); + + if (_.isArray(adminMatch)) { + ret = true; + } else if (_.isArray(electionsMatch) && 3 === electionsMatch.length) { + ret = (_.isObject(authevent.auth_method_config) && + _.isObject(authevent.auth_method_config.config) && + true === authevent.auth_method_config.config.allow_user_resend); + } + return ret; + })(); var fields = _.map( scope.login_fields, @@ -198,9 +244,12 @@ angular.module('avRegistration') el.value = null; el.disabled = false; } - if (el.type === "email" && scope.email !== null) { - el.value = scope.email; - el.disabled = true; + if (el.type === "email") { + if (scope.email !== null) { + el.value = scope.email; + el.disabled = true; + } + scope.emailIndex = index; } else if (el.type === "code" && scope.code !== null) { el.value = scope.code.trim().replace(/ |\n|\t|-|_/g,'').toUpperCase(); el.disabled = true; diff --git a/bower.json b/bower.json index 13a61649..98e47140 100755 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "avCommon", - "version" : "103111.6", + "version" : "103111.7", "main": "index.html", "ignore": [ "tests", diff --git a/dist/appCommon-v103111.6.js b/dist/appCommon-v103111.7.js similarity index 95% rename from dist/appCommon-v103111.6.js rename to dist/appCommon-v103111.7.js index 4e51190b..6cf3c395 100644 --- a/dist/appCommon-v103111.6.js +++ b/dist/appCommon-v103111.7.js @@ -219,22 +219,37 @@ angular.module("avRegistration").factory("Authmethod", [ "$http", "$cookies", "C }, authmethod; } ]), angular.module("avRegistration").controller("LoginController", [ "$scope", "$stateParams", "$filter", "ConfigService", "$i18next", function($scope, $stateParams, $filter, ConfigService, $i18next) { $scope.event_id = $stateParams.id, $scope.code = $stateParams.code, $scope.email = $stateParams.email; -} ]), angular.module("avRegistration").directive("avLogin", [ "Authmethod", "StateDataService", "$parse", "$state", "$cookies", "$i18next", "$window", "$timeout", "ConfigService", function(Authmethod, StateDataService, $parse, $state, $cookies, $i18next, $window, $timeout, ConfigService) { +} ]), angular.module("avRegistration").directive("avLogin", [ "Authmethod", "StateDataService", "$parse", "$state", "$location", "$cookies", "$i18next", "$window", "$timeout", "ConfigService", "Patterns", function(Authmethod, StateDataService, $parse, $state, $location, $cookies, $i18next, $window, $timeout, ConfigService, Patterns) { function link(scope, element, attrs) { function isValidTel(inputName) { return !!document.getElementById(inputName) && angular.element(document.getElementById(inputName)).intlTelInput("isValidNumber"); } + function isValidEmail(email) { + var pattern = Patterns.get("email"); + return null !== email.match(pattern); + } var adminId = ConfigService.freeAuthId + "", autheventid = attrs.eventId; scope.orgName = ConfigService.organization.orgName, $cookies["authevent_" + adminId] && $cookies["authevent_" + adminId] === adminId && autheventid === adminId && $cookies["auth_authevent_" + adminId] && ($window.location.href = "/admin/elections"), scope.sendingData = !1, scope.currentFormStep = 0, scope.stateData = StateDataService.getData(), - scope.signupLink = ConfigService.signupLink, scope.code = null, attrs.code && attrs.code.length > 0 && (scope.code = attrs.code), - scope.email = null, attrs.email && attrs.email.length > 0 && (scope.email = attrs.email), - scope.isAdmin = !1, autheventid === adminId && (scope.isAdmin = !0), scope.resendAuthCode = function(field) { - if (!scope.sendingData && _.contains([ "sms", "sms-otp" ], scope.method) && -1 !== scope.telIndex && isValidTel("input" + scope.telIndex)) { - field && (field.value = ""); + scope.signupLink = ConfigService.signupLink, scope.allowUserResend = !1, scope.code = null, + attrs.code && attrs.code.length > 0 && (scope.code = attrs.code), scope.email = null, + attrs.email && attrs.email.length > 0 && (scope.email = attrs.email), scope.isAdmin = !1, + autheventid === adminId && (scope.isAdmin = !0), scope.resendAuthCode = function(field) { + if (!scope.sendingData && _.contains([ "email", "sms", "sms-otp" ], scope.method)) { var data = {}; - data.tlf = scope.telField.value, scope.sendingData = !0, Authmethod.resendAuthCode(data, autheventid).success(function(rcvData) { - scope.telField.disabled = !0, scope.currentFormStep = 1, $timeout(scope.sendingDataTimeout, 3e3); + if (_.contains([ "sms", "sms-otp" ], scope.method)) { + if (-1 === scope.telIndex) return; + if (!isValidTel("input" + scope.telIndex)) return; + data.tlf = scope.telField.value; + } else if ("email" === scope.method) { + if (-1 === scope.emailIndex) return; + var email = scope.email; + if (null === email && (email = scope.login_fields[scope.emailIndex].value), !isValidEmail(email)) return; + data.email = email; + } + field && (field.value = ""), scope.sendingData = !0, Authmethod.resendAuthCode(data, autheventid).success(function(rcvData) { + _.contains([ "sms", "sms-otp" ], scope.method) ? scope.telField.disabled = !0 : "email" === scope.method && (scope.login_fields[scope.emailIndex].disabled = !0), + scope.currentFormStep = 1, $timeout(scope.sendingDataTimeout, 3e3); }).error(function(error) { $timeout(scope.sendingDataTimeout, 3e3), scope.error = $i18next("avRegistration.errorSendingAuthCode"); }); @@ -277,11 +292,15 @@ angular.module("avRegistration").factory("Authmethod", [ "$http", "$cookies", "C }, scope.apply = function(authevent) { scope.method = authevent.auth_method, scope.name = authevent.name, scope.registrationAllowed = "open" === authevent.census, scope.login_fields = Authmethod.getLoginFields(authevent), scope.telIndex = -1, - scope.telField = null; + scope.emailIndex = -1, scope.telField = null, scope.allowUserResend = function() { + var ret = !1, href = $location.path(), adminMatch = href.match(/^\/admin\//), electionsMatch = href.match(/^\/(elections|election)\/([0-9]+)\//); + return _.isArray(adminMatch) ? ret = !0 : _.isArray(electionsMatch) && 3 === electionsMatch.length && (ret = _.isObject(authevent.auth_method_config) && _.isObject(authevent.auth_method_config.config) && !0 === authevent.auth_method_config.config.allow_user_resend), + ret; + }(); var fields = _.map(scope.login_fields, function(el, index) { return scope.stateData[el.name] ? (el.value = scope.stateData[el.name], el.disabled = !0) : (el.value = null, - el.disabled = !1), "email" === el.type && null !== scope.email ? (el.value = scope.email, - el.disabled = !0) : "code" === el.type && null !== scope.code ? (el.value = scope.code.trim().replace(/ |\n|\t|-|_/g, "").toUpperCase(), + el.disabled = !1), "email" === el.type ? (null !== scope.email && (el.value = scope.email, + el.disabled = !0), scope.emailIndex = index) : "code" === el.type && null !== scope.code ? (el.value = scope.code.trim().replace(/ |\n|\t|-|_/g, "").toUpperCase(), el.disabled = !0) : "tlf" === el.type && "sms" === scope.method ? (null !== scope.email && -1 === scope.email.indexOf("@") && (el.value = scope.email, el.disabled = !0), scope.telIndex = index + 1, scope.telField = el) : "tlf" === el.type && "sms-otp" === scope.method && (null !== scope.email && -1 === scope.email.indexOf("@") && (el.value = scope.email, el.disabled = !0, scope.currentFormStep = 1), scope.telIndex = index + 1, scope.telField = el), @@ -452,14 +471,17 @@ angular.module("avRegistration").factory("Authmethod", [ "$http", "$cookies", "C function link(scope, element, attrs) { scope.codePattern = /[abcdefghjklmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789-]{8,9}/; var rand_code = "" + _.random(1e12); - scope.code_id = "input" + scope.index + rand_code, scope.showResendAuthCode = function() { + if (scope.code_id = "input" + scope.index + rand_code, scope.showResendAuthCode = function() { var data = { showUserSendAuthCode: !0 }; return Plugins.hook("hide-user-send-auth-code", data), data.showUserSendAuthCode; - }, scope.isValidTel = function(inputName) { - return !!document.getElementById(inputName) && angular.element(document.getElementById(inputName)).intlTelInput("isValidNumber"); - }; + }, "sms" === scope.method || "sms-otp" === scope.method) { + var telInput = angular.element(document.getElementById("input" + scope.telIndex)); + scope.isValidTel = telInput.intlTelInput("isValidNumber"), scope.$watch("telField.value", function(newValue, oldValue) { + scope.isValidTel = telInput.intlTelInput("isValidNumber"); + }, !0); + } } return { restrict: "AE", @@ -1113,7 +1135,7 @@ angular.module("jm.i18next").config([ "$i18nextProvider", "ConfigServiceProvider $templateCache.put("avRegistration/field-directive/field-directive.html", '

'), $templateCache.put("avRegistration/fields/bool-field-directive/bool-field-directive.html", '

'), $templateCache.put("avRegistration/fields/captcha-field-directive/captcha-field-directive.html", '

{{field.help}}

{{authMethod.captcha_status}}
'), - $templateCache.put("avRegistration/fields/code-field-directive/code-field-directive.html", '

'), + $templateCache.put("avRegistration/fields/code-field-directive/code-field-directive.html", '

'), $templateCache.put("avRegistration/fields/dni-field-directive/dni-field-directive.html", '

'), $templateCache.put("avRegistration/fields/email-field-directive/email-field-directive.html", '
'), $templateCache.put("avRegistration/fields/image-field-directive/image-field-directive.html", '

'), diff --git a/dist/avConfig-v103111.6.js b/dist/avConfig-v103111.7.js similarity index 99% rename from dist/avConfig-v103111.6.js rename to dist/avConfig-v103111.7.js index 09a025fa..872154b6 100644 --- a/dist/avConfig-v103111.6.js +++ b/dist/avConfig-v103111.7.js @@ -20,7 +20,7 @@ * in this same file, which you might want to edit and tune if needed. */ -var AV_CONFIG_VERSION = '103111.6'; +var AV_CONFIG_VERSION = '103111.7'; var avConfigData = { // the base url path for ajax requests, for example for sending ballots or diff --git a/dist/avPlugins-v103111.6.js b/dist/avPlugins-v103111.7.js similarity index 100% rename from dist/avPlugins-v103111.6.js rename to dist/avPlugins-v103111.7.js diff --git a/dist/avThemes-v103111.6.js b/dist/avThemes-v103111.7.js similarity index 100% rename from dist/avThemes-v103111.6.js rename to dist/avThemes-v103111.7.js diff --git a/dist/index.html b/dist/index.html index 6597d45f..260968fe 100644 --- a/dist/index.html +++ b/dist/index.html @@ -1,2 +1,2 @@ Agora Voting
Page is taking some time to load, wait a moment please. If it takes too long, please check that you have javascript activated, try with another browser or contact us.
For security reasons, your browser is unsupported. Please use a newer web browser (if you are using Internet Explorer, use version 9 or newer).
\ No newline at end of file + so in the compiled app e2e tests are not expected work. -->
Page is taking some time to load, wait a moment please. If it takes too long, please check that you have javascript activated, try with another browser or contact us.
For security reasons, your browser is unsupported. Please use a newer web browser (if you are using Internet Explorer, use version 9 or newer).
\ No newline at end of file diff --git a/dist/libCommon-v103111.6.js b/dist/libCommon-v103111.7.js similarity index 100% rename from dist/libCommon-v103111.6.js rename to dist/libCommon-v103111.7.js diff --git a/dist/libcompat-v103111.6.js b/dist/libcompat-v103111.7.js similarity index 100% rename from dist/libcompat-v103111.6.js rename to dist/libcompat-v103111.7.js diff --git a/dist/libnocompat-v103111.6.js b/dist/libnocompat-v103111.7.js similarity index 100% rename from dist/libnocompat-v103111.6.js rename to dist/libnocompat-v103111.7.js diff --git a/package.json b/package.json index cc2253f8..a8d13bcf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "agora-gui-common", - "version" : "103111.6.0", + "version" : "103111.7.0", "devDependencies": { "grunt": "~0.4", "grunt-angular-templates": "~0.5",