Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A0 widget #16

Merged
merged 55 commits into from
Oct 8, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2f616bc
Fix for legacy php versions
glena Sep 27, 2014
e5867b5
A0 widget
glena Sep 26, 2014
21d10b6
Fix to allow to show multiple times the auth0 login form in the same …
glena Sep 26, 2014
b5a36ec
fix
glena Sep 26, 2014
dd2c202
plugin version updated
glena Sep 26, 2014
9c5ff93
upgraded to lock :)
glena Sep 26, 2014
e49b940
upgrade cdn settings to use the lock widget
glena Sep 26, 2014
8af498e
Merge remote-tracking branch 'origin/a0-widget' into a0-widget
glena Sep 27, 2014
b823c8d
Fix for legacy php versions
glena Sep 29, 2014
49a7b54
New settings management
glena Sep 30, 2014
68e09ae
agregado de configuracion
glena Sep 30, 2014
479c34c
change the way it generates the json configuration
glena Sep 30, 2014
9973cbc
added dict + extra settings
glena Oct 1, 2014
cc89ecb
added widget configurations
glena Oct 1, 2014
345cc9d
update version
glena Sep 30, 2014
58d1bf6
fix hidden WP login form when the plugin is disabled
glena Oct 1, 2014
2bae772
upgrade the plugin revision
glena Oct 1, 2014
8349e67
fix
glena Sep 26, 2014
d088c60
A0 widget
glena Sep 26, 2014
a2a362d
fix
glena Sep 26, 2014
0d0c582
upgraded to lock :)
glena Sep 26, 2014
84f5d09
agregado de configuracion
glena Sep 30, 2014
30facef
fix hidden WP login form when the plugin is disabled
glena Oct 1, 2014
f9c6784
the widget now has its own settings! :)
glena Oct 1, 2014
3a39a9f
now the widget can be shown as a modal! :D
glena Oct 2, 2014
2c62c15
shortCode with settings & modal
glena Oct 2, 2014
347dc53
fix the way that the modal is shown (by error it was setted as popup)
glena Oct 2, 2014
b2b5275
updated settings and readme
glena Oct 4, 2014
7529736
fix js changes
glena Oct 4, 2014
f975bfc
change the widget settings form to allow the user to select which opt…
glena Oct 4, 2014
a3b8157
fixes for the shortcode
glena Oct 4, 2014
594a97d
fixes :)
glena Oct 4, 2014
1544fc8
update version
glena Sep 30, 2014
106a829
fix hidden WP login form when the plugin is disabled
glena Oct 1, 2014
607c4ae
upgrade the plugin revision
glena Oct 1, 2014
41434d5
A0 widget
glena Sep 26, 2014
f53f4b5
Fix to allow to show multiple times the auth0 login form in the same …
glena Sep 26, 2014
7b683e5
fix
glena Sep 26, 2014
7cdd8e5
upgraded to lock :)
glena Sep 26, 2014
2a77e29
A0 widget
glena Sep 26, 2014
362f6a9
Fix to allow to show multiple times the auth0 login form in the same …
glena Sep 26, 2014
a48ce05
fix
glena Sep 26, 2014
e35b5b3
New settings management
glena Sep 30, 2014
d4ea519
agregado de configuracion
glena Sep 30, 2014
bfa0c97
added dict + extra settings
glena Oct 1, 2014
3147493
fix hidden WP login form when the plugin is disabled
glena Oct 1, 2014
d10006c
fix
glena Sep 26, 2014
2e57d26
agregado de configuracion
glena Sep 30, 2014
ac6159f
fix hidden WP login form when the plugin is disabled
glena Oct 1, 2014
75ebd3d
the widget now has its own settings! :)
glena Oct 1, 2014
36640dd
now the widget can be shown as a modal! :D
glena Oct 2, 2014
d6f6be9
removed fields, added fields, added descriptions and links
glena Oct 7, 2014
fcc4a42
changes to the plugin and screenshots added
glena Oct 7, 2014
fa7c512
fix widget as modal
glena Oct 7, 2014
8d4e4cb
screenshots added
glena Oct 7, 2014
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
Prev Previous commit
Next Next commit
removed fields, added fields, added descriptions and links
  • Loading branch information
glena committed Oct 7, 2014
commit d6f6be9a0608a3d2236cd69053b24a45192f70ed
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Example:
[auth0 show_as_modal="true" social_big_buttons="true" modal_trigger_name="Login button: This text is configurable!"]


All the details about the parameters on the lock wiki (https://github.com/auth0/lock/wiki/Auth0Lock-customization#dict-stringobject)
All the details about the parameters on the lock wiki (https://github.com/auth0/lock/wiki/Auth0Lock-customization)

## FAQs

Expand Down Expand Up @@ -120,7 +120,7 @@ To change the form_title in this case, you need to add the following attribute t

We added a new field called "Extra settings" that allows you to add a json object with all the settings you want to configure.

Have in mind that all the "Extra settings" that we allow to set up in the plugin settings page will be overrided.
Have in mind that all the "Extra settings" that we allow to set up in the plugin settings page will be overrided (For more information about it: https://github.com/auth0/widget).

## Screenshots

Expand Down
66 changes: 36 additions & 30 deletions WP_Auth0.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,27 @@ public static function init(){

add_action( 'widgets_init', array(__CLASS__, 'wp_register_widget'));

$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_$plugin", array(__CLASS__, 'wp_add_plugin_settings_link'));

WP_Auth0_Admin::init();
}

// Add settings link on plugin page
public static function wp_add_plugin_settings_link($links) {
$settings_link = '<a href="options-general.php?page=wpa0">Settings</a>';
array_unshift($links, $settings_link);
return $links;
}

public static function wp_register_widget() {
register_widget( 'wp_auth0_widget' );
}

public static function wp_enqueue(){
$activated = absint(WP_Auth0_Options::get( 'active' ));
$client_id = WP_Auth0_Options::get('client_id');

if(!$activated) {
return;
}
if (trim($client_id) == "") return;

wp_enqueue_style( 'auth0-widget', WPA0_PLUGIN_URL . 'assets/css/main.css' );
}
Expand Down Expand Up @@ -117,11 +125,20 @@ public static function render_back_to_auth0() {

}

protected static function GetBoolean($value)
{
return ($value == 1 || strtolower($value) == 'true');
}
protected static function IsValid($array, $key)
{
return (isset($array[$key]) && trim($array[$key]) != '');
}
public static function buildSettings($settings)
{
$options_obj = array();

if (isset($settings['dict']) && isset($settings['form_title']) && trim($settings['dict']) == '' && trim($settings['form_title']) != '') {
if (isset($settings['form_title']) &&
(!isset($settings['dict']) || (isset($settings['dict']) && trim($settings['dict']) == '')) &&
trim($settings['form_title']) != '') {
$options_obj['dict'] = array(
"signin" => array(
"title" => $settings['form_title']
Expand All @@ -136,52 +153,41 @@ public static function buildSettings($settings)
$options_obj['dict'] = $settings['dict'];
}
}

if (isset($settings['social_big_buttons'])) {
$options_obj['socialBigButtons'] = $settings['social_big_buttons'] == 1;
if (self::IsValid($settings,'social_big_buttons')) {
$options_obj['socialBigButtons'] = self::GetBoolean($settings['social_big_buttons']);
}

if (isset($settings['gravatar'])) {
$options_obj['gravatar'] = $settings['gravatar'] == 1;
if (self::IsValid($settings,'gravatar')) {
$options_obj['gravatar'] = self::GetBoolean($settings['gravatar']);
}

if (isset($settings['username_style'])) {
if (self::IsValid($settings,'username_style')) {
$options_obj['usernameStyle'] = $settings['username_style'];
}

if (isset($settings['remember_last_login'])) {
$options_obj['rememberLastLogin'] = $settings['remember_last_login'] == 1;
if (self::IsValid($settings,'remember_last_login')) {
$options_obj['rememberLastLogin'] = self::GetBoolean($settings['remember_last_login']);
}

if (isset($settings['show_icon']) && $settings['show_icon'] == 1) {
if (self::IsValid($settings,'icon_url')) {
$options_obj['icon'] = $settings['icon_url'];
}

if (isset($settings['extra_conf']) && trim($settings['extra_conf']) != '') {
$extra_conf_arr = json_decode($settings['extra_conf'], true);
$options_obj = array_merge( $extra_conf_arr, $options_obj );
$options_obj = array_merge( $extra_conf_arr, $options_obj );
}

return $options_obj;

}

public static function render_auth0_login_css() {
$activated = absint(WP_Auth0_Options::get( 'active' ));
$client_id = WP_Auth0_Options::get('client_id');

if(!$activated) {
return;
}
if (trim($client_id) == "") return;
?>
<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' )) == 1;
$client_id = WP_Auth0_Options::get('client_id');

if(!$activated)
return $html;
if (trim($client_id) == "") return;

ob_start();

Expand Down
69 changes: 39 additions & 30 deletions lib/WP_Auth0_Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ protected static function init_option_section($sectionName, $settings)

foreach ($settings as $setting)
{
if (!isset($setting['enabled']) || $setting['enabled']){
add_settings_field(
$setting['id'],
__($setting['name'], WPA0_LANG),
array(__CLASS__, $setting['function']),
WP_Auth0_Options::OPTIONS_NAME,
"wp_auth0_{$lowerName}_settings_section",
array('label_for' => $setting['id'])
);
}
add_settings_field(
$setting['id'],
__($setting['name'], WPA0_LANG),
array(__CLASS__, $setting['function']),
WP_Auth0_Options::OPTIONS_NAME,
"wp_auth0_{$lowerName}_settings_section",
array('label_for' => $setting['id'])
);
}
}

Expand All @@ -52,7 +50,6 @@ public static function init_admin(){

self::init_option_section('Basic', array(

array('id' => 'wpa0_active', 'name' => 'Activate Auth0', 'function' => 'render_activate'),
array('id' => 'wpa0_domain', 'name' => 'Domain', 'function' => 'render_domain'),
array('id' => 'wpa0_client_id', 'name' => 'Client ID', 'function' => 'render_client_id'),
array('id' => 'wpa0_client_secret', 'name' => 'Client Secret', 'function' => 'render_client_secret'),
Expand All @@ -66,33 +63,45 @@ public static function init_admin(){

array('id' => 'wpa0_form_title', 'name' => 'Form Title', 'function' => 'render_form_title'),
array('id' => 'wpa0_social_big_buttons', 'name' => 'Show big social buttons', 'function' => 'render_social_big_buttons'),
array('id' => 'wpa0_show_icon', 'name' => 'Show Icon', 'function' => 'render_show_icon'),
array('id' => 'wpa0_icon_url', 'name' => 'Icon URL', 'function' => 'render_icon_url'),
array('id' => 'wpa0_gravatar', 'name' => 'Enable Gravatar integration', 'function' => 'render_gravatar'),

));

/* ------------------------- ADVANCED ------------------------- */

$use_ip_ranges = absint(WP_Auth0_Options::get( 'ip_range_check' )) == 1;

self::init_option_section('Advanced', array(

array('id' => 'wpa0_dict', 'name' => 'Translation', 'function' => 'render_dict'),
array('id' => 'wpa0_username_style', 'name' => 'Username style', 'function' => 'render_username_style'),
array('id' => 'wpa0_remember_last_login', 'name' => 'Remember last login', 'function' => 'render_remember_last_login'),
array('id' => 'wpa0_verified_email', 'name' => 'Requires verified email', 'function' => 'render_verified_email'),
array('id' => 'wpa0_allow_signup', 'name' => 'Allow signup', 'function' => 'render_allow_signup'),
array('id' => 'wpa0_auto_login', 'name' => 'Auto Login (no widget)', 'function' => 'render_auto_login'),
array('id' => 'wpa0_auto_login_method', 'name' => 'Auto Login Method', 'function' => 'render_auto_login_method'),
array('id' => 'wpa0_ip_range_check', 'name' => 'Enable on IP Ranges', 'function' => 'render_ip_range_check'),
array('id' => 'wpa0_ip_ranges', 'name' => 'IP Ranges', 'function' => 'render_ip_ranges', 'enabled' => $use_ip_ranges),
array('id' => 'wpa0_ip_ranges', 'name' => 'IP Ranges', 'function' => 'render_ip_ranges'),
array('id' => 'wpa0_extra_conf', 'name' => 'Extra settings', 'function' => 'render_extra_conf'),
array('id' => 'wpa0_cdn_url', 'name' => 'Widget URL', 'function' => 'render_cdn_url'),

));

register_setting(WP_Auth0_Options::OPTIONS_NAME, WP_Auth0_Options::OPTIONS_NAME, array(__CLASS__, 'input_validator'));
}

public static function render_extra_conf(){
$v = WP_Auth0_Options::get( 'extra_conf' );
echo '<textarea name="' . WP_Auth0_Options::OPTIONS_NAME . '[extra_conf]" id="wpa0_extra_conf">' . esc_attr( $v ) . '</textarea>';
echo '<br/><span class="description">' . __('This field should be a valid json with any setting that is not editable here. Other options will override this settings.', WPA0_LANG)
. '<br/>' . __('(IE: {"disableResetAction": true }) ', WPA0_LANG)
. '<a href="https://github.com/auth0/lock/wiki/Auth0Lock-customization">' . __('More info', WPA0_LANG) . '</a></span>';
}
public static function render_remember_last_login () {
$v = absint(WP_Auth0_Options::get( 'remember_last_login' ));
echo '<input type="checkbox" name="' . WP_Auth0_Options::OPTIONS_NAME . '[remember_last_login]" id="wpa0_remember_last_login" value="1" ' . checked( $v, 1, false ) . '/>';
echo '<br/><span class="description">' . __('Request for SSO data and enable Last time you signed in with[...] message.', WPA0_LANG) . '<a href="https://github.com/auth0/lock/wiki/Auth0Lock-customization#rememberlastlogin-boolean">' . __('More info', WPA0_LANG) . '</a></span>';
}

public static function render_client_id(){
$v = WP_Auth0_Options::get( 'client_id' );
echo '<input type="text" name="' . WP_Auth0_Options::OPTIONS_NAME . '[client_id]" id="wpa0_client_id" value="' . esc_attr( $v ) . '"/>';
Expand All @@ -118,7 +127,7 @@ public static function render_form_title(){
public static function render_dict(){
$v = WP_Auth0_Options::get( 'dict' );
echo '<textarea name="' . WP_Auth0_Options::OPTIONS_NAME . '[dict]" id="wpa0_dict">' . esc_attr( $v ) . '</textarea>';
echo '<br/><span class="description">' . __('This is the widget\'s dict param.', WPA0_LANG) . '<br><a href="https://github.com/auth0/lock/wiki/Auth0Lock-customization#dict-stringobject">' . __('More info', WPA0_LANG) . '</a></span>';
echo '<br/><span class="description">' . __('This is the widget\'s dict param.', WPA0_LANG) . '<a target="_blank" href="https://github.com/auth0/lock/wiki/Auth0Lock-customization#dict-stringobject">' . __('More info', WPA0_LANG) . '</a></span>';
}

public static function render_username_style(){
Expand All @@ -128,12 +137,10 @@ public static function render_username_style(){
echo ' ';
echo '<input type="radio" name="' . WP_Auth0_Options::OPTIONS_NAME . '[username_style]" id="wpa0_username_style_username" value="username" ' . (esc_attr( $v ) == 'username' ? 'checked="true"' : '') . '"/>';
echo '<label for="wpa0_username_style_username">' . __('Username', WPA0_LANG) . '</label>';
}

public static function render_activate(){
$v = absint(WP_Auth0_Options::get( 'active' ));
echo '<input type="checkbox" name="' . WP_Auth0_Options::OPTIONS_NAME . '[active]" id="wpa0_active" value="1" ' . checked( $v, 1, false ) . '/>';
echo '<br/><span class="description">' . __('If you don\'t want to validate that the user enters an email, just set this to username.', WPA0_LANG) . '<a target="_blank" href="https://github.com/auth0/lock/wiki/Auth0Lock-customization#usernamestyle-string">' . __('More info', WPA0_LANG) . '</a></span>';
}

public static function render_auto_login(){
$v = absint(WP_Auth0_Options::get( 'auto_login' ));
echo '<input type="checkbox" name="' . WP_Auth0_Options::OPTIONS_NAME . '[auto_login]" id="wpa0_auto_login" value="1" ' . checked( $v, 1, false ) . '/>';
Expand All @@ -153,10 +160,6 @@ public static function render_ip_ranges(){
echo '<textarea cols="25" name="' . WP_Auth0_Options::OPTIONS_NAME . '[ip_ranges]" id="wpa0_ip_ranges">' . esc_textarea( $v ) . '</textarea>';
echo '<br/><span class="description">' . __('Only one range per line! Range format should be as: <code>xx.xx.xx.xx - yy.yy.yy.yy</code> (spaces will be trimmed)', WPA0_LANG) . '</span>';
}
public static function render_show_icon(){
$v = absint(WP_Auth0_Options::get( 'show_icon' ));
echo '<input type="checkbox" name="' . WP_Auth0_Options::OPTIONS_NAME . '[show_icon]" id="wpa0_show_icon" value="1" ' . checked( $v, 1, false ) . '/>';
}

public static function render_social_big_buttons(){
$v = absint(WP_Auth0_Options::get( 'social_big_buttons' ));
Expand Down Expand Up @@ -228,18 +231,16 @@ public static function input_validator( $input ){
'http',
'https'
));
if(empty($input['icon_url']))
$input['show_icon'] = 0;
else
$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);

$input['social_big_buttons'] = (isset($input['social_big_buttons']) ? 1 : 0);
$input['gravatar'] = (isset($input['gravatar']) ? 1 : 0);

$input['remember_last_login'] = (isset($input['remember_last_login']) ? 1 : 0);

$error = "";
if (empty($input["domain"]) ) {
$error = __("You need to specify domain", WPA0_LANG);
Expand All @@ -255,7 +256,15 @@ public static function input_validator( $input ){
{
if (strpos($input["dict"], '{') !== false && json_decode($input["dict"]) === null)
{
$error = __("The dict parameter should be a valid json object", WPA0_LANG);
$error = __("The Translation parameter should be a valid json object", WPA0_LANG);
}
}

if (trim($input["extra_conf"]) != '')
{
if (json_decode($input["extra_conf"]) === null)
{
$error = __("The Extra settings parameter should be a valid json object", WPA0_LANG);
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/WP_Auth0_Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ public static function set( $key, $value ){
private static function defaults(){
return array(
'version' => 1,
'active' => 0,
'auto_login' => 0,
'auto_login_method' => '',
'client_id' => '',
'client_secret' => '',
'domain' => '',
'form_title' => '',
'show_icon' => 0,
'icon_url' => '',
'ip_range_check' => 0,
'ip_ranges' => '',
Expand All @@ -53,8 +51,10 @@ private static function defaults(){
'allow_signup' => true,
'wordpress_login_enabled' => true,
'dict' => '',
'social_big_buttons' => true,
'social_big_buttons' => false,
'username_style' => 'email',
'extra_conf' => '',
'remember_last_login' => true,
'gravatar' => true,
);
}
Expand Down
20 changes: 19 additions & 1 deletion lib/WP_Auth0_Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class WP_Auth0_Widget extends WP_Widget {
function __construct() {
parent::__construct(
'wp_auth0_widget',
__('Auth0 login widget', 'wp_auth0_widget_domain'),
__('Auth0 Login widget', 'wp_auth0_widget_domain'),
array( 'description' => __( 'Auth0 widget to embed the login form.', 'wpb_widget_domain' ), )
);
}
Expand Down Expand Up @@ -43,6 +43,24 @@ public function widget( $args, $instance ) {
}

}

public function update( $new_instance, $old_instance ) {
if (trim($new_instance["dict"]) != '')
{
if (strpos($new_instance["dict"], '{') !== false && json_decode($new_instance["dict"]) === null)
{
$new_instance["dict"] = $old_instance["dict"];
}
}
if (trim($new_instance["extra_conf"]) != '')
{
if (json_decode($new_instance["extra_conf"]) === null)
{
$new_instance["extra_conf"] = $old_instance["extra_conf"];
}
}
return $new_instance;
}
}


2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Example:

[auth0 show_as_modal="true" social_big_buttons="true" modal_trigger_name="Login button: This text is configurable!"]

All the details about the parameters on the lock wiki (https://github.com/auth0/lock/wiki/Auth0Lock-customization#dict-stringobject)
All the details about the parameters on the lock wiki (https://github.com/auth0/lock/wiki/Auth0Lock-customization)

== Frequently Asked Questions ==

Expand Down
Loading