Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions WP_Auth0.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ public static function init(){
add_action( 'plugins_loaded', array(__CLASS__, 'initialize_wpdb_tables'));
add_action( 'template_redirect', array(__CLASS__, 'init_auth0'), 1 );

// Add an action to append a stylesheet for the login page
add_action( 'login_enqueue_scripts', array(__CLASS__, 'render_auth0_login_css') );

// Add a hook to add Auth0 code on the login page
add_filter( 'login_message', array(__CLASS__, 'render_form') );

// Add hook to redirect directly on login auto
add_action('login_init', array(__CLASS__, 'login_auto'));
// Add hook to handle when a user is deleted
Expand Down Expand Up @@ -96,6 +101,15 @@ public static function logout() {

}

public static function render_back_to_auth0() {

include WPA0_PLUGIN_DIR . 'templates/back-to-auth0.php';

}

public static function render_auth0_login_css() { ?>
<link rel='stylesheet' href='<?php echo plugins_url( 'assets/css/login.css', __FILE__ ); ?>' type='text/css' />
<?php }

public static function render_form( $html ){
$activated = absint(WP_Auth0_Options::get( 'active' ));
Expand Down
35 changes: 35 additions & 0 deletions assets/css/login.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#extra-options {
width: 272px;
margin:auto;
padding: 0px 24px;
margin-top:15px;
}
.form-signin #extra-options {
margin-bottom:15px;
margin-top:0;
}
#extra-options a {
text-decoration: none;
color: #999;
}
#extra-options a:hover {
color: #2ea2cc;
}
body.a0-widget-open>* {
display: inherit;
}
#loginform{
display: none;
}
#login #nav {
display: none;
}
#a0-widget .a0-panel{
margin: auto;
}
#auth0-login-form {
margin-bottom: 20px;
}
#auth0-login-form {
min-height: 250px;
}
10 changes: 5 additions & 5 deletions assets/css/main.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.a0-footer {
display: none;
display: none;
}
#a0-widget .a0-zocial.a0-wp-login {
background-color: #490050;
background-color: #490050;
}
#wp-login-form-wrapper {
display: none;
display: none;
}
.auth0-login .form-signin-heading {
margin-bottom: 10px;
}
margin-bottom: 10px;
}
16 changes: 16 additions & 0 deletions lib/WP_Auth0_Admin.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ public static function init_admin(){
array('label_for' => 'wpa0_client_secret')
);

add_settings_field(
'wpa0_login_enabled',
__('WordPress login enabled', WPA0_LANG),
array(__CLASS__, 'render_allow_wordpress_login'),
WP_Auth0_Options::OPTIONS_NAME,
'wp_auth0_basic_settings_section',
array('label_for' => 'wpa0_login_enabled')
);



add_settings_section(
Expand Down Expand Up @@ -246,6 +255,12 @@ public static function render_allow_signup () {
echo '<br/><span class="description">' . __('If you have database connection you can allow users to signup in the widget', WPA0_LANG) . '</span>';
}

public static function render_allow_wordpress_login () {
$v = absint(WP_Auth0_Options::get( 'wordpress_login_enabled' ));
echo '<input type="checkbox" name="' . WP_Auth0_Options::OPTIONS_NAME . '[wordpress_login_enabled]" id="wpa0_wp_login_enabled" value="1" ' . checked( $v, 1, false ) . '/>';
echo '<br/><span class="description">' . __('Mark this if you want to enable the regular WordPress login', WPA0_LANG) . '</span>';
}


public static function render_basic_description(){

Expand Down Expand Up @@ -277,6 +292,7 @@ public static function input_validator( $input ){
$input['show_icon'] = (isset($input['show_icon']) ? 1 : 0);
$input['active'] = (isset($input['active']) ? 1 : 0);
$input['requires_verified_email'] = (isset($input['requires_verified_email']) ? 1 : 0);
$input['wordpress_login_enabled'] = (isset($input['wordpress_login_enabled']) ? 1 : 0);
$input['allow_signup'] = (isset($input['allow_signup']) ? 1 : 0);

$error = "";
Expand Down
4 changes: 3 additions & 1 deletion lib/WP_Auth0_Options.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class WP_Auth0_Options {
private static function get_options(){
if(empty(self::$_opt)){
$options = get_option( self::OPTIONS_NAME, array());

if(!is_array($options))
$options = self::defaults();

Expand Down Expand Up @@ -48,7 +49,8 @@ private static function defaults(){
'ip_ranges' => '',
'cdn_url' => '//cdn.auth0.com/w2/auth0-widget-5.min.js',
'requires_verified_email' => true,
'allow_signup' => true
'allow_signup' => true,
'wordpress_login_enabled' => true
);
}
}
73 changes: 73 additions & 0 deletions templates/auth0-login-form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
$client_id = WP_Auth0_Options::get('client_id');
$domain = WP_Auth0_Options::get('domain');
$show_icon = absint(WP_Auth0_Options::get('show_icon'));
$cdn = WP_Auth0_Options::get('cdn_url');
$allow_signup = WP_Auth0_Options::get('allow_signup') == 1;
$extra_css = apply_filters( 'auth0_login_css', '');

$form_desc = WP_Auth0_Options::get('form_desc');
if (isset($_GET['interim-login']) && $_GET['interim-login'] == 1) {
$interim_login = true;
} else {
$interim_login = false;
}

// Get title for login widget
$title = WP_Auth0_Options::get('form_title');
if (empty($title)) {
$title = "Sign In";
}

$stateObj = array("interim" => $interim_login, "uuid" =>uniqid());
$state = json_encode($stateObj);

if(empty($client_id) || empty($domain)): ?>
<p><?php _e('Auth0 Integration has not yet been set up! Please visit your Wordpress Auth0 settings and fill in the required settings.', WPA0_LANG); ?></p>
<?php else: ?>
<div id="form-signin-wrapper" class="auth0-login">
<?php include 'error-msg.php'; ?>
<div class="form-signin">
<div id="auth0-login-form">
</div>
<?php if ($wordpress_login_enabled): ?>
<div id="extra-options">
<a href="?wle">Login with WordPress username</a>
</div>
<?php endif; ?>
</div>
</div>
<?php if (!empty($extra_css)): ?>
<style type="text/css">
<?php echo $extra_css; ?>
</style>
<?php endif; ?>
<script id="auth0" src="<?php echo $cdn ?>"></script>
<script type="text/javascript">
var callback = null;
if(typeof(a0_wp_login) === "object"){
callback = a0_wp_login.initialize
}

var widget = new Auth0Widget({
domain: '<?php echo $domain; ?>',
chrome: true,
clientID: '<?php echo $client_id; ?>',
callbackURL: '<?php echo site_url('/index.php?auth0=1'); ?>',
container: 'auth0-login-form',
state: '<?php echo $state; ?>',
showSignup: <?php echo $allow_signup?'true':'false' ?>,
dict: { signin: { title: '<?php echo $title ?>' } }
});

widget.signin({
onestep: true,
theme: 'static',
standalone: true,
showIcon: <?php echo ($show_icon ? 'true' : 'false'); ?>,
icon: '<?php echo ($show_icon ? WP_Auth0_Options::get('icon_url') : ''); ?>'
}, callback);

</script>
<?php
endif;
8 changes: 8 additions & 0 deletions templates/back-to-auth0.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<style>
#loginform{
display: block !important;
}
</style>
<div id="extra-options">
<a href="?">← Back to Auth0 login</a>
</div>
86 changes: 6 additions & 80 deletions templates/login-form.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,10 @@
if(is_user_logged_in())
return;

$client_id = WP_Auth0_Options::get('client_id');
$domain = WP_Auth0_Options::get('domain');
$show_icon = absint(WP_Auth0_Options::get('show_icon'));
$cdn = WP_Auth0_Options::get('cdn_url');
$allow_signup = WP_Auth0_Options::get('allow_signup') == 1;
$extra_css = apply_filters( 'auth0_login_css', '');

$form_desc = WP_Auth0_Options::get('form_desc');
if (isset($_GET['interim-login']) && $_GET['interim-login'] == 1) {
$interim_login = true;
} else {
$interim_login = false;
}

// Get title for login widget
$title = WP_Auth0_Options::get('form_title');
if (empty($title)) {
$title = "Sign In";
$wordpress_login_enabled = WP_Auth0_Options::get('wordpress_login_enabled') == 1;
if (!$wordpress_login_enabled || !isset($_GET['wle'])) {
include ('auth0-login-form.php');
}else{
add_action('login_footer', array(WP_Auth0::class, 'render_back_to_auth0'));
}

$stateObj = array("interim" => $interim_login, "uuid" =>uniqid());
$state = json_encode($stateObj);

if(empty($client_id) || empty($domain)): ?>
<p><?php _e('Auth0 Integration has not yet been set up! Please visit your Wordpress Auth0 settings and fill in the required settings.', WPA0_LANG); ?></p>
<?php else: ?>
<div id="form-signin-wrapper" class="auth0-login">
<?php include 'error-msg.php'; ?>
<div class="form-signin">

<div id="auth0-login-form" style=" min-height: 440px;"></div>
</div>
</div>
<?php if (!empty($extra_css)): ?>
<style type="text/css">
<?php echo $extra_css; ?>
</style>
<?php endif; ?>
<script id="auth0" src="<?php echo $cdn ?>"></script>
<script type="text/javascript">
var callback = null;
if(typeof(a0_wp_login) === "object"){
callback = a0_wp_login.initialize
}

var widget = new Auth0Widget({
domain: '<?php echo $domain; ?>',
chrome: true,
clientID: '<?php echo $client_id; ?>',
callbackURL: '<?php echo site_url('/index.php?auth0=1'); ?>',
container: 'auth0-login-form',
state: '<?php echo $state; ?>',
showSignup: <?php echo $allow_signup?'true':'false' ?>,
dict: { signin: { title: '<?php echo $title ?>' } }
});

widget.signin({
onestep: true,
theme: 'static',
standalone: true,
showIcon: <?php echo ($show_icon ? 'true' : 'false'); ?>,
icon: '<?php echo ($show_icon ? WP_Auth0_Options::get('icon_url') : ''); ?>'
}, callback);

</script>
<style type="text/css">
body.a0-widget-open>* {
display: inherit;
}
#loginform{
display: none;
}
#login #nav {
display: none;
}
#a0-widget .a0-panel{
margin: auto;
}

</style>
<?php endif;
?>