Skip to content

Commit

Permalink
v2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
milesimarco committed Dec 30, 2021
1 parent f069394 commit 8afe325
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 26 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Plugin WordPress per l'interfacciamento con il Sistema Pubblico di Identità Dig

## Credits

Copyright © 2017-2022 **Marco Milesi** - www.marcomilesi.com - www.wpgov.it
Copyright © 2017-2022 **Marco Milesi**
www.marcomilesi.com - www.wpgov.it

### Ringraziamenti
* **Christian Ghellere, Andrea Smith**: attività di software testing
Expand Down
32 changes: 19 additions & 13 deletions admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ function spid_get_tabs( $id ) {
break;
case 1:
$id1 = ' nav-tab-active';
break;
case 2:
$id2 = ' nav-tab-active';
break;
}
$r = '<h2 class="nav-tab-wrapper wp-clearfix">
<a href="?page=spid_menu" class="nav-tab'.$id0.'">Home</a>
Expand All @@ -21,7 +23,6 @@ function spid_get_tabs( $id ) {
}

function spid_menu_func() {

echo '
<div id="welcome-panel" class="welcome-panel" style="text-align: center; padding: 30px;">
Expand All @@ -38,6 +39,9 @@ function spid_menu_func() {
$options = get_option( 'spid' );

?>
<p class="about-description">
Hai bisogno di aiuto? Consulta la <a href="https://github.com/WPGov/wp-spid-italia/wiki" alt="Documentazione" target="_blank">documentazione</a> o <a href="https://www.wpgov.it/contatti" alt="Contatti" target="_blank">contattaci</a> per una consulenza.
</p>
<table class="form-table">
<tr valign="top">
<th scope="row">
Expand All @@ -53,14 +57,15 @@ function spid_menu_func() {
</th>
<td>
<input id="enable_validator" name="spid[enable_validator]" type="checkbox" value="1" <?php checked( '1', isset($options['enable_validator']) ); ?> />
Lasciare questa opzione disattiva quando non sono in corso test
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="countryName">countryName</label>
</th>
<td>
<input id="countryName" name="spid[countryName]" type="text" value="<?php echo $options['countryName']; ?>" />
<input id="countryName" name="spid[countryName]" type="text" value="<?php echo ( isset( $options['countryName']) ? $options['countryName'] : '' ); ?>" />
Codice ISO 3166-1 α-2 del Paese ove è situata la sede legale del SP (esempio: IT)
</td>
</tr>
Expand All @@ -69,87 +74,88 @@ function spid_menu_func() {
<label for="stateOrProvinceName">stateOrProvinceName</label>
</th>
<td>
<input id="stateOrProvinceName" name="spid[stateOrProvinceName]" type="text" value="<?php echo $options['stateOrProvinceName']; ?>" />
<input id="stateOrProvinceName" name="spid[stateOrProvinceName]" type="text" value="<?php echo ( isset( $options['stateOrProvinceName']) ? $options['stateOrProvinceName'] : '' ); ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="localityName">localityName</label>
</th>
<td>
<input id="localityName" name="spid[localityName]" type="text" value="<?php echo $options['localityName']; ?>" />
<input id="localityName" name="spid[localityName]" type="text" value="<?php echo ( isset( $options['localityName']) ? $options['localityName'] : '' ); ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="commonName">commonName</label>
</th>
<td>
<input id="commonName" name="spid[commonName]" type="text" value="<?php echo $options['commonName']; ?>" />
<input id="commonName" name="spid[commonName]" type="text" value="<?php echo ( isset( $options['commonName']) ? $options['commonName'] : '' ); ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="emailAddress">emailAddress</label>
</th>
<td>
<input id="emailAddress" name="spid[emailAddress]" type="text" value="<?php echo $options['emailAddress']; ?>" />
<input id="emailAddress" name="spid[emailAddress]" type="text" value="<?php echo ( isset( $options['emailAddress']) ? $options['emailAddress'] : '' ); ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="sp_org_name">sp_org_name</label>
</th>
<td>
<input id="sp_org_name" name="spid[sp_org_name]" type="text" value="<?php echo $options['sp_org_name']; ?>" maxlength="60"/> your organization full name
<input id="sp_org_name" name="spid[sp_org_name]" type="text" value="<?php echo ( isset( $options['sp_org_name']) ? $options['sp_org_name'] : '' ); ?>" maxlength="60"/> your organization full name
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="sp_org_display_name">sp_org_display_name</label>
</th>
<td>
<input id="sp_org_display_name" name="spid[sp_org_display_name]" type="text" value="<?php echo $options['sp_org_display_name']; ?>" maxlength="60"/> your organization display name
<input id="sp_org_display_name" name="spid[sp_org_display_name]" type="text" value="<?php echo ( isset( $options['sp_org_display_name']) ? $options['sp_org_display_name'] : '' ); ?>" maxlength="60"/> your organization display name
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="sp_contact_ipa_code">sp_contact_ipa_code</label>
</th>
<td>
<input id="sp_contact_ipa_code" name="spid[sp_contact_ipa_code]" type="text" value="<?php echo $options['sp_contact_ipa_code']; ?>" />
<input id="sp_contact_ipa_code" name="spid[sp_contact_ipa_code]" type="text" value="<?php echo ( isset( $options['sp_contact_ipa_code']) ? $options['sp_contact_ipa_code'] : '' ); ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="sp_contact_fiscal_code">sp_contact_fiscal_code</label>
</th>
<td>
<input id="sp_contact_fiscal_code" name="spid[sp_contact_fiscal_code]" type="text" value="<?php echo $options['sp_contact_fiscal_code']; ?>" />
<input id="sp_contact_fiscal_code" name="spid[sp_contact_fiscal_code]" type="text" value="<?php echo ( isset( $options['sp_contact_fiscal_code']) ? $options['sp_contact_fiscal_code'] : '' ); ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="sp_contact_email">sp_contact_email</label>
</th>
<td>
<input id="sp_contact_email" name="spid[sp_contact_email]" type="text" value="<?php echo $options['sp_contact_email']; ?>" />
<input id="sp_contact_email" name="spid[sp_contact_email]" type="text" value="<?php echo ( isset( $options['sp_contact_email']) ? $options['sp_contact_email'] : '' ); ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="sp_contact_phone">sp_contact_phone</label>
</th>
<td>
<input id="sp_contact_phone" name="spid[sp_contact_phone]" type="text" value="<?php echo $options['sp_contact_phone']; ?>" />
<input id="sp_contact_phone" name="spid[sp_contact_phone]" type="text" value="<?php echo ( isset( $options['sp_contact_phone']) ? $options['sp_contact_phone'] : '' ); ?>" />
</td>
</tr>
</table>
<?php
submit_button();
echo '</form>';
} else if ( $_GET['spid_action'] == 'metadata' ) {
} else if ( isset($_GET['spid_action']) && $_GET['spid_action'] == 'metadata' ) {
echo spid_get_tabs( 2 );
echo '<p">Attenzione! Questo URL è riservato e deve essere conservato con cura. Non comunicarlo a terzi e non indicarlo su siti o forum di supporto.</p>';
echo '<p class="about-description">URL metadata: <a href="'.spid_get_metadata_url().'" target="_blank">'.spid_get_metadata_url().'</a></p>';
} else {
echo spid_get_tabs( 0 );
Expand Down
14 changes: 11 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Tags: spid, italia, sistema, pubblico, identità, digitale, login, sistema pubbl
Requires at least: 4.8
Requires PHP: 7
Tested up to: 5.9
Version: 2.2.4
Stable tag: 2.2.4
Version: 2.3
Stable tag: 2.3
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand All @@ -25,7 +25,8 @@ https://www.youtube.com/watch?v=w5Z5EBG1R1M

https://www.youtube.com/watch?v=i2eTL_Q2xfM

Copyright © 2017-2022 **Marco Milesi** - [www.marcomilesi.com](https://www.marcomilesi.com) - [www.wpgov.it](https://www.wpgov.it)
Copyright © 2017-2022 **Marco Milesi**
[www.marcomilesi.com](https://www.marcomilesi.com) - [www.wpgov.it](https://www.wpgov.it)

### Ringraziamenti
* **Christian Ghellere, Andrea Smith**: attività di software testing
Expand All @@ -50,6 +51,13 @@ https://www.youtube.com/watch?v=2UNAtVjFFAs
== Changelog ==
> Backup your data before upgrade.

= 2.3 20211230 =
* [NEW] Added compatibility with third party login URL modifiers and custom filters - check [wiki](https://github.com/WPGov/wp-spid-italia/wiki)
* [IMPROVEMENT] Performance boost
* [IMPROVEMENT] Settings page changes
* [IMPROVEMENT] Readme and doc changes
* [BUGFIX] Removed some warnings

= 2.2.4 20211201 =
* [BUGFIX] Minor bugfix - https://github.com/WPGov/wp-spid-italia/releases

Expand Down
30 changes: 21 additions & 9 deletions wp-spid-italia.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: WP SPID Italia
Description: SPID - Sistema Pubblico di Identità Digitale
Author: Marco Milesi
Version: 2.2.4
Version: 2.3
Author URI: http://www.marcomilesi.com
*/

Expand Down Expand Up @@ -132,7 +132,7 @@ function() { include( plugin_dir_path( __FILE__ ) . 'admin/settings.php'); spid_
try {
$sp = spid_load();
if ( $sp && $sp->isAuthenticated() ) {
return get_site_url() . '/wp-login.php?spid_sso=out';
return wp_spid_italia_get_login_url( 'out' ) .'?spid_sso=out';
}
} catch ( Exception $e) {

Expand Down Expand Up @@ -221,8 +221,7 @@ function spid_errors( $errorMsg2 ){
wp_clear_auth_cookie();
remove_action('login_footer', 'wp_shake_js', 12);
add_filter( 'login_errors', function() { return 'Disconnesso da SPID'; } );
$sp->logout( 0, get_site_url() . '/wp-login.php?spid_sso=out' );
//$sp->logout( 0, wp_logout_url() );
$sp->logout( 0, wp_spid_italia_get_login_url( 'out' ) .'?spid_sso=out' );
} else if (isset($_POST) && isset($_POST['selected_idp'])) {
$idp = $_POST['selected_idp'];
} else if ( isset( $_GET['spid_sso'] ) && $_GET['spid_sso'] == 'in' ) {
Expand All @@ -234,8 +233,7 @@ function spid_errors( $errorMsg2 ){
if ( isset( $_GET['spid_idp'] ) && $_GET['spid_idp'] != '' ) {
if ( $sp->isAuthenticated() ) {
session_destroy();
$_SESSION = NULL;
#$sp->logout( 0, get_site_url() . '/wp-login.php?spid_sso=out&' );
$_SESSION = NULL;
}
$assertId = 0; // index of assertion consumer service as per the SP metadata (sp_assertionconsumerservice in settings array)
$attrId = 0; // index of attribute consuming service as per the SP metadata (sp_attributeconsumingservice in settings array)
Expand Down Expand Up @@ -282,7 +280,7 @@ function spid_errors( $errorMsg2 ){
$attributes = $sp->getAttributes();
echo 'Gentile '.$attributes['name'].',<br>il tuo account non è abilitato su questo sito.';

echo '<br><br><a class="button button-secondary button-large" href="'.esc_url( get_site_url() . '/wp-login.php?spid_sso=out' ).'" alt="Logout">Disconnetti SPID</a>';
echo '<br><br><a class="button button-secondary button-large" href="'.esc_url( wp_spid_italia_get_login_url( 'out' ) .'?spid_sso=out' ).'" alt="Logout">Disconnetti SPID</a>';
echo '</p>';
die();
}
Expand Down Expand Up @@ -333,6 +331,19 @@ function spid_update_user( $user, $attributes ) {
wp_enqueue_script( 'spid-js-loginform', plugins_url( 'js/spid-sp-loginform.js', __FILE__ ), array( 'jquery' ) );
}, 1 );

function wp_spid_italia_get_login_url( $dir = 'default' ) {
$default_url = wp_login_url();

if ( $default_url != apply_filters( 'spid_filter_login_url_dir_default', $default_url ) ) {
return apply_filters( 'spid_filter_login_url_dir_default', $default_url );
} else if ( $dir == 'in' ) {
return apply_filters( 'spid_filter_login_url_dir_in', $default_url );
} else if ( $dir == 'out' ) {
return apply_filters( 'spid_filter_login_url_dir_out', $default_url );
}
return $default_url;
}

function is_spid_enabled() {
return spid_option('enabled');
}
Expand Down Expand Up @@ -363,9 +374,9 @@ function spid_load() {
'sp_cert_file' => SPID__CERT_DIR.'sp.crt',
'sp_comparison' => 'minimum', // one of: "exact", "minimum", "better" or "maximum"
'sp_assertionconsumerservice' => [
get_site_url() . '/wp-login.php?spid_sso=in', // Servizio standard
wp_spid_italia_get_login_url( 'in' ) .'?spid_sso=in', // Servizio standard
],
'sp_singlelogoutservice' => [ [ get_site_url() . '/wp-login.php?spid_sso=out', '' ] ],
'sp_singlelogoutservice' => [ [ wp_spid_italia_get_login_url( 'out' ) .'?spid_sso=out', '' ] ],
'sp_org_name' => spid_option( 'sp_org_name' ),
'sp_org_display_name' => spid_option( 'sp_org_display_name' ),
'sp_contact_ipa_code' => spid_option( 'sp_contact_ipa_code' ),
Expand Down Expand Up @@ -412,6 +423,7 @@ function spid_fs() {
'has_paid_plans' => false,
'menu' => array(
'slug' => 'spid_menu',
'account' => false,
'contact' => false,
'support' => false,
'parent' => array(
Expand Down

0 comments on commit 8afe325

Please sign in to comment.