From 49d2d7863642d6de30363d77d9a0db2a40a80495 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 21 Aug 2019 17:47:38 +0200 Subject: [PATCH] Improved factorization --- src/misc/utilities.php | 4 ++++ src/xmlrpc/accounts.php | 10 +--------- src/xmlrpc/aliases.php | 5 +---- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/misc/utilities.php b/src/misc/utilities.php index 0190894..3156204 100644 --- a/src/misc/utilities.php +++ b/src/misc/utilities.php @@ -136,6 +136,10 @@ function is_key_matching($key, $account) { Logger::getInstance()->error("Key doesn't match"); return false; } + + // Key is one time only + $account->confirmation_key = INVALID_CONFIRMATION_KEY; + $account->update(); return true; } diff --git a/src/xmlrpc/accounts.php b/src/xmlrpc/accounts.php index da73518..7e6707b 100644 --- a/src/xmlrpc/accounts.php +++ b/src/xmlrpc/accounts.php @@ -260,9 +260,6 @@ function xmlrpc_activate_phone_account($method, $args) { if (!is_key_matching($key, $account)) { return KEY_DOESNT_MATCH; } - // Key is one time only - $account->confirmation_key = INVALID_CONFIRMATION_KEY; - $account->update(); // If this is a recovery, account is already activated, don't go through the following again if (!is_activated($account->activated)) { @@ -439,12 +436,10 @@ function xmlrpc_activate_email_account($method, $args) { return KEY_DOESNT_MATCH; } - $expiration = NULL; $account->activated = "1"; - // Key is one time only - $account->confirmation_key = INVALID_CONFIRMATION_KEY; $account->update(); + $expiration = NULL; // TODO /*if (USE_IN_APP_PURCHASES) { $expiration = get_trial_expiration_date(); @@ -693,9 +688,6 @@ function xmlrpc_recover_account_from_confirmation_key($method, $args) { if (!is_key_matching($key, $account)) { return KEY_DOESNT_MATCH; } - // Key is one time only - $account->confirmation_key = INVALID_CONFIRMATION_KEY; - $account->update(); $password = new Password($db); $password->account_id = $account->id; diff --git a/src/xmlrpc/aliases.php b/src/xmlrpc/aliases.php index 250d2b8..b9a6c3b 100644 --- a/src/xmlrpc/aliases.php +++ b/src/xmlrpc/aliases.php @@ -128,13 +128,10 @@ function xmlrpc_activate_phone_number_link($method, $args) { if (!is_activated($account->activated)) { return ACCOUNT_NOT_YET_ACTIVATED; } - + if (!is_key_matching($key, $account)) { return KEY_DOESNT_MATCH; } - // Key is one time only - $account->confirmation_key = INVALID_CONFIRMATION_KEY; - $account->update(); $password = new Password($db); $password->account_id = $account->id;