Skip to content

Commit

Permalink
Combining Lock init process; removing unused templates; Lock login fo…
Browse files Browse the repository at this point in the history
…rm id constant
  • Loading branch information
joshcanhelp committed Apr 17, 2018
1 parent 190fca8 commit 95e1cea
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 248 deletions.
3 changes: 1 addition & 2 deletions WP_Auth0.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
define( 'WPA0_LOCK_CDN_URL', 'https://cdn.auth0.com/js/lock/11.5/lock.min.js' );
define( 'WPA0_AUTH0_JS_CDN_URL', 'https://cdn.auth0.com/js/auth0/9.4/auth0.min.js' );

define( 'WPA0_AUTH0_LOGIN_FORM_ID', 'auth0-login-form' );
define( 'WPA0_CACHE_GROUP', 'wp_auth0' );
define( 'WPA0_STATE_COOKIE_NAME', 'auth0_state' );
define( 'WPA0_JWKS_CACHE_TRANSIENT_NAME', 'WP_Auth0_JWKS_cache' );
Expand Down Expand Up @@ -130,7 +131,6 @@ public function init() {
$this->check_signup_status();

if ( $this->a0_options->get( 'auto_login' ) ) {

WP_Auth0_Nonce_Handler::getInstance()->setCookie();
}

Expand Down Expand Up @@ -400,7 +400,6 @@ public function render_form( $html ) {
ob_start();
require_once WPA0_PLUGIN_DIR . 'templates/login-form.php';
renderAuth0Form();

return ob_get_clean();
}

Expand Down
42 changes: 42 additions & 0 deletions assets/js/lock-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* globals jQuery, console, Cookies, wpAuth0LockGlobal, Auth0Lock, Auth0LockPasswordless */
jQuery(document).ready(function ($) {
var opts = wpAuth0LockGlobal;
var loginForm = $( '#' + opts.loginFormId );

// Missing critical Auth0 settings
if ( ! opts.ready || ! loginForm.length ) {
$( '#form-signin-wrapper' ).hide();
$( '#loginform' ).show();
$( '#login' ).find( 'h1' ).show();

if ( ! opts.ready ) {
console.error( opts.i18n.notReadyText );
}
if ( ! loginForm.length ) {
console.error( opts.i18n.cannotFindNodeText + '"' + opts.loginFormId + '"' );
}
return;
}

// Set state cookie to verify during callback
Cookies.set( opts.stateCookieName, opts.settings.auth.params.state );

// Set Lock to standard or Passwordless
var Lock = opts.usePasswordless
? new Auth0LockPasswordless( opts.clientId, opts.domain, opts.settings )
: new Auth0Lock( opts.clientId, opts.domain, opts.settings );

// Check if we're showing as a modal, can be used in shortcodes and widgets
if ( opts.showAsModal ) {
$( '<button>' )
.text( opts.i18n.modalButtonText )
.attr( 'id', 'a0LoginButton' )
.insertAfter( loginForm )
.click( function () {
Lock.show();
} );
} else {
Lock.show();
}
});

43 changes: 0 additions & 43 deletions assets/js/login-pwl.js

This file was deleted.

1 change: 1 addition & 0 deletions assets/lib/js.cookie.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/WP_Auth0_Embed_Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function widget( $args, $instance ) {

$instance['show_as_modal'] = $this->showAsModal();
$instance['modal_trigger_name'] = isset( $instance['modal_trigger_name'] )
? $instance['modal_trigger_name']
: __( 'Login', 'wp-auth0' );
? $instance['modal_trigger_name']
: __( 'Login', 'wp-auth0' );

if ( !isset( $instance['redirect_to'] ) || empty($instance['redirect_to']) ) {
$instance['redirect_to'] = home_url( $_SERVER["REQUEST_URI"] );
Expand Down
18 changes: 8 additions & 10 deletions lib/WP_Auth0_Lock10_Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ class WP_Auth0_Lock10_Options {
protected $signup_mode = false;
protected $_scopes = 'openid email name nickname picture';

const PWL_CDN_URL = '//cdn.auth0.com/js/lock/11.5/lock.min.js';

/**
* WP_Auth0_Lock10_Options constructor.
*
Expand Down Expand Up @@ -233,19 +231,16 @@ public function get_lock_options() {
if ( isset( $this->extended_settings['redirect_to'] ) ) {
$redirect_to = $this->extended_settings['redirect_to'];
}
$state = $this->get_state_obj( $redirect_to );

$options_obj = $this->build_settings( $this->wp_options->get_options() );
$extended_settings = $this->build_settings( $extended_settings );

$extraOptions = array(
"auth" => array(
"params" => array("state" => $state ),
"params" => array(
"state" => $this->get_state_obj( $redirect_to ),
"scope" => apply_filters( 'auth0_auth_param_scopes', $this->_scopes ),
),
),
);

$extraOptions["auth"]["params"]["scope"] = apply_filters( 'auth0_auth_param_scopes', $this->_scopes );

if ( $this->get_auth0_implicit_workflow() ) {
$extraOptions["auth"]["responseType"] = 'id_token';
$extraOptions["auth"]["redirectUrl"] = $this->get_implicit_callback_url();
Expand All @@ -255,10 +250,13 @@ public function get_lock_options() {
$extraOptions["auth"]["redirectUrl"] = $this->get_code_callback_url();
}

$options_obj = $this->build_settings( $this->wp_options->get_options() );
$extended_settings = $this->build_settings( $extended_settings );

$options_obj = array_replace_recursive( $extraOptions, $options_obj, $extended_settings );

if ( ! $this->show_as_modal() ) {
$options_obj['container'] = 'auth0-login-form';
$options_obj['container'] = WPA0_AUTH0_LOGIN_FORM_ID;
}

if ( ! $this->is_registration_enabled() ) {
Expand Down
2 changes: 1 addition & 1 deletion lib/WP_Auth0_Lock_Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function get_lock_options() {
$options_obj = array_merge( $extraOptions, $options_obj, $extended_settings );

if ( ! $this->show_as_modal() ) {
$options_obj['container'] = 'auth0-login-form';
$options_obj['container'] = WPA0_AUTH0_LOGIN_FORM_ID;
}

if ( ! $this->is_registration_enabled() ) {
Expand Down
14 changes: 5 additions & 9 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,18 @@ Yes, this plugin will override the default WooCommerce login forms with the Auth
All is not lost!

* If you're setting up the plugin for the first time or having issues with users logging in, please review the [configuration](https://auth0.com/docs/cms/wordpress/configuration) and [troubleshooting](https://auth0.com/docs/cms/wordpress/troubleshoot) pages at [auth0.com/docs](https://auth0.com/docs/cms/wordpress/).
* If you found a bug in the plugin code [submit an issue](https://github.com/auth0/wp-auth0/issues) or [create a pull request](https://github.com/auth0/wp-auth0/pulls) on [GitHub](https://github.com/auth0/wp-auth0/).
* If you found a bug in the plugin code [submit an issue](https://github.com/auth0/wp-auth0/issues) or [create a pull request](https://github.com/auth0/wp-auth0/pulls) on GitHub.
* If you have questions about how to use Auth0 or the plugin, please [post on our community site](https://community.auth0.com/) or create a [support forum request here](https://wordpress.org/support/plugin/auth0).
* You can also see additional documentation and answers on our [support site](https://support.auth0.com/). Customers on a paid Auth0 plan can [submit a trouble ticket](https://support.auth0.com/tickets) for a fast response.

= My question is not covered here; what do I do? =

All is not lost!

* If you're setting up the plugin for the first time or having issues after an upgrade, please review the [configuration
page at auth0.com/docs](https://auth0.com/docs/cms/wordpress/configuration)
* If you found a bug in the plugin code [submit an issue](https://github.com/auth0/wp-auth0/issues) or [create a pull
request](https://github.com/auth0/wp-auth0/pulls) on [GitHub](https://github.com/auth0/wp-auth0/).
* If you have questions about how to use Auth0 or the plugin, please [post on our community site](https://community
.auth0.com/) or create a [support forum request here](https://wordpress.org/support/plugin/auth0).
* You can also see additional documentation and answers on our [support site](https://support.auth0.com/). Customers on
a paid Auth0 plan can submit trouble tickets for a fast response.
* If you're setting up the plugin for the first time or having issues after an upgrade, please review the [configuration page at auth0.com/docs](https://auth0.com/docs/cms/wordpress/configuration)
* If you found a bug in the plugin code [submit an issue](https://github.com/auth0/wp-auth0/issues) or [create a pull request](https://github.com/auth0/wp-auth0/pulls) on [GitHub](https://github.com/auth0/wp-auth0/).
* If you have questions about how to use Auth0 or the plugin, please [post on our community site](https://community.auth0.com/) or create a [support forum request here](https://wordpress.org/support/plugin/auth0).
* You can also see additional documentation and answers on our [support site](https://support.auth0.com/). Customers on a paid Auth0 plan can submit trouble tickets for a fast response.

== Changelog ==

Expand Down
76 changes: 0 additions & 76 deletions templates/auth0-login-form-lock10.php

This file was deleted.

39 changes: 0 additions & 39 deletions templates/auth0-login-form-pwl.php

This file was deleted.

27 changes: 27 additions & 0 deletions templates/auth0-login-form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
$auth0_options = WP_Auth0_Options::Instance();
$wle = (bool) $auth0_options->get( 'wordpress_login_enabled', true );
?>
<div id="form-signin-wrapper" class="auth0-login">
<div class="form-signin">
<div id="<?php echo esc_attr( WPA0_AUTH0_LOGIN_FORM_ID ) ?>"></div>
<?php if ( $wle && function_exists( 'login_header' ) ) : ?>
<div id="extra-options">
<a href="<?php echo wp_login_url() ?>?wle">
<?php _e( 'Login with WordPress username', 'wp-auth0' ) ?>
</a>
</div>
<?php endif ?>
</div>
</div>

<style type="text/css">
<?php echo apply_filters( 'auth0_login_css', '' ) ?>
<?php echo $auth0_options->get( 'custom_css' ) ?>
</style>

<?php if ( $custom_js = $auth0_options->get( 'custom_js' ) ) : ?>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() { <?php echo $custom_js ?> });
</script>
<?php endif ?>
34 changes: 0 additions & 34 deletions templates/error-msg.php

This file was deleted.

Loading

0 comments on commit 95e1cea

Please sign in to comment.