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 32 commits
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
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,44 @@ For both scenarios you may configure in the WP admin whether is mandatory that t

You can access the rich user profile information coming from the Identity Providers. **WordPress** defines a function called `get_currentuserinfo` to populate the global variable `current_user` with the logged in `WP_User`. Similary we define `get_currentauth0userinfo` that populates `current_user` and `currentauth0_user` with the information of the Normalized profile.

### Enabling dual (Auth0 and Wordpress) login

You can enable the standard Wordpress login by turning on the "WordPress login enabled" setting (enabled by default). This will make visible a link on the login page to swap between both.

### Using the plugin widget

You can enable the Auth0 as a Wordpress widget in order to show it in the sidebar. The widget inherits the plugin settings and it can be overrided with its own settings.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put a picture of how to active Auth0 Widget and where you see the configs?


Also, a new layout setting is enabled in order to be shown as a modal. Enabling the "Show as modal" setting, a button which trigger the modal is generated.

### Using the login widget as a shortcode

Also, you can use the Auth0 widget as a shortcode in your posts.

The way to use it is just adding the following:

[auth0]

And can be customized by adding the following parameters:

* form_title: string
* dict: string, should be a the language or a valid json with the translation (see https://github.com/auth0/lock/wiki/Auth0Lock-customization#dict-stringobject)
* social_big_buttons: boolean
* gravatar: boolean
* username_style: string, "email" or "username"
* remember_last_login: boolean
* icon_url: string (valid url)
* extra_conf: string, valid json
* show_as_modal: boolean
* modal_trigger_name: string, button text

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link to the main wiki instead of #dict here


## FAQs

### What should I do if I end up with two accounts for the same user?
Expand Down Expand Up @@ -66,6 +104,24 @@ For a complete list look at https://docs.auth0.com/identityproviders

If you get this error, make sure you are requesting the Email attribute from each provider in the Auth0 Dashboard under Connections -> Social (expand each provider). Take into account that not all providers return Email addresses for users (e.g. Twitter). If this happens, you can always add an Email address to any logged in user through the Auth0 Dashbaord (pr API). See Users -> Edit.

### The form_title setting is ignored when I set up the dict setting

Internally, the plugin uses the dict setting to change the Auth0 widget title. When you set up the dict field it overrides the form_title one.

To change the form_title in this case, you need to add the following attribute to the dict json:

{
signin:{
title: "The desired form title"
}
}

### How can I set up the settings that are not provided in the settings page?

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link here to Lock customization wiki as well


## Screenshots

![](https://raw.githubusercontent.com/auth0/wp-auth0/master/screenshot-1.png)
Expand Down
88 changes: 80 additions & 8 deletions WP_Auth0.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Wordpress Auth0 Integration
* Description: Implements the Auth0 Single Sign On solution into Wordpress
* Version: 1.0.8
* Version: 1.1.0
* Author: Auth0
* Author URI: https://auth0.com
*/
Expand Down Expand Up @@ -61,6 +61,7 @@ public static function wp_register_widget() {

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

if(!$activated) {
return;
}
Expand All @@ -69,10 +70,15 @@ public static function wp_enqueue(){
}

public static function shortcode( $atts ){

$settings = WP_Auth0::buildSettings($atts);
$settings[ 'show_as_modal' ] = (isset($atts[ 'show_as_modal' ]) && strtolower($atts[ 'show_as_modal' ]) == 'true' ? 1 : false);
$settings[ 'modal_trigger_name' ] = (isset($atts[ 'modal_trigger_name' ]) ? $atts[ 'modal_trigger_name' ] : 'Login');

ob_start();

require_once WPA0_PLUGIN_DIR . 'templates/login-form.php';
renderAuth0Form(false);
renderAuth0Form(false, $settings);

$html = ob_get_clean();
return $html;
Expand Down Expand Up @@ -116,12 +122,79 @@ public static function render_back_to_auth0() {

}

public static function render_auth0_login_css() { ?>
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['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']
)
);
}
elseif (isset($settings['dict']) && trim($settings['dict']) != '') {
if ($oDict = json_decode($settings['dict'], true)) {
$options_obj['dict'] = $oDict;
}
else{
$options_obj['dict'] = $settings['dict'];
}
}

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

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

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

if (self::IsValid($settings,'show_icon') && isset($settings['icon_url'])) {
$options_obj['icon'] = self::GetBoolean($settings['show_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 );
}

return $options_obj;

}

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

if(!$activated) {
return;
}
?>
<link rel='stylesheet' href='<?php echo plugins_url( 'assets/css/login.css', __FILE__ ); ?>' type='text/css' />
<?php }
<?php
}

public static function render_form( $html ){
$activated = absint(WP_Auth0_Options::get( 'active' ));
$activated = absint(WP_Auth0_Options::get( 'active' )) == 1;

if(!$activated)
return $html;
Expand Down Expand Up @@ -357,11 +430,10 @@ public static function wp_init(){
self::setup_rewrites();

$cdn_url = WP_Auth0_Options::get('cdn_url');

if (strpos($cdn_url, 'w2/auth0-widget') !== false)
if (strpos($cdn_url, 'auth0-widget-5') !== false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will we be able to update Lock version as well in every future WP update if we want? Something like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to upgrade from auth0-widget-5 to lock. Right now, it is tied to lock-6.min.js and will be updated until the next major release.

If we want to force the update, I added an internal version counter (other than the AUTH0_DB_VERSION) to manage the settings updates.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!


Martin Gontovnikas
Software Engineer
Buenos Aires, Argentina

Twitter: @mgonto (https://twitter.com/mgonto)
Linkedin: http:https://www.linkedin.com/in/mgonto
Github: https://github.com/mgonto

On Monday, 6 de October de 2014 at 11:49, Germán Lena wrote:

In WP_Auth0.php:

@@ -345,6 +428,14 @@ private static function login_user( $userinfo, $data ){ > > public static function wp_init(){ > self::setup_rewrites(); > + > + $cdn_url = WP_Auth0_Options::get('cdn_url'); > + if (strpos($cdn_url, 'auth0-widget-5') !== false)
this is to upgrade from auth0-widget-5 to lock. Right now, it is tied to lock-6.min.js and will be updated until the next major release.
If we want to force the update, I added an internal version counter (other than the AUTH0_DB_VERSION) to manage the settings updates.


Reply to this email directly or view it on GitHub (https://github.com/auth0/wp-auth0/pull/16/files#r18460630).

{
WP_Auth0_Options::set( 'cdn_url', '//cdn.auth0.com/js/lock-6.min.js' );
WP_Auth0_Options::set( 'version', 1 );
//WP_Auth0_Options::set( 'version', 1 );
}

// Initialize session
Expand Down
4 changes: 3 additions & 1 deletion assets/css/login.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ body.a0-widget-open>* {
margin: auto;
}
#auth0-login-form {
margin-bottom: 20px;
width: 280px;
margin: auto;
}
#auth0-login-form {
min-height: 250px;
}
.auth0-login{
margin-bottom: 20px;
}
10 changes: 9 additions & 1 deletion assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ jQuery(document).ready(function($) {
if (typeof(media_frame)!=="undefined")
media_frame.close();

var related_control_id = 'wpa0_icon_url';
if (typeof($(this).attr('related')) != 'undefined' &&
$(this).attr('related') != '')
{
related_control_id = $(this).attr('related');
}

//Create WP media frame.
media_frame = wp.media.frames.customHeader = wp.media({
title: wpa0.media_title,
Expand All @@ -22,7 +29,8 @@ jQuery(document).ready(function($) {
// Set the frame callback
media_frame.on('select', function() {
var attachment = media_frame.state().get('selection').first().toJSON();
$('#wpa0_icon_url').val(attachment.url);
$('#'+related_control_id).val(attachment.url);
console.log($('#'+related_control_id));
});

//Open modal
Expand Down
Loading