Skip to content

Commit

Permalink
Merge pull request #78 from agoravoting/go-v7
Browse files Browse the repository at this point in the history
Go v7
  • Loading branch information
Findeton committed Oct 23, 2017
2 parents 9eb590b + aeef47f commit c825c6b
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 54 deletions.
22 changes: 11 additions & 11 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/**'
Expand Down Expand Up @@ -195,10 +195,10 @@ module.exports = function (grunt) {
options: {
remove: ['script[data-remove!="false"]','link[data-remove!="false"]'],
append: [
{selector:'body',html:'<!--[if lte IE 8]><script src="/libcompat-v103111.6.js"></script><![endif]--><!--[if gte IE 9]><script src="/libnocompat-v103111.6.js"></script><![endif]--><!--[if !IE]><!--><script src="/libnocompat-v103111.6.js"></script><!--<![endif]-->'},
{selector:'body',html:'<!--[if lte IE 8]><script src="/libcompat-v103111.7.js"></script><![endif]--><!--[if gte IE 9]><script src="/libnocompat-v103111.7.js"></script><![endif]--><!--[if !IE]><!--><script src="/libnocompat-v103111.7.js"></script><!--<![endif]-->'},
{selector:'body',html:'<!--All the source code of this program under copyright. Take a look at the license details at https://github.com/agoravoting/agora-core-view/blob/master/README.md -->'},
{selector:'body',html:'<script src="/appCommon-v103111.6.js"></script>'},
{selector:'body',html:'<script src="/avPlugins-v103111.6.js"></script>'},
{selector:'body',html:'<script src="/appCommon-v103111.7.js"></script>'},
{selector:'body',html:'<script src="/avPlugins-v103111.7.js"></script>'},
{selector:'head',html:'<link rel="stylesheet" id="theme" href="/themes/default/app.min.css">'}
]
},
Expand Down Expand Up @@ -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']
}
}
},
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion avConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
required />
<p class="help-block" ng-i18next="avRegistration.codeHelp">
<p class="help-block code-help">
<span ng-if="showResendAuthCode() && !sendingData && isValidTel('input' + telIndex)">
<span ng-if="allowUserResend && showResendAuthCode() && !sendingData && (('sms' !== method && 'sms-otp' !== method) || isValidTel)">
<b ng-i18next="avRegistration.noCodeReceivedQuestion"></b>
<a
ng-click="resendAuthCode(field)"
Expand Down
17 changes: 10 additions & 7 deletions avRegistration/fields/code-field-directive/code-field-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ angular.module('avRegistration')
return data.showUserSendAuthCode;
};

scope.isValidTel = function (inputName) {
if (!document.getElementById(inputName)) {
return false;
}
var telInput = angular.element(document.getElementById(inputName));
return telInput.intlTelInput("isValidNumber");
};
if ('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");
},
true);
}
}
return {
restrict: 'AE',
Expand Down
77 changes: 63 additions & 14 deletions avRegistration/login-directive/login-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ angular.module('avRegistration')
StateDataService,
$parse,
$state,
$location,
$cookies,
$i18next,
$window,
$timeout,
ConfigService) {
ConfigService,
Patterns) {
// we use it as something similar to a controller here
function link(scope, element, attrs) {
var adminId = ConfigService.freeAuthId + '';
Expand All @@ -44,6 +46,8 @@ angular.module('avRegistration')
scope.stateData = StateDataService.getData();

scope.signupLink = ConfigService.signupLink;

scope.allowUserResend = false;

scope.code = null;
if (attrs.code && attrs.code.length > 0) {
Expand All @@ -66,32 +70,58 @@ 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
if (!!field) {
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);
})
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "avCommon",
"version" : "103111.6",
"version" : "103111.7",
"main": "index.html",
"ignore": [
"tests",
Expand Down
Loading

0 comments on commit c825c6b

Please sign in to comment.