Skip to content

Census query #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions avRegistration/auth-method-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ angular.module('avRegistration')
return $http.post(backendUrl + 'auth-event/'+eid+'/authenticate/', data);
};

authmethod.censusQuery = function(data, authevent) {
var eid = authevent || authId;
delete data['authevent'];
return $http.post(backendUrl + 'auth-event/'+eid+'/census/public-query/', data);
};

authmethod.resendAuthCode = function(data, eid) {
return $http.post(backendUrl + 'auth-event/'+eid+'/resend_auth_code/', data);
};
Expand Down Expand Up @@ -391,6 +397,20 @@ angular.module('avRegistration')
return fields;
};

authmethod.getCensusQueryFields = function (viewEventData)
{
var fields = angular.copy(viewEventData.extra_fields);

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

return fields;
};

authmethod.getLoginFields = function (viewEventData) {
var fields = authmethod.getRegisterFields(viewEventData);
if (viewEventData.auth_method === "sms" || viewEventData.auth_method === "email")
Expand Down
77 changes: 70 additions & 7 deletions avRegistration/login-directive/login-directive.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
<div class="container-fluid">
<div class="row">
<div class="col-sm-12 loginheader">
<h2 class="tex-center" ng-i18next="[i18next]({name: orgName})avRegistration.loginHeader"></h2>
<h2
class="tex-center"
ng-if="!isCensusQuery"
ng-i18next="[i18next]({name: orgName})avRegistration.loginHeader">
</h2>
<h2
class="tex-center"
ng-if="!!isCensusQuery"
ng-i18next="avRegistration.censusQueryHeader">
</h2>
</div>

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

<div class="col-sm-offset-4 col-sm-8 button-group">
<div class="input-error">
<div class="input-error" ng-if="!isCensusQuery">
<div class="error text-danger" ng-if="error">{{ error }}</div>
</div>
<div class="input-warn">
Expand All @@ -21,24 +34,74 @@ <h2 class="tex-center" ng-i18next="[i18next]({name: orgName})avRegistration.logi
avRegistration.fillValidFormText
</span>
</div>
<div
class="input-info"
ng-if="isCensusQuery && censusQuery == 'querying'">
<div
class="text-info"
ng-i18next="avRegistration.censusQuerying">
</div>
</div>
<div
class="input-success"
ng-if="isCensusQuery && censusQuery == 'success'">
<div
class="success text-success"
ng-i18next="avRegistration.censusSuccess">
</div>
</div>
<div
class="input-success"
ng-if="isCensusQuery && censusQuery == 'fail'">
<div
class="error text-danger"
ng-i18next="avRegistration.censusFail">
</div>
</div>
<button
type="submit"
class="btn btn-block btn-success"
ng-if="!isCensusQuery"
ng-i18next="avRegistration.loginButton"
ng-click="loginUser(form.$valid)"
tabindex="{{login_fields.length+1}}"
ng-disabled="!form.$valid || sendingData">
</button>
<button
type="submit"
class="btn btn-block btn-success"
ng-if="!!isCensusQuery"
ng-i18next="avRegistration.checkCensusButton"
ng-click="checkCensus(form.$valid)"
tabindex="{{login_fields.length+1}}"
ng-disabled="!form.$valid || sendingData">
</button>
</div>
</form>
</div>
<div
class="col-sm-5 col-sm-offset-1 hidden-xs"
ng-if="registrationAllowed">
<h3 class="help-h3" ng-i18next="avRegistration.notRegisteredYet"></h3>
ng-if="registrationAllowed && !isCensusQuery">
<h3
class="help-h3"
ng-i18next="avRegistration.notRegisteredYet">
</h3>
<p>
<a ng-if="!isAdmin" href="#/election/{{election.id}}/public/register" ng-i18next="avRegistration.registerHere" ng-click="goSignup()" tabindex="{{login_fields.length+2}}"></a><br/>
<a ng-if="isAdmin" href="{{ signupLink }}" ng-i18next="avRegistration.registerHere" tabindex="{{login_fields.length+2}}"></a><br/>
<a
ng-if="!isAdmin"
href="#/election/{{election.id}}/public/register"
ng-i18next="avRegistration.registerHere"
ng-click="goSignup()"
tabindex="{{login_fields.length+2}}">
</a>
<br/>
<a
ng-if="isAdmin"
href="{{ signupLink }}"
ng-i18next="avRegistration.registerHere"
tabindex="{{login_fields.length+2}}">
</a>
<br/>
<span ng-i18next="avRegistration.fewMinutes"></span>
</p>
</div>
Expand Down
77 changes: 59 additions & 18 deletions avRegistration/login-directive/login-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,25 @@
**/

angular.module('avRegistration')
.directive('avLogin', function(Authmethod,
StateDataService,
$parse,
$state,
$location,
$cookies,
$i18next,
$window,
$timeout,
ConfigService,
Patterns) {
// we use it as something similar to a controller here
function link(scope, element, attrs) {
.directive(
'avLogin',
function(
Authmethod,
StateDataService,
$parse,
$state,
$location,
$cookies,
$i18next,
$window,
$timeout,
ConfigService,
Patterns)
{
// we use it as something similar to a controller here
function link(scope, element, attrs)
{
scope.isCensusQuery = attrs.isCensusQuery;
var adminId = ConfigService.freeAuthId + '';
var autheventid = attrs.eventId;
scope.orgName = ConfigService.organization.orgName;
Expand All @@ -46,8 +52,9 @@ angular.module('avRegistration')
scope.stateData = StateDataService.getData();

scope.signupLink = ConfigService.signupLink;

scope.allowUserResend = false;
scope.censusQuery = "not-sent";

scope.code = null;
if (attrs.code && attrs.code.length > 0) {
Expand All @@ -62,15 +69,15 @@ angular.module('avRegistration')
if (autheventid === adminId) {
scope.isAdmin = true;
}

function isValidTel(inputName) {
if (!document.getElementById(inputName)) {
return false;
}
var telInput = angular.element(document.getElementById(inputName));
return telInput.intlTelInput("isValidNumber");
}

function isValidEmail(email) {
var pattern = Patterns.get('email');
return null !== email.match(pattern);
Expand Down Expand Up @@ -135,6 +142,36 @@ angular.module('avRegistration')
scope.sendingData = false;
};

scope.checkCensus = function(valid) {
if (!valid) {
return;
}

if (scope.sendingData) {
return;
}
scope.censusQuery = "querying";

var data = {
'captcha_code': Authmethod.captcha_code,
};
_.each(scope.login_fields, function (field) {
data[field.name] = field.value;
});

scope.sendingData = true;
Authmethod.censusQuery(data, autheventid)
.success(function(rcvData) {
scope.sendingData = false;
scope.censusQueryData = rcvData;
scope.censusQuery = "success";
})
.error(function(error) {
scope.sendingData = false;
scope.censusQuery = "fail";
});
};

scope.loginUser = function(valid) {
if (!valid) {
return;
Expand Down Expand Up @@ -214,7 +251,11 @@ angular.module('avRegistration')
scope.method = authevent['auth_method'];
scope.name = authevent['name'];
scope.registrationAllowed = (authevent['census'] === 'open');
scope.login_fields = Authmethod.getLoginFields(authevent);
if (!scope.isCensusQuery) {
scope.login_fields = Authmethod.getLoginFields(authevent);
} else {
scope.login_fields = Authmethod.getCensusQueryFields(authevent);
}
scope.telIndex = -1;
scope.emailIndex = -1;
scope.telField = null;
Expand All @@ -227,7 +268,7 @@ angular.module('avRegistration')
if (_.isArray(adminMatch)) {
ret = true;
} else if (_.isArray(electionsMatch) && 3 === electionsMatch.length) {
ret = (_.isObject(authevent.auth_method_config) &&
ret = (_.isObject(authevent.auth_method_config) &&
_.isObject(authevent.auth_method_config.config) &&
true === authevent.auth_method_config.config.allow_user_resend);
}
Expand Down
Loading