wait for service config load to redirect to oidc provider

This commit is contained in:
viehlieb 2022-07-08 15:09:39 +02:00
parent 05a98fa88b
commit ee254cb9c8
2 changed files with 45 additions and 57 deletions

View file

@ -21,7 +21,7 @@ const validator = {
// let isSettingDatabaseFctCallDone = false;
Template.userFormsLayout.onCreated(function() {
Template.userFormsLayout.onCreated(function () {
const templateInstance = this;
templateInstance.currentSetting = new ReactiveVar();
templateInstance.isLoading = new ReactiveVar(false);
@ -37,7 +37,7 @@ Template.userFormsLayout.onCreated(function() {
}
// isSettingDatabaseFctCallDone = true;
if(currSetting && currSetting !== undefined && currSetting.customLoginLogoImageUrl !== undefined)
if (currSetting && currSetting !== undefined && currSetting.customLoginLogoImageUrl !== undefined)
document.getElementById("isSettingDatabaseCallDone").style.display = 'none';
else
document.getElementById("isSettingDatabaseCallDone").style.display = 'block';
@ -50,36 +50,19 @@ Template.userFormsLayout.onCreated(function() {
}
});
if(!Meteor.user()?.profile)
{
Meteor.call('isOidcRedirectionEnabled', (_, result) => {
serviceName = 'oidc';
if (result)
{
methodName = "loginWithOidc";
var loginWithService = Meteor[methodName];
AccountsTemplates.options.socialLoginStyle = 'redirect';
options = {
loginStyle: AccountsTemplates.options.socialLoginStyle,
};
loginWithService(options, function(err) {
AccountsTemplates.setDisabled(false);
if (err && err instanceof Accounts.LoginCancelledError)
{
}
else if (err && err instanceof ServiceConfiguration.ConfigError)
{
if (Accounts._loginButtonsSession) return Accounts._loginButtonsSession.configureService('oidc');
}
else
{
AccountsTemplates.submitCallback(err, state);
}
});
}
else console.log("oidc redirect not set");
});
if (!Meteor.user()?.profile) {
Meteor.call('isOidcRedirectionEnabled', (_, result) => {
serviceName = 'oidc';
if (result) {
AccountsTemplates.options.socialLoginStyle = 'redirect';
options = {
loginStyle: AccountsTemplates.options.socialLoginStyle,
};
console.log('options :',JSON.stringify(options,null,2));
Meteor.loginWithOidc(options);
}
else console.log("oidc redirect not set");
});
}
Meteor.call('isDisableRegistration', (_, result) => {
if (result) {
@ -112,22 +95,22 @@ Template.userFormsLayout.helpers({
// return isSettingDatabaseFctCallDone;
// },
isLegalNoticeLinkExist(){
isLegalNoticeLinkExist() {
const currSet = Template.instance().currentSetting.get();
if(currSet && currSet !== undefined && currSet != null){
if (currSet && currSet !== undefined && currSet != null) {
return currSet.legalNotice !== undefined && currSet.legalNotice.trim() != "";
}
else
return false;
},
getLegalNoticeWithWritTraduction(){
getLegalNoticeWithWritTraduction() {
let spanLegalNoticeElt = $("#legalNoticeSpan");
if(spanLegalNoticeElt != null && spanLegalNoticeElt != undefined){
if (spanLegalNoticeElt != null && spanLegalNoticeElt != undefined) {
spanLegalNoticeElt.html(TAPi18n.__('acceptance_of_our_legalNotice', {}));
}
let atLinkLegalNoticeElt = $("#legalNoticeAtLink");
if(atLinkLegalNoticeElt != null && atLinkLegalNoticeElt != undefined){
if (atLinkLegalNoticeElt != null && atLinkLegalNoticeElt != undefined) {
atLinkLegalNoticeElt.html(TAPi18n.__('legalNotice', {}));
}
return true;
@ -178,41 +161,41 @@ Template.userFormsLayout.events({
}
isCheckDone = false;
},
'click #at-signUp'(event, templateInstance){
'click #at-signUp'(event, templateInstance) {
isCheckDone = false;
},
'DOMSubtreeModified #at-oidc'(event){
if(alreadyCheck <= 2){
'DOMSubtreeModified #at-oidc'(event) {
if (alreadyCheck <= 2) {
let currSetting = Settings.findOne();
let oidcBtnElt = $("#at-oidc");
if(currSetting && currSetting !== undefined && currSetting.oidcBtnText !== undefined && oidcBtnElt != null && oidcBtnElt != undefined){
if (currSetting && currSetting !== undefined && currSetting.oidcBtnText !== undefined && oidcBtnElt != null && oidcBtnElt != undefined) {
let htmlvalue = "<i class='fa fa-oidc'></i>" + currSetting.oidcBtnText;
if(alreadyCheck == 1){
if (alreadyCheck == 1) {
alreadyCheck++;
oidcBtnElt.html("");
}
else{
else {
alreadyCheck++;
oidcBtnElt.html(htmlvalue);
}
}
}
else{
else {
alreadyCheck = 1;
}
},
'DOMSubtreeModified .at-form'(event){
if(alreadyCheck <= 2 && !isCheckDone){
if(document.getElementById("at-oidc") != null){
'DOMSubtreeModified .at-form'(event) {
if (alreadyCheck <= 2 && !isCheckDone) {
if (document.getElementById("at-oidc") != null) {
let currSetting = Settings.findOne();
let oidcBtnElt = $("#at-oidc");
if(currSetting && currSetting !== undefined && currSetting.oidcBtnText !== undefined && oidcBtnElt != null && oidcBtnElt != undefined){
if (currSetting && currSetting !== undefined && currSetting.oidcBtnText !== undefined && oidcBtnElt != null && oidcBtnElt != undefined) {
let htmlvalue = "<i class='fa fa-oidc'></i>" + currSetting.oidcBtnText;
if(alreadyCheck == 1){
if (alreadyCheck == 1) {
alreadyCheck++;
oidcBtnElt.html("");
}
else{
else {
alreadyCheck++;
isCheckDone = true;
oidcBtnElt.html(htmlvalue);
@ -220,7 +203,7 @@ Template.userFormsLayout.events({
}
}
}
else{
else {
alreadyCheck = 1;
}
},
@ -252,7 +235,7 @@ async function authentication(event, templateInstance) {
switch (result) {
case 'ldap':
return new Promise(resolve => {
Meteor.loginWithLDAP(match, password, function() {
Meteor.loginWithLDAP(match, password, function () {
resolve(FlowRouter.go('/'));
});
});
@ -264,7 +247,7 @@ async function authentication(event, templateInstance) {
{
provider,
},
function() {
function () {
resolve(FlowRouter.go('/'));
},
);
@ -272,7 +255,7 @@ async function authentication(event, templateInstance) {
case 'cas':
return new Promise(resolve => {
Meteor.loginWithCas(match, password, function() {
Meteor.loginWithCas(match, password, function () {
resolve(FlowRouter.go('/'));
});
});
@ -298,7 +281,6 @@ function getUserAuthenticationMethod(defaultAuthenticationMethod, match) {
Meteor.subscribe('user-authenticationMethod', match, {
onReady() {
const user = Users.findOne();
const authenticationMethod = user
? user.authenticationMethod
: defaultAuthenticationMethod;

View file

@ -229,6 +229,12 @@ if (Meteor.isServer) {
]);
}
function loadOidcConfig(){
config = ServiceConfiguration.configurations.findOne({service: 'oidc'});
configKeys = Object.keys(config);
return Object.keys(config).length > 0;
}
function sendInvitationEmail(_id) {
const icode = InvitationCodes.findOne(_id);
const author = Users.findOne(Meteor.userId());
@ -509,8 +515,8 @@ if (Meteor.isServer) {
return process.env.PASSWORD_LOGIN_ENABLED === 'false';
},
isOidcRedirectionEnabled(){
return process.env.OIDC_REDIRECTION_ENABLED === 'true';
},
return process.env.OIDC_REDIRECTION_ENABLED === 'true' && loadOidcConfig();
}
});
}