Skip to content

Commit

Permalink
🐞 OIDC automatically authentication with no clicking (#383)
Browse files Browse the repository at this point in the history
Parent issue: sequentech/meta#681
  • Loading branch information
edulix authored Mar 13, 2024
1 parent 4007fc8 commit 93bd8f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion avRegistration/login-directive/login-directive.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<section class="container-login" ng-if="!isOpenId" aria-labelledby="login-header-text">
<section class="container-login" aria-labelledby="login-header-text">
<div class="row">
<div class="col-sm-12 loginheader">
<h3
Expand Down
6 changes: 6 additions & 0 deletions avRegistration/login-directive/login-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,11 @@ angular.module('avRegistration')
var authevent = angular.copy(scope.base_authevent);
if (altAuthMethod === null) {
scope.current_alt_auth_method_id = null;
// isOpenId connect is only automatically set in the redirect view
// so we need to set it here
scope.isOpenId = (
scope.isOpenId || authevent.auth_method === 'openid-connect'
);
scope.apply(authevent);
return;
}
Expand Down Expand Up @@ -1012,6 +1017,7 @@ angular.module('avRegistration')
// if all fields all filled in and it's not OpenID Connect do
// auto-login
if (
!scope.isOpenId &&
!scope.isOtl &&
!scope.isCensusQuery &&
!scope.withCode &&
Expand Down
7 changes: 4 additions & 3 deletions dist/appCommon-v10.2.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,8 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist
return altAuthMethod.public_name_i18n && altAuthMethod.public_name_i18n[langCode] ? altAuthMethod.public_name_i18n[langCode] : altAuthMethod.public_name;
}, scope.setCurrentAltAuthMethod = function(altAuthMethod) {
var authevent = angular.copy(scope.base_authevent);
if (null === altAuthMethod) return scope.current_alt_auth_method_id = null, void scope.apply(authevent);
if (null === altAuthMethod) return scope.current_alt_auth_method_id = null, scope.isOpenId = scope.isOpenId || "openid-connect" === authevent.auth_method,
void scope.apply(authevent);
altAuthMethod.id !== scope.current_alt_auth_method_id && ("smart-link" !== scope.selectedAltMethod && "smart-link" === altAuthMethod.auth_method_name || (scope.current_alt_auth_method_id = altAuthMethod.id,
authevent.extra_fields = altAuthMethod.extra_fields, authevent.auth_method_config = altAuthMethod.auth_method_config,
authevent.auth_method = altAuthMethod.auth_method_name, scope.apply(authevent)));
Expand Down Expand Up @@ -698,7 +699,7 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist
filledFields = _.filter(filledFields, function(el) {
return null !== el.value || "otp-code" === el.type;
});
!scope.isOpenId && filledFields.length !== scope.login_fields.length || scope.isOtl || scope.isCensusQuery || scope.withCode || scope.oidcError || scope.loginUser(!0);
!scope.isOpenId && filledFields.length !== scope.login_fields.length || scope.isOpenId || scope.isOtl || scope.isCensusQuery || scope.withCode || scope.oidcError || scope.loginUser(!0);
}, scope.view = function(id) {
Authmethod.viewEvent(id).then(function(altAuthMethod) {
"ok" === altAuthMethod.data.status ? (scope.base_authevent = angular.copy(altAuthMethod.data.events),
Expand Down Expand Up @@ -1784,7 +1785,7 @@ angular.module("avTest", []), angular.module("avTest").controller("UnitTestE2ECo
$templateCache.put("avRegistration/fields/textarea-field-directive/textarea-field-directive.html", '<div class="form-group"><div class="col-sm-offset-2 col-sm-10"><textarea aria-label="{{index}}Text" id="{{index}}Text" rows="5" cols="60" tabindex="0" readonly>{{field.name}}</textarea><p class="help-block" ng-if="field.help || field.help_i18n" ng-bind-html="field | customI18n : \'help\' | addTargetBlank"></p></div></div>'),
$templateCache.put("avRegistration/loading.html", '<div avb-busy><p ng-i18next="avRegistration.loadingRegistration"></p></div>'),
$templateCache.put("avRegistration/login-controller/login-controller.html", '<div class="col-xs-12 login-controller"><div class="pad"><div av-login event-id="{{event_id}}" code="{{code}}" email="{{email}}" with-code="{{withCode}}" username="{{username}}" is-otl="{{isOtl}}" is-open-id="{{isOpenId}}" otl-secret="{{otlSecret}}" with-alt-method="{{withAltMethod}}" selected-alt-method="{{selectedAltMethod}}"></div></div></div>'),
$templateCache.put("avRegistration/login-directive/login-directive.html", '<section class="container-login" ng-if="!isOpenId" aria-labelledby="login-header-text"><div class="row"><div class="col-sm-12 loginheader"><h3 class="tex-center login-header-text" id="login-header-text" ng-if="!isAdmin && !isOtl && !isCensusQuery" ng-i18next="[i18next]({name: orgName})avRegistration.loginHeader"></h3><h3 class="tex-center login-header-text" id="login-header-text" ng-if="isAdmin && !isOtl" ng-i18next="[i18next]avRegistration.adminLoginHeader"></h3><h3 class="tex-center login-header-text" id="login-header-text" ng-if="!!isCensusQuery" ng-i18next="avRegistration.censusQueryHeader"></h3><h3 class="tex-center login-header-text" id="login-header-text" ng-if="isOtl" ng-i18next="avRegistration.otlHeader"></h3><div class="text-success" ng-if="!!successfulRegistration" ng-i18next="[html:i18next]avRegistration.loginAfterRegistration"></div></div>\x3c!-- Shows the alternative auth method tabs in case there\'s any --\x3e<div class="col-sm-12 alternative-auth-methods-tabs" ng-if="alternative_auth_methods"><ul class="nav nav-tabs"><li class="default-auth-method" ng-class="{\'active\': current_alt_auth_method_id == null}"><a ng-click="setCurrentAltAuthMethod(null)"><i class="fa fa-user"></i> <span ng-i18next="avRegistration.defaultAuthMethod"></span></a></li>\x3c!-- we disable click for smart-link unless it comes from a smart-link,\n because it doesn\'t work --\x3e<li ng-repeat="alt_auth_method in alternative_auth_methods" ng-class="{\'active\': current_alt_auth_method_id == alt_auth_method.id, \'disabled\': selectedAltMethod !== \'smart-link\' && alt_auth_method.auth_method_name === \'smart-link\'}"><a ng-click="setCurrentAltAuthMethod(alt_auth_method)"><i ng-if="alt_auth_method.icon" class="{{alt_auth_method.icon}}"></i> <span>{{getAltAuthMethodName(alt_auth_method)}}</span></a></li></ul></div><div class="col-sm-12" ng-if="method !== \'openid-connect\'"><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) && otlStatus !== \'success\'"></div><div class="button-group"><section class="input-error" ng-if="!isCensusQuery" aria-label="{{ \'avRegistration.loginError.errorLabel\' | i18next }}"><div class="error text-danger" role="alert" ng-if="error" ng-i18next>[html:i18next]({{errorData}}){{error}}</div></section><section class="input-warn" aria-label="{{ \'avRegistration.loginError.warningLabel\' | i18next }}"><div class="warn-box" ng-if="!form.$valid || sendingData"><span class="glyphicon glyphicon-warning-sign"></span><div role="alert" ng-i18next>avRegistration.fillValidFormText</div></div></section><button type="submit" class="btn btn-block btn-lg btn-success-action" ng-if="!isCensusQuery && !isOtl" ng-i18next="avRegistration.loginButton" ng-click="loginUser(form.$valid)" tabindex="0" ng-disabled="!form.$valid || sendingData"></button> <button type="submit" class="btn btn-block btn-lg btn-success-action" ng-if="isCensusQuery" ng-i18next="avRegistration.checkCensusButton" ng-click="checkCensus(form.$valid)" tabindex="0" ng-disabled="!form.$valid || sendingData"></button> <button type="submit" class="btn btn-block btn-lg btn-success-action" ng-if="isOtl && otlStatus !== \'success\'" ng-i18next="avRegistration.otlButton" ng-click="otlAuth(form.$valid)" tabindex="0" ng-disabled="!form.$valid || sendingData"></button><div class="otl-auth" ng-if="isOtl"><div class="input-info" ng-if="otlStatus == \'querying\'"><div class="text-info" ng-i18next="avRegistration.otlStatus.querying"></div></div><div class="input-success" ng-if="otlStatus == \'success\'"><div class="success text-success" ng-i18next="[html:i18next]({code: otpCode})avRegistration.otlStatus.success"></div></div><div class="input-success" ng-if="otlStatus == \'fail\'"><div class="error text-danger" role="alert" ng-i18next="[html]avRegistration.otlStatus.fail"></div></div></div><div class="census-query" ng-if="isCensusQuery"><div class="input-info census-query" ng-if="censusQuery == \'querying\'"><div class="text-info" ng-i18next="avRegistration.censusQuerying"></div></div><div class="input-success census-query" ng-if="censusQuery == \'success\'"><div class="success text-success" ng-i18next="[html]avRegistration.censusSuccess"></div></div><div class="input-success census-query" ng-if="censusQuery == \'fail\'"><div class="error text-danger" role="alert" ng-i18next="[html]avRegistration.censusFail"></div></div></div></div></form></div><div class="col-sm-5 col-sm-offset-1 hidden-xs not-registered-yet" ng-if="registrationAllowed && !isCensusQuery && method !== \'openid-connect\' && !isOtl"><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="0"></a><br><a ng-if="isAdmin" href="{{ signupLink }}" ng-i18next="avRegistration.registerHere" tabindex="0"></a><br><span ng-i18next="avRegistration.fewMinutes"></span></p></div><div class="col-sm-12 text-center oidc-section" ng-if="method === \'openid-connect\'"><p class="oidc-login-description" ng-i18next="[html]avRegistration.openidLoginDescription"></p><span ng-repeat="provider in current_oidc_providers" class="provider-span"><button ng-click="openidConnectAuth(provider)" alt="{{provider.public_info.description}}" tabindex="0" class="btn btn-block btn-lg btn-success-action provider-btn" ng-class="{[provider.public_info.id]: true}"><img ng-if="!!provider.public_info.icon" alt="{{provider.public_info.description}}" class="logo-img" ng-src="{{provider.public_info.icon}}"> {{provider.public_info.title}}</button></span><div class="button-group"><div class="input-error"><div class="error text-danger" role="alert" ng-if="error" ng-i18next>[html:i18next]({{errorData}}){{error}}</div></div></div></div></div></section>'),
$templateCache.put("avRegistration/login-directive/login-directive.html", '<section class="container-login" aria-labelledby="login-header-text"><div class="row"><div class="col-sm-12 loginheader"><h3 class="tex-center login-header-text" id="login-header-text" ng-if="!isAdmin && !isOtl && !isCensusQuery" ng-i18next="[i18next]({name: orgName})avRegistration.loginHeader"></h3><h3 class="tex-center login-header-text" id="login-header-text" ng-if="isAdmin && !isOtl" ng-i18next="[i18next]avRegistration.adminLoginHeader"></h3><h3 class="tex-center login-header-text" id="login-header-text" ng-if="!!isCensusQuery" ng-i18next="avRegistration.censusQueryHeader"></h3><h3 class="tex-center login-header-text" id="login-header-text" ng-if="isOtl" ng-i18next="avRegistration.otlHeader"></h3><div class="text-success" ng-if="!!successfulRegistration" ng-i18next="[html:i18next]avRegistration.loginAfterRegistration"></div></div>\x3c!-- Shows the alternative auth method tabs in case there\'s any --\x3e<div class="col-sm-12 alternative-auth-methods-tabs" ng-if="alternative_auth_methods"><ul class="nav nav-tabs"><li class="default-auth-method" ng-class="{\'active\': current_alt_auth_method_id == null}"><a ng-click="setCurrentAltAuthMethod(null)"><i class="fa fa-user"></i> <span ng-i18next="avRegistration.defaultAuthMethod"></span></a></li>\x3c!-- we disable click for smart-link unless it comes from a smart-link,\n because it doesn\'t work --\x3e<li ng-repeat="alt_auth_method in alternative_auth_methods" ng-class="{\'active\': current_alt_auth_method_id == alt_auth_method.id, \'disabled\': selectedAltMethod !== \'smart-link\' && alt_auth_method.auth_method_name === \'smart-link\'}"><a ng-click="setCurrentAltAuthMethod(alt_auth_method)"><i ng-if="alt_auth_method.icon" class="{{alt_auth_method.icon}}"></i> <span>{{getAltAuthMethodName(alt_auth_method)}}</span></a></li></ul></div><div class="col-sm-12" ng-if="method !== \'openid-connect\'"><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) && otlStatus !== \'success\'"></div><div class="button-group"><section class="input-error" ng-if="!isCensusQuery" aria-label="{{ \'avRegistration.loginError.errorLabel\' | i18next }}"><div class="error text-danger" role="alert" ng-if="error" ng-i18next>[html:i18next]({{errorData}}){{error}}</div></section><section class="input-warn" aria-label="{{ \'avRegistration.loginError.warningLabel\' | i18next }}"><div class="warn-box" ng-if="!form.$valid || sendingData"><span class="glyphicon glyphicon-warning-sign"></span><div role="alert" ng-i18next>avRegistration.fillValidFormText</div></div></section><button type="submit" class="btn btn-block btn-lg btn-success-action" ng-if="!isCensusQuery && !isOtl" ng-i18next="avRegistration.loginButton" ng-click="loginUser(form.$valid)" tabindex="0" ng-disabled="!form.$valid || sendingData"></button> <button type="submit" class="btn btn-block btn-lg btn-success-action" ng-if="isCensusQuery" ng-i18next="avRegistration.checkCensusButton" ng-click="checkCensus(form.$valid)" tabindex="0" ng-disabled="!form.$valid || sendingData"></button> <button type="submit" class="btn btn-block btn-lg btn-success-action" ng-if="isOtl && otlStatus !== \'success\'" ng-i18next="avRegistration.otlButton" ng-click="otlAuth(form.$valid)" tabindex="0" ng-disabled="!form.$valid || sendingData"></button><div class="otl-auth" ng-if="isOtl"><div class="input-info" ng-if="otlStatus == \'querying\'"><div class="text-info" ng-i18next="avRegistration.otlStatus.querying"></div></div><div class="input-success" ng-if="otlStatus == \'success\'"><div class="success text-success" ng-i18next="[html:i18next]({code: otpCode})avRegistration.otlStatus.success"></div></div><div class="input-success" ng-if="otlStatus == \'fail\'"><div class="error text-danger" role="alert" ng-i18next="[html]avRegistration.otlStatus.fail"></div></div></div><div class="census-query" ng-if="isCensusQuery"><div class="input-info census-query" ng-if="censusQuery == \'querying\'"><div class="text-info" ng-i18next="avRegistration.censusQuerying"></div></div><div class="input-success census-query" ng-if="censusQuery == \'success\'"><div class="success text-success" ng-i18next="[html]avRegistration.censusSuccess"></div></div><div class="input-success census-query" ng-if="censusQuery == \'fail\'"><div class="error text-danger" role="alert" ng-i18next="[html]avRegistration.censusFail"></div></div></div></div></form></div><div class="col-sm-5 col-sm-offset-1 hidden-xs not-registered-yet" ng-if="registrationAllowed && !isCensusQuery && method !== \'openid-connect\' && !isOtl"><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="0"></a><br><a ng-if="isAdmin" href="{{ signupLink }}" ng-i18next="avRegistration.registerHere" tabindex="0"></a><br><span ng-i18next="avRegistration.fewMinutes"></span></p></div><div class="col-sm-12 text-center oidc-section" ng-if="method === \'openid-connect\'"><p class="oidc-login-description" ng-i18next="[html]avRegistration.openidLoginDescription"></p><span ng-repeat="provider in current_oidc_providers" class="provider-span"><button ng-click="openidConnectAuth(provider)" alt="{{provider.public_info.description}}" tabindex="0" class="btn btn-block btn-lg btn-success-action provider-btn" ng-class="{[provider.public_info.id]: true}"><img ng-if="!!provider.public_info.icon" alt="{{provider.public_info.description}}" class="logo-img" ng-src="{{provider.public_info.icon}}"> {{provider.public_info.title}}</button></span><div class="button-group"><div class="input-error"><div class="error text-danger" role="alert" ng-if="error" ng-i18next>[html:i18next]({{errorData}}){{error}}</div></div></div></div></div></section>'),
$templateCache.put("avRegistration/register-controller/register-controller.html", '<div class="col-xs-12 top-section"><div class="pad"><div av-register event-id="{{event_id}}" code="{{code}}" email="{{email}}"></div></div></div>'),
$templateCache.put("avRegistration/register-directive/register-directive.html", '<div class="container"><div class="row"><div class="col-sm-12"><h2 ng-if="!admin" class="registerheader" ng-i18next="avRegistration.registerHeader"></h2><h2 ng-if="admin" class="registerheader" ng-i18next="avRegistration.registerAdminHeader"></h2></div></div><div class="row"><div class="col-sm-6"><div ng-if="method == \'dnie\'"><a type="submit" class="btn btn-block btn-success" ng-i18next="avRegistration.registerButton" ng-href="{{ dnieurl }}/"></a></div><form ng-if="method != \'dnie\'" name="form" id="registerForm" role="form" class="form-horizontal"><div ng-repeat="field in register_fields" avr-field index="{{$index+1}}"></div><div class="col-sm-12 button-group"><div class="input-error"><div class="error text-danger" role="alert" ng-if="error" ng-bind-html="error"></div></div><div class="input-warn"><span class="text-warning" ng-if="!form.$valid || sendingData" ng-i18next>avRegistration.fillValidFormText</span></div><button type="submit" class="btn btn-block btn-success" ng-i18next="avRegistration.registerButton" ng-click="signUp(form.$valid)" tabindex="0" ng-disabled="!form.$valid || sendingData"></button></div></form></div><div class="col-sm-5 col-sm-offset-1 help-sidebar hidden-xs"><span ng-if="admin"><h3 class="help-h3" ng-i18next="avRegistration.registerAdminFormHelpTitle"></h3><p ng-i18next>avRegistration.helpAdminRegisterForm</p></span><span><p ng-if="!admin" ng-i18next>avRegistration.helpRegisterForm</p><h3 class="help-h3" ng-i18next="avRegistration.alreadyRegistered"></h3><p ng-i18next>[html]avRegistration.helpAlreadyRegisteredForm</p><a href="" ng-click="goLogin($event)" ng-i18next="avRegistration.loginHere"></a><br></span></div></div></div>'),
$templateCache.put("avRegistration/success.html", '<div av-success><p ng-i18next="avRegistration.successRegistration"></p></div>'),
Expand Down

0 comments on commit 93bd8f0

Please sign in to comment.