Skip to content

Commit fff655c

Browse files
authored
Census query (#89)
* initial work on census query * rebuild
1 parent b92627a commit fff655c

File tree

6 files changed

+195
-38
lines changed

6 files changed

+195
-38
lines changed

avRegistration/auth-method-service.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ angular.module('avRegistration')
265265
return $http.post(backendUrl + 'auth-event/'+eid+'/authenticate/', data);
266266
};
267267

268+
authmethod.censusQuery = function(data, authevent) {
269+
var eid = authevent || authId;
270+
delete data['authevent'];
271+
return $http.post(backendUrl + 'auth-event/'+eid+'/census/public-query/', data);
272+
};
273+
268274
authmethod.resendAuthCode = function(data, eid) {
269275
return $http.post(backendUrl + 'auth-event/'+eid+'/resend_auth_code/', data);
270276
};
@@ -391,6 +397,20 @@ angular.module('avRegistration')
391397
return fields;
392398
};
393399

400+
authmethod.getCensusQueryFields = function (viewEventData)
401+
{
402+
var fields = angular.copy(viewEventData.extra_fields);
403+
404+
fields = _.filter(
405+
fields,
406+
function (field) {
407+
return field.required_on_authentication;
408+
}
409+
);
410+
411+
return fields;
412+
};
413+
394414
authmethod.getLoginFields = function (viewEventData) {
395415
var fields = authmethod.getRegisterFields(viewEventData);
396416
if (viewEventData.auth_method === "sms" || viewEventData.auth_method === "email")

avRegistration/login-directive/login-directive.html

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
<div class="container-fluid">
22
<div class="row">
33
<div class="col-sm-12 loginheader">
4-
<h2 class="tex-center" ng-i18next="[i18next]({name: orgName})avRegistration.loginHeader"></h2>
4+
<h2
5+
class="tex-center"
6+
ng-if="!isCensusQuery"
7+
ng-i18next="[i18next]({name: orgName})avRegistration.loginHeader">
8+
</h2>
9+
<h2
10+
class="tex-center"
11+
ng-if="!!isCensusQuery"
12+
ng-i18next="avRegistration.censusQueryHeader">
13+
</h2>
514
</div>
615

716
<div class="col-sm-6">
817
<form name="form" id="loginForm" role="form" class="form-horizontal">
9-
<div ng-repeat="field in login_fields" avr-field index="{{$index+1}}" ng-if="field.steps === undefined || field.steps.indexOf(currentFormStep) !== -1">
18+
<div
19+
ng-repeat="field in login_fields"
20+
avr-field
21+
index="{{$index+1}}"
22+
ng-if="field.steps === undefined || field.steps.indexOf(currentFormStep) !== -1">
1023
</div>
1124

1225
<div class="col-sm-offset-4 col-sm-8 button-group">
13-
<div class="input-error">
26+
<div class="input-error" ng-if="!isCensusQuery">
1427
<div class="error text-danger" ng-if="error">{{ error }}</div>
1528
</div>
1629
<div class="input-warn">
@@ -21,24 +34,74 @@ <h2 class="tex-center" ng-i18next="[i18next]({name: orgName})avRegistration.logi
2134
avRegistration.fillValidFormText
2235
</span>
2336
</div>
37+
<div
38+
class="input-info"
39+
ng-if="isCensusQuery && censusQuery == 'querying'">
40+
<div
41+
class="text-info"
42+
ng-i18next="avRegistration.censusQuerying">
43+
</div>
44+
</div>
45+
<div
46+
class="input-success"
47+
ng-if="isCensusQuery && censusQuery == 'success'">
48+
<div
49+
class="success text-success"
50+
ng-i18next="avRegistration.censusSuccess">
51+
</div>
52+
</div>
53+
<div
54+
class="input-success"
55+
ng-if="isCensusQuery && censusQuery == 'fail'">
56+
<div
57+
class="error text-danger"
58+
ng-i18next="avRegistration.censusFail">
59+
</div>
60+
</div>
2461
<button
2562
type="submit"
2663
class="btn btn-block btn-success"
64+
ng-if="!isCensusQuery"
2765
ng-i18next="avRegistration.loginButton"
2866
ng-click="loginUser(form.$valid)"
2967
tabindex="{{login_fields.length+1}}"
3068
ng-disabled="!form.$valid || sendingData">
3169
</button>
70+
<button
71+
type="submit"
72+
class="btn btn-block btn-success"
73+
ng-if="!!isCensusQuery"
74+
ng-i18next="avRegistration.checkCensusButton"
75+
ng-click="checkCensus(form.$valid)"
76+
tabindex="{{login_fields.length+1}}"
77+
ng-disabled="!form.$valid || sendingData">
78+
</button>
3279
</div>
3380
</form>
3481
</div>
3582
<div
3683
class="col-sm-5 col-sm-offset-1 hidden-xs"
37-
ng-if="registrationAllowed">
38-
<h3 class="help-h3" ng-i18next="avRegistration.notRegisteredYet"></h3>
84+
ng-if="registrationAllowed && !isCensusQuery">
85+
<h3
86+
class="help-h3"
87+
ng-i18next="avRegistration.notRegisteredYet">
88+
</h3>
3989
<p>
40-
<a ng-if="!isAdmin" href="#/election/{{election.id}}/public/register" ng-i18next="avRegistration.registerHere" ng-click="goSignup()" tabindex="{{login_fields.length+2}}"></a><br/>
41-
<a ng-if="isAdmin" href="{{ signupLink }}" ng-i18next="avRegistration.registerHere" tabindex="{{login_fields.length+2}}"></a><br/>
90+
<a
91+
ng-if="!isAdmin"
92+
href="#/election/{{election.id}}/public/register"
93+
ng-i18next="avRegistration.registerHere"
94+
ng-click="goSignup()"
95+
tabindex="{{login_fields.length+2}}">
96+
</a>
97+
<br/>
98+
<a
99+
ng-if="isAdmin"
100+
href="{{ signupLink }}"
101+
ng-i18next="avRegistration.registerHere"
102+
tabindex="{{login_fields.length+2}}">
103+
</a>
104+
<br/>
42105
<span ng-i18next="avRegistration.fewMinutes"></span>
43106
</p>
44107
</div>

avRegistration/login-directive/login-directive.js

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,25 @@
1616
**/
1717

1818
angular.module('avRegistration')
19-
.directive('avLogin', function(Authmethod,
20-
StateDataService,
21-
$parse,
22-
$state,
23-
$location,
24-
$cookies,
25-
$i18next,
26-
$window,
27-
$timeout,
28-
ConfigService,
29-
Patterns) {
30-
// we use it as something similar to a controller here
31-
function link(scope, element, attrs) {
19+
.directive(
20+
'avLogin',
21+
function(
22+
Authmethod,
23+
StateDataService,
24+
$parse,
25+
$state,
26+
$location,
27+
$cookies,
28+
$i18next,
29+
$window,
30+
$timeout,
31+
ConfigService,
32+
Patterns)
33+
{
34+
// we use it as something similar to a controller here
35+
function link(scope, element, attrs)
36+
{
37+
scope.isCensusQuery = attrs.isCensusQuery;
3238
var adminId = ConfigService.freeAuthId + '';
3339
var autheventid = attrs.eventId;
3440
scope.orgName = ConfigService.organization.orgName;
@@ -46,8 +52,9 @@ angular.module('avRegistration')
4652
scope.stateData = StateDataService.getData();
4753

4854
scope.signupLink = ConfigService.signupLink;
49-
55+
5056
scope.allowUserResend = false;
57+
scope.censusQuery = "not-sent";
5158

5259
scope.code = null;
5360
if (attrs.code && attrs.code.length > 0) {
@@ -62,15 +69,15 @@ angular.module('avRegistration')
6269
if (autheventid === adminId) {
6370
scope.isAdmin = true;
6471
}
65-
72+
6673
function isValidTel(inputName) {
6774
if (!document.getElementById(inputName)) {
6875
return false;
6976
}
7077
var telInput = angular.element(document.getElementById(inputName));
7178
return telInput.intlTelInput("isValidNumber");
7279
}
73-
80+
7481
function isValidEmail(email) {
7582
var pattern = Patterns.get('email');
7683
return null !== email.match(pattern);
@@ -135,6 +142,36 @@ angular.module('avRegistration')
135142
scope.sendingData = false;
136143
};
137144

145+
scope.checkCensus = function(valid) {
146+
if (!valid) {
147+
return;
148+
}
149+
150+
if (scope.sendingData) {
151+
return;
152+
}
153+
scope.censusQuery = "querying";
154+
155+
var data = {
156+
'captcha_code': Authmethod.captcha_code,
157+
};
158+
_.each(scope.login_fields, function (field) {
159+
data[field.name] = field.value;
160+
});
161+
162+
scope.sendingData = true;
163+
Authmethod.censusQuery(data, autheventid)
164+
.success(function(rcvData) {
165+
scope.sendingData = false;
166+
scope.censusQueryData = rcvData;
167+
scope.censusQuery = "success";
168+
})
169+
.error(function(error) {
170+
scope.sendingData = false;
171+
scope.censusQuery = "fail";
172+
});
173+
};
174+
138175
scope.loginUser = function(valid) {
139176
if (!valid) {
140177
return;
@@ -214,7 +251,11 @@ angular.module('avRegistration')
214251
scope.method = authevent['auth_method'];
215252
scope.name = authevent['name'];
216253
scope.registrationAllowed = (authevent['census'] === 'open');
217-
scope.login_fields = Authmethod.getLoginFields(authevent);
254+
if (!scope.isCensusQuery) {
255+
scope.login_fields = Authmethod.getLoginFields(authevent);
256+
} else {
257+
scope.login_fields = Authmethod.getCensusQueryFields(authevent);
258+
}
218259
scope.telIndex = -1;
219260
scope.emailIndex = -1;
220261
scope.telField = null;
@@ -227,7 +268,7 @@ angular.module('avRegistration')
227268
if (_.isArray(adminMatch)) {
228269
ret = true;
229270
} else if (_.isArray(electionsMatch) && 3 === electionsMatch.length) {
230-
ret = (_.isObject(authevent.auth_method_config) &&
271+
ret = (_.isObject(authevent.auth_method_config) &&
231272
_.isObject(authevent.auth_method_config.config) &&
232273
true === authevent.auth_method_config.config.allow_user_resend);
233274
}

0 commit comments

Comments
 (0)