Skip to content

Commit

Permalink
bugfix license API
Browse files Browse the repository at this point in the history
  • Loading branch information
froger-me committed Jan 8, 2024
1 parent 3834f73 commit 6470d5b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
55 changes: 34 additions & 21 deletions inc/class-wppus-license-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,24 +283,30 @@ public function activate( $license_data ) {
}

if ( empty( $result ) ) {
$payload = array(
$payload = array(
'id' => $license->id,
'status' => 'activated',
'allowed_domains' => array_unique( array_merge( $license_data['allowed_domains'], $license->allowed_domains ) ),
);
$result = $this->license_server->edit_license(
$result = $this->license_server->edit_license(
apply_filters( 'wppus_activate_license_payload', $payload )
);
$result->license_signature = $this->license_server->generate_license_signature( $license, reset( $license_data['allowed_domains'] ) );
$raw_result = clone $result;

unset( $result->hmac_key );
unset( $result->crypto_key );
unset( $result->data );
unset( $result->owner_name );
unset( $result->email );
unset( $result->company_name );
unset( $result->id );

if ( is_object( $result ) ) {
$result->license_signature = $this->license_server->generate_license_signature( $license, reset( $license_data['allowed_domains'] ) );

unset( $result->hmac_key );
unset( $result->crypto_key );
unset( $result->data );
unset( $result->owner_name );
unset( $result->email );
unset( $result->company_name );
unset( $result->id );

$raw_result = clone $result;
} else {
$raw_result = $result;
}
}
} else {
$result['license_key'] = isset( $license_data['license_key'] ) ?
Expand Down Expand Up @@ -373,15 +379,22 @@ public function deactivate( $license_data ) {
$result = $this->license_server->edit_license(
apply_filters( 'wppus_deactivate_license_payload', $payload )
);
$raw_result = clone $result;

unset( $result->hmac_key );
unset( $result->crypto_key );
unset( $result->data );
unset( $result->owner_name );
unset( $result->email );
unset( $result->company_name );
unset( $result->id );

if ( is_object( $result ) ) {
$result->license_signature = $this->license_server->generate_license_signature( $license, reset( $license_data['allowed_domains'] ) );

unset( $result->hmac_key );
unset( $result->crypto_key );
unset( $result->data );
unset( $result->owner_name );
unset( $result->email );
unset( $result->company_name );
unset( $result->id );

$raw_result = clone $result;
} else {
$raw_result = $result;
}
}
} else {
$result['license_key'] = isset( $license_data['license_key'] ) ? $license_data['license_key'] : false;
Expand Down
8 changes: 4 additions & 4 deletions inc/class-wppus-license-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ protected function sanitize_payload( $license ) {

foreach ( $value as $index => $domain ) {

if ( ! filter_var( 'admin@' . $domain, FILTER_VALIDATE_EMAIL ) ) {
if ( ! is_scalar( $domain ) || 5 > strlen( strval( $domain ) ) ) {
unset( $license['allowed_domains'][ $index ] );
}
}
Expand Down Expand Up @@ -811,10 +811,10 @@ protected function validate_license_payload( $license, $partial = false ) {
$errors[] = __( 'The allowed domains must be an array.', 'wppus' );
} elseif ( ! empty( $license['allowed_domains'] ) ) {

foreach ( $license['allowed_domains'] as $key => $value ) {
foreach ( $license['allowed_domains'] as $value ) {

if ( ! filter_var( 'admin@' . $value, FILTER_VALIDATE_EMAIL ) ) {
$errors['invalid_domain'] = __( 'All allowed domains values must be valid domains or subdomains without protocol.', 'wppus' );
if ( ! is_scalar( $value ) || 5 > strlen( strval( $value ) ) ) {
$errors['invalid_domain'] = __( 'All allowed domains values must be scalar with a string-equivalent length superior to 5 characters.', 'wppus' );

break;
}
Expand Down

0 comments on commit 6470d5b

Please sign in to comment.