diff --git a/htdocs/admin/oauth.php b/htdocs/admin/oauth.php index 038a07d5be3..a38afa8f769 100644 --- a/htdocs/admin/oauth.php +++ b/htdocs/admin/oauth.php @@ -1,6 +1,7 @@ * Copyright (C) 2016 Raphaƫl Doursenaud + * Copyright (C) 2022 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -46,38 +47,47 @@ $action = GETPOST('action', 'aZ09'); $provider = GETPOST('provider', 'aZ09'); $label = GETPOST('label', 'aZ09'); +$error = 0; + /* * Actions */ -if ($action == 'update') { - $error = 0; - - if (GETPOST('add') && $provider && $provider != '-1') { // $provider is OAUTH_XXX +if ($action == 'add') { // $provider is OAUTH_XXX + if ($provider && $provider != '-1') { $constname = strtoupper($provider).($label ? '-'.$label : '').'_ID'; - dolibarr_set_const($db, $constname, 'ToComplete', 'chaine', 0, '', $conf->entity); - } else { - foreach ($conf->global as $key => $val) { - if (!empty($val) && preg_match('/^OAUTH_.+_ID$/', $key)) { - $constvalue = str_replace('_ID', '', $key); - if (!dolibarr_set_const($db, $constvalue.'_ID', GETPOST($constvalue.'_ID'), 'chaine', 0, '', $conf->entity)) { - $error++; - } - // If we reset this provider, we also remove the secret - if (!dolibarr_set_const($db, $constvalue.'_SECRET', GETPOST($constvalue.'_ID') ? GETPOST($constvalue.'_SECRET') : '', 'chaine', 0, '', $conf->entity)) { - $error++; - } - } - } - if (!$error) { - setEventMessages($langs->trans("SetupSaved"), null); + if (getDolGlobalString($constname)) { + setEventMessages($langs->trans("AOAuthEntryForThisProviderAndLabelAlreadyHasAKey"), null, 'errors'); + $error++; } else { - setEventMessages($langs->trans("Error"), null, 'errors'); + dolibarr_set_const($db, $constname, 'ToComplete', 'chaine', 0, '', $conf->entity); + setEventMessages($langs->trans("OAuthProviderAdded"), null); } } } +if ($action == 'update') { + foreach ($conf->global as $key => $val) { + if (!empty($val) && preg_match('/^OAUTH_.+_ID$/', $key)) { + $constvalue = str_replace('_ID', '', $key); + if (!dolibarr_set_const($db, $constvalue.'_ID', GETPOST($constvalue.'_ID'), 'chaine', 0, '', $conf->entity)) { + $error++; + } + // If we reset this provider, we also remove the secret + if (!dolibarr_set_const($db, $constvalue.'_SECRET', GETPOST($constvalue.'_ID') ? GETPOST($constvalue.'_SECRET') : '', 'chaine', 0, '', $conf->entity)) { + $error++; + } + } + } + + if (!$error) { + setEventMessages($langs->trans("SetupSaved"), null); + } else { + setEventMessages($langs->trans("Error"), null, 'errors'); + } +} + /* * View @@ -92,7 +102,7 @@ print load_fiche_titre($langs->trans('ConfigOAuth'), $linkback, 'title_setup'); print '
'; print ''; -print ''; +print ''; $head = oauthadmin_prepare_head(); @@ -102,8 +112,8 @@ print dol_get_fiche_head($head, 'services', '', -1, 'technic'); print ''.$langs->trans("ListOfSupportedOauthProviders").'

'; -print ''; +print ''; foreach ($list as $key) { $supported = 0; $keyforsupportedoauth2array = $key[0]; @@ -122,10 +132,16 @@ print ''; print ajax_combobox('provider'); print ' '; print ' '; +print '
'; + print '
'; print '
'; +print '
'; +print ''; +print ''; + print '
'; print ''; diff --git a/htdocs/langs/en_US/oauth.lang b/htdocs/langs/en_US/oauth.lang index f41c1632cac..225a62bb13b 100644 --- a/htdocs/langs/en_US/oauth.lang +++ b/htdocs/langs/en_US/oauth.lang @@ -12,9 +12,10 @@ TokenDeleted=Token deleted RequestAccess=Click here to request/renew access and receive a new token DeleteAccess=Click here to delete token UseTheFollowingUrlAsRedirectURI=Use the following URL as the Redirect URI when creating your credentials with your OAuth provider: -ListOfSupportedOauthProviders=Enter the credentials provided by your OAuth2 provider. Only supported OAuth2 providers are listedd here. These services may be used by other modules that need OAuth2 authentication. +ListOfSupportedOauthProviders=Add you OAuth2 token providers. Only supported OAuth2 providers are listedd here. These services may be used by other modules that need OAuth2 authentication. OAuthSetupForLogin=Page to manage (generate/delete) OAuth tokens SeePreviousTab=See previous tab +OAuthProvider=OAuth provider OAuthIDSecret=OAuth ID and Secret TOKEN_REFRESH=Token Refresh Present TOKEN_EXPIRED=Token expired @@ -32,4 +33,6 @@ OAUTH_URL_FOR_CREDENTIAL=Go to