Skip to content

Commit

Permalink
initial support for login with admin generated auth code (#152)
Browse files Browse the repository at this point in the history
* initial support for login with admin generated auth code

* setting username from url

* do not allow resend auth-code in authenticate-with-admin-code mode

* beautifying app code
  • Loading branch information
edulix authored Oct 1, 2021
1 parent 3469b51 commit 06b3947
Show file tree
Hide file tree
Showing 6 changed files with 4,626 additions and 1,300 deletions.
30 changes: 30 additions & 0 deletions avRegistration/auth-method-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ angular.module('avRegistration')
return $http.post(url, params);
};

/**
* @returns the http request
*/
authmethod.obtainVoterAuthCode = function (electionId, username)
{
var params = {username: username};
var url = backendUrl + 'auth-event/' + electionId + '/generate-auth-code/';

return $http.post(url, params);
};

/**
* @returns the http request
*/
Expand Down Expand Up @@ -368,6 +379,25 @@ angular.module('avRegistration')
return fields;
};

authmethod.getLoginWithCode = function (_viewEventData) {
return [
{
"name": "__username",
"type": "text",
"required": true,
"min": 3,
"max": 200,
"required_on_authentication": true
},
{
"name": "code",
"type": "code",
"required": true,
"required_on_authentication": true
}
];
};

authmethod.getLoginFields = function (viewEventData) {
var fields = authmethod.getRegisterFields(
viewEventData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
class="form-group"
ng-class="{'has-error': fieldForm.input.$dirty && fieldForm.input.$invalid}">
<label for="input{{index}}" class="control-label col-sm-4">
<span ng-if="field.name == 'username'" ng-i18next="avRegistration.usernameLabel"></span>
<span ng-if="field.name != 'username'">{{field.name}}</span>
<span
ng-if="field.name == 'username' || field.name == '__username'"
ng-i18next="avRegistration.usernameLabel"
></span>
<span
ng-if="field.name != 'username' && field.name != '__username'"
>
{{field.name}}
</span>
</label>
<div class="col-sm-8">
<input
Expand Down
5 changes: 4 additions & 1 deletion avRegistration/login-controller/login-controller.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
event-id="{{event_id}}"
code="{{code}}"
email="{{email}}"
ng-if="!isOpenId">
with-code="{{withCode}}"
username="{{username}}"
ng-if="!isOpenId"
>
</div>
<div
av-openid-connect
Expand Down
12 changes: 4 additions & 8 deletions avRegistration/login-controller/login-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@ angular.module('avRegistration')
'LoginController',
function(
$scope,
$stateParams,
$filter,
$i18next,
$cookies,
$window,
ConfigService,
Authmethod)
{
$stateParams
) {
$scope.event_id = $stateParams.id;
$scope.code = $stateParams.code;
$scope.email = $stateParams.email;
$scope.username = $stateParams.username;
$scope.isOpenId = $stateParams.isOpenId;
$scope.withCode = $stateParams.withCode;
}
);
14 changes: 12 additions & 2 deletions avRegistration/login-directive/login-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ angular.module('avRegistration')
function link(scope, element, attrs)
{
scope.isCensusQuery = attrs.isCensusQuery;
scope.withCode = attrs.withCode;
scope.username = attrs.username;
scope.error = null;

// by default
Expand Down Expand Up @@ -372,16 +374,21 @@ angular.module('avRegistration')
(authevent['census'] === 'open') &&
(autheventid !== adminId || ConfigService.allowAdminRegistration)
);
if (!scope.isCensusQuery) {
if (!scope.isCensusQuery && !scope.withCode) {
scope.login_fields = Authmethod.getLoginFields(authevent);
} else {
} else if (scope.withCode) {
scope.login_fields = Authmethod.getLoginWithCode(authevent);
} else { // scope.isCensusQuery is true
scope.login_fields = Authmethod.getCensusQueryFields(authevent);
}
scope.hide_default_login_lookup_field = authevent.hide_default_login_lookup_field;
scope.telIndex = -1;
scope.emailIndex = -1;
scope.telField = null;
scope.allowUserResend = (function () {
if (scope.withCode) {
return false;
}
var ret = false;
var href = $location.path();
var adminMatch = href.match(/^\/admin\//);
Expand Down Expand Up @@ -434,6 +441,9 @@ angular.module('avRegistration')
}
scope.telIndex = index+1;
scope.telField = el;
} else if (el.name === '__username' && scope.withCode) {
el.value = scope.username;
el.disabled = true;
}
return el;
});
Expand Down
Loading

0 comments on commit 06b3947

Please sign in to comment.