From 1fae68570ae0eb5b9f7f30a6e0babf966dcddf92 Mon Sep 17 00:00:00 2001 From: Jay Oh Date: Thu, 9 Apr 2015 16:40:54 -0700 Subject: [PATCH] Check if username exists when creating a new user. Fixed error message output (self::insertAuth0Error doesn't exist) in get_currentauth0userinfo --- WP_Auth0.php | 5 +---- lib/WP_Auth0_Users.php | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/WP_Auth0.php b/WP_Auth0.php index ec87c846..9257c408 100644 --- a/WP_Auth0.php +++ b/WP_Auth0.php @@ -686,15 +686,12 @@ function get_currentauth0userinfo() { global $wpdb; get_currentuserinfo(); - if ($current_user instanceof WP_User && $current_user->ID > 0 ) { + if ($current_user instanceof WP_User && $current_user->ID > 0) { $sql = 'SELECT auth0_obj FROM ' . $wpdb->auth0_user .' WHERE wp_id = %d'; $result = $wpdb->get_row($wpdb->prepare($sql, $current_user->ID)); if (is_null($result) || $result instanceof WP_Error ) { - - self::insertAuth0Error('get_currentauth0userinfo',$result); - return null; } $currentauth0_user = unserialize($result->auth0_obj); diff --git a/lib/WP_Auth0_Users.php b/lib/WP_Auth0_Users.php index 552f786e..c275515d 100644 --- a/lib/WP_Auth0_Users.php +++ b/lib/WP_Auth0_Users.php @@ -33,9 +33,10 @@ public static function create_user( $userinfo ){ } $username = $userinfo->nickname; - if (empty($username)) { + if (empty($username) || username_exists($username)) { $username = $email; } + // Create the user data array for updating first- and lastname $user_data = array( 'user_email' => $email,