From b885c812a9da47ffeb8a9dc1c2b29d9f5378c074 Mon Sep 17 00:00:00 2001 From: Josh Cunningham Date: Mon, 26 Mar 2018 17:33:52 -0700 Subject: [PATCH] Combining Lock init process; removing unused templates; Lock login form id constant --- WP_Auth0.php | 3 +- assets/js/lock-init.js | 42 +++++++++++++++ assets/js/login-pwl.js | 43 --------------- assets/lib/js.cookie.min.js | 1 + lib/WP_Auth0_Embed_Widget.php | 4 +- lib/WP_Auth0_Lock10_Options.php | 18 +++---- lib/WP_Auth0_Lock_Options.php | 2 +- readme.txt | 14 ++--- templates/auth0-login-form-lock10.php | 76 --------------------------- templates/auth0-login-form-pwl.php | 39 -------------- templates/auth0-login-form.php | 27 ++++++++++ templates/error-msg.php | 34 ------------ templates/login-form.php | 69 +++++++++++++----------- 13 files changed, 124 insertions(+), 248 deletions(-) create mode 100644 assets/js/lock-init.js delete mode 100644 assets/js/login-pwl.js create mode 100644 assets/lib/js.cookie.min.js delete mode 100644 templates/auth0-login-form-lock10.php delete mode 100644 templates/auth0-login-form-pwl.php create mode 100644 templates/auth0-login-form.php delete mode 100644 templates/error-msg.php diff --git a/WP_Auth0.php b/WP_Auth0.php index 52ae1919..b9bb3f2b 100644 --- a/WP_Auth0.php +++ b/WP_Auth0.php @@ -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' ); @@ -130,7 +131,6 @@ public function init() { $this->check_signup_status(); if ( $this->a0_options->get( 'auto_login' ) ) { - WP_Auth0_Nonce_Handler::getInstance()->setCookie(); } @@ -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(); } diff --git a/assets/js/lock-init.js b/assets/js/lock-init.js new file mode 100644 index 00000000..d69ab921 --- /dev/null +++ b/assets/js/lock-init.js @@ -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 ) { + $( ' - -
- - get_wordpress_login_enabled() && $canShowLegacyLogin ) { ?> -
- Login with WordPress username -
- - - - - - - - diff --git a/templates/auth0-login-form-pwl.php b/templates/auth0-login-form-pwl.php deleted file mode 100644 index d2f6ae3d..00000000 --- a/templates/auth0-login-form-pwl.php +++ /dev/null @@ -1,39 +0,0 @@ - - -
- - -
- - - -get( 'custom_js' ) ) : ?> - - \ No newline at end of file diff --git a/templates/auth0-login-form.php b/templates/auth0-login-form.php new file mode 100644 index 00000000..397039ed --- /dev/null +++ b/templates/auth0-login-form.php @@ -0,0 +1,27 @@ +get( 'wordpress_login_enabled', true ); +?> +
+ +
+ + + +get( 'custom_js' ) ) : ?> + + \ No newline at end of file diff --git a/templates/error-msg.php b/templates/error-msg.php deleted file mode 100644 index 4967506d..00000000 --- a/templates/error-msg.php +++ /dev/null @@ -1,34 +0,0 @@ - - - -
- - Email sent: In a minute or two, you should get an email with the password reset link.', LP_THEME_LANG ); ?> -
- -
- - Congratulations: Your password has been changed and you can now log in below.', LP_THEME_LANG ); ?> -
- -
- - Account created: Your password has been sent to your email address.', LP_THEME_LANG ); ?> -
- -
- - Account created: Your account is awaiting activation. Once an administrator has activated your account, a password will be emailed to you.', LP_THEME_LANG ); ?> -
- -
- - Not activated: Your account is awaiting activation.', LP_THEME_LANG ); ?> -
- -
- - Error: Invalid e-mail or password.', LP_THEME_LANG ); ?> -
- - diff --git a/templates/login-form.php b/templates/login-form.php index 877e1043..a22df7d2 100755 --- a/templates/login-form.php +++ b/templates/login-form.php @@ -1,40 +1,45 @@ get('passwordless_enabled', FALSE ); + $lock_cdn_url = $options->get( $use_passwordless ? 'passwordless_cdn_url' : 'cdn_url' ); - if ( ! $options->get('passwordless_enabled', FALSE) ) { - wp_enqueue_script( 'wpa0_lock', $options->get('cdn_url'), array( 'jquery' ), FALSE ); - require_once 'auth0-login-form-lock10.php'; - } else { - $lock_options = new WP_Auth0_Lock10_Options( $specialSettings ); + wp_enqueue_script( 'wpa0_lock', $lock_cdn_url, array( 'jquery' ), FALSE, TRUE ); + wp_enqueue_script( 'js-cookie', WPA0_PLUGIN_LIB_URL . 'js.cookie.min.js', FALSE, '2.2.0', TRUE ); + wp_enqueue_script( 'wpa0_lock_init', WPA0_PLUGIN_JS_URL . 'lock-init.js', array( 'jquery' ), WPA0_VERSION, TRUE ); + wp_localize_script( + 'wpa0_lock_init', + 'wpAuth0LockGlobal', + array( + 'settings' => $lock_options->get_lock_options(), + 'ready' => WP_Auth0::ready(), + 'domain' => $options->get( 'domain' ), + 'clientId' => $options->get( 'client_id' ), + 'stateCookieName' => WPA0_STATE_COOKIE_NAME, + 'usePasswordless' => $use_passwordless, + 'loginFormId' => WPA0_AUTH0_LOGIN_FORM_ID, + 'showAsModal' => ! empty( $specialSettings['show_as_modal'] ), + 'i18n' => array( + 'notReadyText' => __( 'Auth0 is not configured', 'wp-auth0' ), + 'cannotFindNodeText' => __( 'Auth0 cannot find node with id ', 'wp-auth0' ), + 'modalButtonText' => ! empty ( $specialSettings['modal_trigger_name'] ) + ? sanitize_text_field( $specialSettings['modal_trigger_name'] ) + : __( 'Login', 'wp-auth0' ), + ), + ) + ); - // This is output in the footer so it can run after wp_head - wp_enqueue_script( 'wpa0_lock', $options->get('passwordless_cdn_url'), array( 'jquery' ), FALSE ); - wp_enqueue_script( 'auth0-pwl', WPA0_PLUGIN_JS_URL . 'login-pwl.js', array( 'jquery' ), WPA0_VERSION, TRUE ); + $login_tpl = apply_filters( 'auth0_login_form_tpl', 'auth0-login-form.php', $lock_options, $canShowLegacyLogin ); + require $login_tpl; - // Set required global var - wp_localize_script( - 'auth0-pwl', - 'wpAuth0PwlGlobal', - array( - 'i18n' => array(), - 'lock' => array( - 'options' => $lock_options->get_lock_options(), - 'ready' => WP_Auth0::ready(), - 'domain' => $options->get( 'domain' ), - 'clientId' => $options->get( 'client_id' ), - ), - ) - ); - - require_once 'auth0-login-form-pwl.php'; - } - } else { - add_action( 'login_footer', array( 'WP_Auth0', 'render_back_to_auth0' ) ); - add_action( 'woocommerce_after_customer_login_form', array( 'WP_Auth0', 'render_back_to_auth0' ) ); - } + } else { + add_action( 'login_footer', array( 'WP_Auth0', 'render_back_to_auth0' ) ); + add_action( 'woocommerce_after_customer_login_form', array( 'WP_Auth0', 'render_back_to_auth0' ) ); + } } \ No newline at end of file