Skip to content

Commit 0ca4d57

Browse files
authored
Merge pull request #44 from agoravoting/go
Go
2 parents 1eb31ba + 9424d8f commit 0ca4d57

32 files changed

+243
-64
lines changed

Gruntfile.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'use strict';
2020

2121
var pkg = require('./package.json');
22-
var AV_CONFIG_VERSION = '17.04';
22+
var AV_CONFIG_VERSION = '103111.1';
2323

2424
//Using exclusion patterns slows down Grunt significantly
2525
//instead of creating a set of patterns like '**/*.js' and '!**/node_modules/**'
@@ -192,10 +192,10 @@ module.exports = function (grunt) {
192192
options: {
193193
remove: ['script[data-remove!="false"]','link[data-remove!="false"]'],
194194
append: [
195-
{selector:'body',html:'<!--[if lte IE 8]><script src="/libcompat-v17.04.js"></script><![endif]--><!--[if gte IE 9]><script src="/libnocompat-v17.04.js"></script><![endif]--><!--[if !IE]><!--><script src="/libnocompat-v17.04.js"></script><!--<![endif]-->'},
195+
{selector:'body',html:'<!--[if lte IE 8]><script src="/libcompat-v103111.1.js"></script><![endif]--><!--[if gte IE 9]><script src="/libnocompat-v103111.1.js"></script><![endif]--><!--[if !IE]><!--><script src="/libnocompat-v103111.1.js"></script><!--<![endif]-->'},
196196
{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 -->'},
197-
{selector:'body',html:'<script src="/appCommon-v17.04.js"></script>'},
198-
{selector:'body',html:'<script src="/avPlugins-v17.04.js"></script>'},
197+
{selector:'body',html:'<script src="/appCommon-v103111.1.js"></script>'},
198+
{selector:'body',html:'<script src="/avPlugins-v103111.1.js"></script>'},
199199
{selector:'head',html:'<link rel="stylesheet" id="theme" href="/themes/default/app.min.css">'}
200200
]
201201
},
@@ -225,9 +225,9 @@ module.exports = function (grunt) {
225225
'temp/libnocompat.js': ['<%= dom_munger.data.libnocompatjs %>'],
226226
'temp/lib.js': ['<%= dom_munger.data.libjs %>'],
227227
'temp/app.js': ['<%= dom_munger.data.appjs %>','<%= ngtemplates.main.dest %>'],
228-
'dist/avConfig-v17.04.js': ['avConfig.js'],
229-
'dist/avThemes-v17.04.js': ['avThemes.js'],
230-
'dist/avPlugins-v17.04.js': ['plugins/**/*.js']
228+
'dist/avConfig-v103111.1.js': ['avConfig.js'],
229+
'dist/avThemes-v103111.1.js': ['avThemes.js'],
230+
'dist/avPlugins-v103111.1.js': ['plugins/**/*.js']
231231
}
232232
}
233233
},
@@ -259,10 +259,10 @@ module.exports = function (grunt) {
259259
beautify: true
260260
},
261261
files: {
262-
'dist/appCommon-v17.04.js': 'temp/app.js',
263-
'dist/libCommon-v17.04.js': 'temp/lib.js',
264-
'dist/libnocompat-v17.04.js': 'temp/libnocompat.js',
265-
'dist/libcompat-v17.04.js': 'temp/libcompat.js',
262+
'dist/appCommon-v103111.1.js': 'temp/app.js',
263+
'dist/libCommon-v103111.1.js': 'temp/lib.js',
264+
'dist/libnocompat-v103111.1.js': 'temp/libnocompat.js',
265+
'dist/libcompat-v103111.1.js': 'temp/libcompat.js',
266266
'dist/avWidgets.js': 'avWidgets.js',
267267

268268
"dist/locales/moment/es.js": "bower_components/moment/lang/es.js",

avConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* in this same file, which you might want to edit and tune if needed.
2121
*/
2222

23-
var AV_CONFIG_VERSION = '17.04';
23+
var AV_CONFIG_VERSION = '103111.1';
2424

2525
var avConfigData = {
2626
// the base url path for ajax requests, for example for sending ballots or

avRegistration/auth-method-service.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ angular.module('avRegistration')
152152
}
153153
});
154154

155-
if (viewEventData.auth_method === "sms" && !found) {
155+
if ((viewEventData.auth_method === "sms" || viewEventData.auth_method === "sms-otp") && !found) {
156156
fields.push({
157157
"name": "tlf",
158158
"type": "tlf",
@@ -181,7 +181,7 @@ angular.module('avRegistration')
181181
});
182182
}
183183

184-
// put captha the last
184+
// put captcha the last
185185
for (var i=0; i<fields.length; i++) {
186186
if (fields[i]['type'] === "captcha") {
187187
var captcha = fields.splice(i, 1);
@@ -194,13 +194,23 @@ angular.module('avRegistration')
194194

195195
authmethod.getLoginFields = function (viewEventData) {
196196
var fields = authmethod.getRegisterFields(viewEventData);
197-
if (viewEventData.auth_method === "sms" || viewEventData.auth_method === "email") {
197+
if (viewEventData.auth_method === "sms" || viewEventData.auth_method === "email")
198+
{
198199
fields.push({
199200
"name": "code",
200201
"type": "code",
201202
"required": true,
202203
"required_on_authentication": true
203204
});
205+
} else if (viewEventData.auth_method === "sms-otp")
206+
{
207+
fields.push({
208+
"name": "code",
209+
"type": "code",
210+
"required": true,
211+
"steps": [1],
212+
"required_on_authentication": true
213+
});
204214
}
205215

206216
fields = _.filter(fields, function (field) {return field.required_on_authentication;});

avRegistration/fields/tel-field-directive/tel-field-directive.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
required />
1515
<p class="help-block" ng-i18next="avRegistration.telHelp">
1616
</p>
17+
<p class="text-warning" ng-if="'sms-otp' === method" ng-i18next="avRegistration.otpHelp">
18+
</p>
1719
<div class="input-error">
1820
<span class="error" ng-show="form.input{{index}}.$error.pattern" ng-i18next="avRegistration.telInvalid"></span>
1921
</div>

avRegistration/login-directive/login-directive.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ <h2 class="tex-center" ng-i18next="[i18next]({name: orgName})avRegistration.logi
66

77
<div class="col-sm-6">
88
<form name="form" id="loginForm" role="form" class="form-horizontal">
9-
<div ng-repeat="field in login_fields" avr-field index="{{$index+1}}">
9+
<div ng-repeat="field in login_fields" avr-field index="{{$index+1}}" ng-if="field.steps === undefined || field.steps.indexOf(currentFormStep) !== -1">
1010
</div>
1111

1212
<div class="col-sm-offset-4 col-sm-8 button-group">

avRegistration/login-directive/login-directive.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ angular.module('avRegistration')
3939
}
4040
scope.sendingData = false;
4141

42+
scope.currentFormStep = 0;
43+
4244
scope.stateData = StateDataService.getData();
4345

4446
scope.code = null;
@@ -56,7 +58,7 @@ angular.module('avRegistration')
5658
}
5759

5860
scope.resendAuthCode = function(field) {
59-
if (scope.sendingData || scope.method !== "sms") {
61+
if (scope.sendingData || !_.contains(["sms", "sms-otp"], scope.method)) {
6062
return;
6163
}
6264

@@ -69,14 +71,18 @@ angular.module('avRegistration')
6971
}
7072

7173
// reset code field, as we are going to send a new one
72-
field.value = "";
74+
if (!!field) {
75+
field.value = "";
76+
}
7377

7478
var data = {};
7579
data['tlf'] = scope.telField.value;
7680

7781
scope.sendingData = true;
7882
Authmethod.resendAuthCode(data, autheventid)
7983
.success(function(rcvData) {
84+
scope.telField.disabled = true;
85+
scope.currentFormStep = 1;
8086
$timeout(scope.sendingDataTimeout, 3000);
8187
})
8288
.error(function(error) {
@@ -96,6 +102,12 @@ angular.module('avRegistration')
96102
if (scope.sendingData) {
97103
return;
98104
}
105+
106+
// loginUser
107+
if (scope.method === 'sms-otp' && scope.currentFormStep === 0) {
108+
scope.resendAuthCode();
109+
return;
110+
}
99111
var data = {
100112
'captcha_code': Authmethod.captcha_code,
101113
};
@@ -188,6 +200,14 @@ angular.module('avRegistration')
188200
}
189201
scope.telIndex = index+1;
190202
scope.telField = el;
203+
} else if (el.type === "tlf" && scope.method === "sms-otp") {
204+
if (scope.email !== null && scope.email.indexOf('@') === -1) {
205+
el.value = scope.email;
206+
el.disabled = true;
207+
scope.currentFormStep = 1;
208+
}
209+
scope.telIndex = index+1;
210+
scope.telField = el;
191211
}
192212
return el;
193213
});

avRegistration/register-directive/register-directive.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ angular.module('avRegistration')
3838
if (!scope.admin) {
3939
return {path: 'election.public.show.login', data: {id: eventId}};
4040
} else {
41-
return {path: 'admin.login', data:{}};
41+
return {path: 'admin.login_email', data:{email: scope.email}};
4242
}
4343
};
4444

@@ -52,7 +52,13 @@ angular.module('avRegistration')
5252
};
5353
_.each(scope.register_fields, function (field) {
5454
data[field.name] = field.value;
55-
if (field.name === 'email') {
55+
if (field.name === 'email' && scope.method === 'email')
56+
{
57+
scope.email = field.value;
58+
}
59+
else if (field.name === 'tlf' &&
60+
_.contains(['sms', 'sms-otp'], scope.method))
61+
{
5662
scope.email = field.value;
5763
}
5864
});

avUi/checker-service.js

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ angular.module('avUi')
125125
if (!pass) {
126126
error(item.check, {key: item.key}, item.postfix);
127127
}
128-
129128
} else if (item.check === "lambda") {
130129
if (!item.validator(d.data[item.key])) {
131130
var errorData = {key: item.key};
@@ -135,6 +134,38 @@ angular.module('avUi')
135134
error(item.check, errorData, item.postfix);
136135
}
137136

137+
} else if (item.check === "is-string-if-defined") {
138+
pass = angular.isUndefined(d.data[item.key]) ||
139+
angular.isString(d.data[item.key], item.postfix);
140+
if (!pass) {
141+
error(item.check, {key: item.key}, item.postfix);
142+
}
143+
144+
} else if (item.check === "array-length-if-defined") {
145+
if (angular.isDefined(d.data[item.key])) {
146+
itemMin = evalValue(item.min, d.data);
147+
itemMax = evalValue(item.max, d.data);
148+
149+
if (angular.isArray(d.data[item.key]) || angular.isString(d.data[item.key]))
150+
{
151+
min = angular.isUndefined(item.min) || d.data[item.key].length >= itemMin;
152+
max = angular.isUndefined(item.max) || d.data[item.key].length <= itemMax;
153+
pass = min && max;
154+
if (!min) {
155+
error(
156+
"array-length-min",
157+
{key: item.key, min: itemMin, num: d.data[item.key].length},
158+
item.postfix);
159+
}
160+
if (!max) {
161+
var itemErrorData0 = {key: item.key, max: itemMax, num: d.data[item.key].length};
162+
error(
163+
"array-length-max",
164+
itemErrorData0,
165+
item.postfix);
166+
}
167+
}
168+
}
138169
} else if (item.check === "is-string") {
139170
pass = angular.isString(d.data[item.key], item.postfix);
140171
if (!pass) {
@@ -247,6 +278,31 @@ angular.module('avUi')
247278
});
248279
}),
249280
true);
281+
} else if (item.check === "object-key-chain") {
282+
pass = _.isString(item.key) && _.isObject(d.data[item.key]);
283+
if (!!pass) {
284+
var data = d.data[item.key];
285+
var extra = {};
286+
extra[item.append.key] = evalValue(item.append.value, data);
287+
var prefix = "";
288+
if (angular.isString(d.prefix)) {
289+
prefix += d.prefix;
290+
}
291+
if (angular.isString(item.prefix)) {
292+
prefix += item.prefix;
293+
}
294+
pass = _.every(
295+
item.checks,
296+
function (check, index) {
297+
return checker({
298+
data: data,
299+
errorData: angular.extend({}, d.errorData, extra),
300+
onError: d.onError,
301+
checks: [check],
302+
prefix: prefix,
303+
});
304+
});
305+
}
250306
}
251307
if (!pass && d.data.groupType === 'chain') {
252308
return false;

avUi/documentation-directive/documentation-directive.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ <h2 class="text-center text-av-secondary" ng-i18next="avDocumentation.documentat
4747
</ul>
4848
<div
4949
class="documentation-html-include"
50-
ng-bind-html="documentation_html_include | addTargetBlank">
50+
av-plugin-html
51+
ng-bind-html="documentation_html_include">
5152
</div>
5253
</div>

avUi/documentation-directive/documentation-directive.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
* loading config, showing results, showing error if needed.
2121
*/
2222
angular.module('avUi').controller('DocumentationUiController',
23-
function($state, $stateParams, $http, $scope,$i18next, ConfigService, InsideIframeService, Authmethod) {
23+
function($state, $stateParams, $http, $scope, $sce, $i18next, ConfigService, InsideIframeService, Authmethod) {
2424
$scope.inside_iframe = InsideIframeService();
2525
$scope.documentation = ConfigService.documentation;
2626
$scope.documentation.security_contact = ConfigService.legal.security_contact;
27-
$scope.documentation_html_include = ConfigService.documentation_html_include;
27+
$scope.documentation_html_include = $sce.trustAsHtml(ConfigService.documentation_html_include);
2828
$scope.auths_url = '/election/' + $stateParams.id + '/public/authorities';
2929
$scope.legal_url = '/election/' + $stateParams.id + '/public/legal';
3030

@@ -41,6 +41,9 @@ angular.module('avUi')
4141
.directive('documentationDirective', function() {
4242
return {
4343
restrict: 'AE',
44+
scope: {
45+
extra: '='
46+
},
4447
templateUrl: 'avUi/documentation-directive/documentation-directive.html',
4548
controller: 'DocumentationUiController'
4649
};

avUi/percent-votes-service.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@ angular.module('avUi')
4444
if (over === undefined || over === null) {
4545
over = question.answer_total_votes_percentage;
4646
}
47-
if (over === "over-valid-votes") {
47+
if ("over-valid-votes" === over || "over-total-valid-votes" === over) {
4848
base = question.totals.valid_votes;
4949
}
50+
else if ("over-total-valid-points" === over &&
51+
undefined !== question.totals.valid_points) {
52+
base = question.totals.valid_points;
53+
}
5054

5155
return print(100*total_votes / base);
5256
};

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "avCommon",
3-
"version" : "17.04",
3+
"version" : "103111.1",
44
"main": "index.html",
55
"ignore": [
66
"tests",

0 commit comments

Comments
 (0)