Skip to content

Commit

Permalink
[privacy] [activation] If there is no user during activation shows a …
Browse files Browse the repository at this point in the history
…small form to gather minimum information needed to create a new user.
  • Loading branch information
DanieleAlessandra committed Apr 19, 2024
1 parent bc644c2 commit 4ae2490
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 34 deletions.
29 changes: 26 additions & 3 deletions assets/scss/admin/_gdpr-consent.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#fs_marketing_optin
.fs_gdpr_consent
{
display: none;
margin-top: 10px;
Expand Down Expand Up @@ -62,7 +62,7 @@

.rtl
{
#fs_marketing_optin
.fs_gdpr_consent
{
.fs-input-container
{
Expand All @@ -78,4 +78,27 @@
margin-right: 20px;
}
}
}
}

#fs_personal_data
{
.fs-fields-container {
display: flex;
flex-wrap: wrap;
margin: 0 -15px;

.fs-input-container {
padding: 0 15px;
box-sizing: border-box;
flex: 1 1 50%;

input {
width: 100%;
}

&:last-child {
flex: 1 1 100%;
}
}
}
}
31 changes: 16 additions & 15 deletions includes/class-freemius.php
Original file line number Diff line number Diff line change
Expand Up @@ -13763,7 +13763,10 @@ function _activate_license_ajax_action() {
fs_request_get( 'module_id', null, 'post' ),
fs_request_get( 'user_id', null ),
fs_request_get_bool( 'is_extensions_tracking_allowed', null ),
fs_request_get_bool( 'is_diagnostic_tracking_allowed', null )
fs_request_get_bool( 'is_diagnostic_tracking_allowed', null ),
fs_request_get( 'user_firstname', null ),
fs_request_get( 'user_lastname', null ),
fs_request_get( 'user_email', null )
);

if (
Expand Down Expand Up @@ -14026,7 +14029,10 @@ private function activate_license(
$plugin_id = null,
$license_owner_id = null,
$is_extensions_tracking_allowed = null,
$is_diagnostic_tracking_allowed = null
$is_diagnostic_tracking_allowed = null,
$user_firstname = null,
$user_lastname = null,
$user_email = null
) {
$this->_logger->entrance();

Expand All @@ -14052,7 +14058,8 @@ private function activate_license(
) );

$error = false;
$next_page = false;
$error_code = false;
$next_page = false;

$has_valid_blog_id = is_numeric( $blog_id );

Expand Down Expand Up @@ -14186,9 +14193,9 @@ private function activate_license(
$fs->update_connectivity_info( $is_connected );
} else {
$next_page = $fs->opt_in(
false,
false,
false,
$user_email || false,
$user_firstname || false,
$user_lastname || false,
$license_key,
false,
false,
Expand All @@ -14199,6 +14206,7 @@ private function activate_license(

if ( isset( $next_page->error ) ) {
$error = $next_page->error;
$error_code = $next_page->code;
} else {
if ( $is_network_activation_or_migration ) {
/**
Expand Down Expand Up @@ -14267,6 +14275,7 @@ private function activate_license(

if ( false !== $error ) {
$result['error'] = $fs->apply_filters( 'opt_in_error_message', $error );
$result['error_code'] = $error_code;
} else {
if ( $fs->is_addon() || $fs->has_addons() ) {
/**
Expand Down Expand Up @@ -17214,9 +17223,6 @@ function get_opt_in_params( $override_with = array(), $network_level_or_blog_id
$versions = $this->get_versions();

$params = array_merge( $versions, array(
'user_firstname' => $current_user->user_firstname,
'user_lastname' => $current_user->user_lastname,
'user_email' => $current_user->user_email,
'plugin_slug' => $this->_slug,
'plugin_id' => $this->get_id(),
'plugin_public_key' => $this->get_public_key(),
Expand Down Expand Up @@ -17329,11 +17335,6 @@ function opt_in(
) {
$this->_logger->entrance();

if ( false === $email ) {
$current_user = self::_get_current_wp_user();
$email = $current_user->user_email;
}

/**
* @since 1.2.1 If activating with license key, ignore the context-user
* since the user will be automatically loaded from the license.
Expand Down Expand Up @@ -21349,7 +21350,7 @@ private function _sync_plugin_license(
* associated with that ID is not included in the user's licenses collection.
* Save previous value to manage remote license renewals.
*/
$was_license_expired_before_sync = $this->_license->is_expired();
$was_license_expired_before_sync = $this->_license && $this->_license->is_expired();
$this->_sync_licenses(
$site->license_id,
( $is_context_single_site ?
Expand Down
5 changes: 1 addition & 4 deletions templates/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,10 @@
} else {
$current_user = Freemius::_get_current_wp_user();

// Add site and user info to the request, this information
// Add site info to the request, this information
// is NOT being stored unless the user complete the purchase
// and agrees to the TOS.
$context_params = array_merge( $context_params, array(
'user_firstname' => $current_user->user_firstname,
'user_lastname' => $current_user->user_lastname,
'user_email' => $current_user->user_email,
'home_url' => home_url(),
) );

Expand Down
74 changes: 62 additions & 12 deletions templates/connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,34 @@ class="wrap<?php if ( ! fs_is_network_admin() && ( ! $fs->is_enable_anonymous()
)
);
?>
<div id="fs_marketing_optin">
<!-- BEGIN EXPLICIT DATA FIELDS -->
<div id="fs_personal_data" class="fs_gdpr_consent">
<!--
The fields below are used to explicitly collect missing information in cases where it is not possible
to assign an existing user to the license being activated. This was done to avoid sending private data
in any case.
-->
<span class="fs-message"><?php fs_echo_inline( "Please enter at least a valid email address to activate your license:",
'email-is-requested' ) ?></span>
<div class="fs-fields-container">
<div class="fs-input-container">
<label for="first_name" class="screen-reader-text">First name</label>
<input type="text" id="first_name" name="first_name" placeholder="First name"
class="fs-input">
</div>
<div class="fs-input-container">
<label for="last_name" class="screen-reader-text">Last name</label>
<input type="text" id="last_name" name="last_name" placeholder="Last name" class="fs-input">
</div>
<div class="fs-input-container">
<label for="user_email" class="screen-reader-text">Email (required)</label>
<input type="email" id="user_email" name="user_email" placeholder="Email (required)"
class="fs-input" required>
</div>
</div>
</div>
<!-- END EXPLICIT DATA FIELDS -->
<div id="fs_marketing_optin" class="fs_gdpr_consent">
<span class="fs-message"><?php fs_echo_inline( "Please let us know if you'd like us to contact you for security & feature updates, educational content, and occasional offers:", 'contact-for-updates' ) ?></span>
<div class="fs-input-container">
<label>
Expand Down Expand Up @@ -525,6 +552,11 @@ class="button button-secondary" tabindex="2"><?php fs_esc_html_echo_x_inline( 'S
$( document.body ).addClass( 'fs-loading' );
};

$('#fs_personal_data input').on('focus', function() {
$('#fs_personal_data').removeClass('error');
resetLoadingMode();
})

$('.fs-actions .button').on('click', function () {
setLoadingMode();

Expand Down Expand Up @@ -697,6 +729,19 @@ function updatePrimaryCtaText( actionType ) {
var ajaxOptin = ( requireLicenseKey || isNetworkActive );

$form.on('submit', function () {
const personal_data = {};
if ($personalData.is(':visible')) {
const email_field = document.querySelector('#user_email');
if (!email_field.checkValidity()) {
$personalData.addClass( 'error' ).show();
resetLoadingMode();
return false;
} else {
personal_data.user_firstname = $('#first_name').val();
personal_data.user_lastname = $('#last_name').val();
personal_data.user_email = $(email_field).val();
}
}
var $extensionsPermission = $( '#fs_permission_extensions .fs-switch' ),
isExtensionsTrackingAllowed = ( $extensionsPermission.length > 0 ) ?
$extensionsPermission.hasClass( 'fs-on' ) :
Expand Down Expand Up @@ -743,7 +788,8 @@ function updatePrimaryCtaText( actionType ) {
action : action,
security : security,
license_key: licenseKey,
module_id : '<?php echo $fs->get_id() ?>'
module_id : '<?php echo $fs->get_id() ?>',
...personal_data
};

if (
Expand Down Expand Up @@ -827,15 +873,17 @@ function updatePrimaryCtaText( actionType ) {
method : 'POST',
data : data,
success: function (result) {
var resultObj = $.parseJSON(result);
if (resultObj.success) {
// Redirect to the "Account" page and sync the license.
window.location.href = resultObj.next_page;
} else {
resetLoadingMode();

// Show error.
$('.fs-content').prepend('<div class="fs-error">' + (resultObj.error.message ? resultObj.error.message : resultObj.error) + '</div>');
var resultObj = $.parseJSON(result);
if (resultObj.success) {
// Redirect to the "Account" page and sync the license.
window.location.href = resultObj.next_page;
} else {
resetLoadingMode();
// Show error.
$('.fs-content').prepend('<div class="fs-error">' + (resultObj.error.message ? resultObj.error.message : resultObj.error) + '</div>');
if (resultObj.error_code === 'empty_email') {
$('#fs_personal_data').show();
}
}
},
error: function () {
Expand Down Expand Up @@ -960,6 +1008,7 @@ function updatePrimaryCtaText( actionType ) {
//--------------------------------------------------------------------------------
var isMarketingAllowedByLicense = {},
$marketingOptin = $('#fs_marketing_optin'),
$personalData = $('#fs_personal_data')
previousLicenseKey = null;

if (requireLicenseKey) {
Expand Down Expand Up @@ -1034,11 +1083,12 @@ function updatePrimaryCtaText( actionType ) {

$marketingOptin.find( 'input' ).click(function() {
$marketingOptin.removeClass( 'error' );
$personalData.removeClass( 'error' );
});
}

//endregion
})(jQuery);
</script>
<?php
fs_require_once_template( 'api-connectivity-message-js.php' );
fs_require_once_template( 'api-connectivity-message-js.php' );

0 comments on commit 4ae2490

Please sign in to comment.