Skip to content

Commit fb16fad

Browse files
committed
change hooks to fix login problems on multisite
usability fixes
1 parent 744ceb3 commit fb16fad

File tree

1 file changed

+47
-22
lines changed

1 file changed

+47
-22
lines changed

sso-rest-auth-client.php

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin URI: https://github.com/rpi-virtuell/rw-sso-rest-auth-client
55
* Description: Client Authentication tool to compare Wordpress login Data with a Remote Login Server
66
* Author: Daniel Reintanz
7-
* Version: 1.0.1
7+
* Version: 1.1.0
88
* Domain Path: /languages
99
* Text Domain: rw-sso-client
1010
* Licence: GPLv3
@@ -28,20 +28,20 @@ class SsoRestAuthClient
2828
*/
2929
public function __construct()
3030
{
31-
if (!defined('KONTO_SERVER')) {
31+
if (!defined('KONTO_SERVER')) {
3232
if (getenv('KONTO_SERVER'))
3333
define('KONTO_SERVER', getenv('KONTO_SERVER'));
3434
else
3535
// .htaccess Eintrag fehlt: SetEnv KONTO_SERVER "https://my-wordpress-website.com"
3636
wp_die('Environmental Var KONTO_SERVER is not defined');
3737
}
3838
add_filter('authenticate', array($this, 'check_credentials'), 999, 3);
39-
add_action('login_head', array($this, 'login_through_token'));
39+
add_action('init', array($this, 'login_through_token'));
4040
add_action('wp_logout', array($this, 'remote_logout'));
4141
add_action('wp_head', array($this, 'remote_login'));
4242
add_action('admin_head', array($this, 'remote_login'));
4343
add_action('admin_menu', array($this, 'add_invite_user_user_page'), 999);
44-
add_action('user_new_form_tag', array($this, 'redir_new_user'), 999);
44+
add_action('user_new_form', array($this, 'redir_new_user'), 999);
4545
add_action('wp_ajax_search_user', 'ajax_search_user');
4646
add_action('wp_ajax_get_users_via_ajax', array($this, 'get_users_via_ajax'));
4747
add_action('wp_ajax_invite_user_via_ajax', array($this, 'invite_user_via_ajax'));
@@ -52,11 +52,14 @@ public function __construct()
5252
return KONTO_SERVER . '/wp-login.php?action=lostpassword';
5353
});
5454
add_filter('register_url', function () {
55-
return KONTO_SERVER . '/wp-login.php?action=register';
56-
});
57-
add_action('before_signup_header',function (){
55+
return KONTO_SERVER . '/wp-login.php?action=register&ref_service='.urlencode(home_url());
56+
},100000);
57+
58+
59+
//maybe use instead before_signup_form?
60+
add_action('before_signup_header',function (){
5861
if(!is_user_logged_in()){
59-
wp_redirect(KONTO_SERVER . '/wp-login.php?action=register');
62+
wp_redirect(KONTO_SERVER . '/wp-login.php?action=register&ref_service='.urlencode(home_url()));
6063
exit();
6164
}
6265
});
@@ -81,8 +84,8 @@ public function backend_notifier()
8184
<p><?php _e('WARNING: TABLE '.$table_name. " WAS NOT CREATED! PLEASE REACTIVATE THE PLUGIN : rw sso REST Auth Client "); ?> </p>
8285
</div>
8386
<?php
84-
}
85-
}
87+
}
88+
}
8689

8790
/**
8891
* Create Table which logs failed login attempts on plugin activation
@@ -261,7 +264,7 @@ public function login_through_token()
261264
}
262265
wp_set_current_user($user->ID);
263266
wp_set_auth_cookie($user->ID);
264-
$redirect_to = home_url();
267+
$redirect_to = home_url();
265268
wp_safe_redirect($redirect_to);
266269
exit();
267270
}
@@ -360,12 +363,18 @@ public function check_credentials($user, $username, $password)
360363

361364
/**
362365
* Redirect Users to the invite users page if user_new.php is accessed
363-
* @action user_new_form_tag
366+
* @action user_new_form
364367
* @since 1.0
365368
*/
366369
function redir_new_user()
367370
{
368-
wp_redirect(home_url() . '/wp-admin/users.php?page=invite_user');
371+
?>
372+
<script>
373+
location.href = "<?php echo admin_url() . '/users.php?page=invite_user';?>";
374+
</script>
375+
<?php
376+
wp_redirect(admin_url() . '/users.php?page=invite_user');
377+
die();
369378
}
370379

371380
/**
@@ -462,6 +471,7 @@ public function invite_user_via_ajax()
462471
*/
463472
function init_invite_user_page()
464473
{
474+
$register_url = KONTO_SERVER.'/register/'. str_replace('https://', '',home_url());
465475

466476
?>
467477
<style>
@@ -500,20 +510,34 @@ function init_invite_user_page()
500510
margin-bottom: 20px !important;
501511
}
502512

513+
.copy_field{
514+
width:600px;max-width: 100%;
515+
516+
background-color: transparent!important;
517+
518+
}
519+
503520
</style>
504521
<div class="wrap">
505-
<h1>Nutzer hinzufügen</h1>
506-
507-
<input id="suche" placeholder="Nutzername oder Email">
508-
<button id="search-button" type="button">Suchen</button>
509-
<p class="results-info">Gewünschten Nutzer auswählen</p>
510-
<div id="results">Ergebnisse</div>
522+
<h1><?php echo __('Add user','rw-sso-client');?></h1>
523+
<div class="invite_user_form">
524+
<p><?php echo __('Invite other users to join your blog. You can search for users who have already registered here','rw-sso-client');?>.</p>
525+
<input id="suche" placeholder="<?php echo __('Username or Email','rw-sso-client');?>">
526+
<button id="search-button" type="button">Suchen</button>
527+
<p class="results-info"><?php echo __('Select desired user (klick)','rw-sso-client');?></p>
528+
</div>
529+
<div id="results"></div>
511530
<div id="user_invite_form" style="display:none;">
512531
<input type="hidden" id="selected_user">
513532
<span id="selected_user_display"></span>
514533
<?php echo $this->prepare_role_html(); ?>
515-
<button type="button" id="invite_user">Nutzer anlegen</button>
534+
<button type="button" id="invite_user"><?php echo __('Add user','rw-sso-client');?></button>
516535
</div>
536+
<p><?php echo __('Send unregistered users a','rw-sso-client');?> <a href="<?php echo $register_url; ?>">
537+
<?php echo __('invitation link','rw-sso-client');?></a> <?php echo __('for your blog','rw-sso-client');?>:<br>
538+
<input type="text" class="copy_field" value="<?php echo $register_url; ?>">
539+
</p>
540+
517541
</div>
518542

519543

@@ -586,10 +610,10 @@ function remote_search() {
586610
success: function (data, textStatus, XMLHttpRequest) { //erfolgreiche anfrage
587611
if ($('#results') && data.success === true) {
588612
$('#user_invite_form').hide();
589-
$('#results').html($('#selected_user').val() + ' wurde erfolgreich hinzugefügt!');
613+
$('#results').html($('#selected_user').val() + ' <?php echo __('was added successfully','rw-sso-client'); ?>!');
590614
}
591615
if ($('#results') && data.success === false) {
592-
$('#results').html($('#selected_user').val() + ' konnte nicht hinzugefügt werden!');
616+
$('#results').html($('#selected_user').val() + ' <?php echo __('could not be added','rw-sso-client'); ?>!');
593617
}
594618
},
595619

@@ -626,6 +650,7 @@ private function prepare_role_html()
626650
$return .= '</select> ';
627651
return $return;
628652
}
653+
629654
}
630655

631656

0 commit comments

Comments
 (0)