From 6d2cf23a80aaab1b016697c241c17725cd6bd906 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 16 Apr 2021 10:48:53 +0200 Subject: [PATCH] Attempt to fix activation issue --- flexisip-account-manager.spec | 2 +- src/misc/utilities.php | 2 +- src/objects/account.php | 21 ++++++++++++++++++++- src/xmlrpc/accounts.php | 6 ++++-- src/xmlrpc/accounts_email.php | 5 +++-- src/xmlrpc/accounts_phone.php | 8 ++++++-- src/xmlrpc/activation.php | 6 ++++-- src/xmlrpc/provisioning.php | 3 +-- 8 files changed, 40 insertions(+), 13 deletions(-) diff --git a/flexisip-account-manager.spec b/flexisip-account-manager.spec index 65c00e4..dd69cd6 100644 --- a/flexisip-account-manager.spec +++ b/flexisip-account-manager.spec @@ -8,7 +8,7 @@ #%define _datadir %{_datarootdir} #%define _docdir %{_datadir}/doc -%define build_number 58 +%define build_number 59 %define var_dir /var/opt/belledonne-communications %define opt_dir /opt/belledonne-communications/share/flexisip-account-manager %define env_file "$RPM_BUILD_ROOT/etc/flexisip-account-manager/flexiapi.env" diff --git a/src/misc/utilities.php b/src/misc/utilities.php index 01695b1..0427650 100644 --- a/src/misc/utilities.php +++ b/src/misc/utilities.php @@ -63,7 +63,7 @@ function get_trial_expiration_date() function is_activated($activated) { - return $activated == "1" || $activated == 1 || $activated; + return $activated == "1"; } // XMLRPC parameters diff --git a/src/objects/account.php b/src/objects/account.php index dee6c19..d0a2087 100644 --- a/src/objects/account.php +++ b/src/objects/account.php @@ -171,6 +171,25 @@ class Account return false; } + public function activate() + { + $query = "UPDATE " . ACCOUNTS_DB_TABLE . " SET activated=1 WHERE id=:id"; + + $stmt = $this->conn->prepare($query); + $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); + + $stmt->bindParam(":id", $this->id); + + Logger::getInstance()->debug("Activating " . (string)$this); + if ($stmt->execute()) { + $this->activated = "1"; + return true; + } + + Logger::getInstance()->error($stmt->errorInfo()); + return false; + } + public function update() { $query = "UPDATE " . ACCOUNTS_DB_TABLE . " SET username=:username, domain=:domain, activated=:activated"; @@ -298,7 +317,7 @@ class Account $this->username = $row['username']; $this->domain = $row['domain']; $this->email = $row['email']; - $this->activated = $row['activated']; + $this->activated = strval($row['activated']); $this->confirmation_key = $row['confirmation_key']; $this->ip_address = $row['ip_address']; $this->alias = $row['alias']; diff --git a/src/xmlrpc/accounts.php b/src/xmlrpc/accounts.php index d979802..a2e23c0 100644 --- a/src/xmlrpc/accounts.php +++ b/src/xmlrpc/accounts.php @@ -130,9 +130,11 @@ function xmlrpc_recover_account_from_confirmation_key($method, $args) return KEY_DOESNT_MATCH; } + Logger::getInstance()->message("Account activation status is " . $account->activated); if (!is_activated($account)) { - $account->activated = "1"; - $account->update(); + if (!$account->activate()) { + Logger::getInstance()->error("Failed to activate account !"); + } } $password = new Password($db); diff --git a/src/xmlrpc/accounts_email.php b/src/xmlrpc/accounts_email.php index 4075436..ebf1148 100644 --- a/src/xmlrpc/accounts_email.php +++ b/src/xmlrpc/accounts_email.php @@ -228,8 +228,9 @@ function xmlrpc_activate_email_account($method, $args) return KEY_DOESNT_MATCH; } - $account->activated = "1"; - $account->update(); + if (!$account->activate()) { + Logger::getInstance()->error("Failed to activate account id " . $account->id); + } $expiration = null; // TODO diff --git a/src/xmlrpc/accounts_phone.php b/src/xmlrpc/accounts_phone.php index 45cb3b4..7798774 100644 --- a/src/xmlrpc/accounts_phone.php +++ b/src/xmlrpc/accounts_phone.php @@ -181,8 +181,9 @@ function xmlrpc_activate_phone_account($method, $args) // If this is a recovery, account is already activated, don't go through the following again if (!is_activated($account->activated)) { $expiration = null; - $account->activated = "1"; - $account->update(); + if (!$account->activate()) { + Logger::getInstance()->error("Failed to activate account id " . $account->id); + } $alias = new Alias($db); $alias->account_id = $account->id; @@ -199,6 +200,9 @@ function xmlrpc_activate_phone_account($method, $args) if (CUSTOM_HOOKS) { hook_on_account_activated($account); } + } else { + Logger::getInstance()->warning("Account id " . $account->id . " was already activated"); + return ACCOUNT_ALREADY_ACTIVATED; } $password = new Password($db); diff --git a/src/xmlrpc/activation.php b/src/xmlrpc/activation.php index 009b013..eb8022a 100644 --- a/src/xmlrpc/activation.php +++ b/src/xmlrpc/activation.php @@ -62,8 +62,10 @@ function activate_email_account($user, $domain, $key, $algo) { return KEY_DOESNT_MATCH; } - $account->activated = "1"; - $account->update(); + if (!$account->activate()) { + Logger::getInstance()->error("[HTTP] Failed to activate account id " . $account->id); + return; + } Logger::getInstance()->message("[HTTP] Account activated"); } diff --git a/src/xmlrpc/provisioning.php b/src/xmlrpc/provisioning.php index e174cee..227d1cd 100644 --- a/src/xmlrpc/provisioning.php +++ b/src/xmlrpc/provisioning.php @@ -168,8 +168,7 @@ if (!empty($username)) { $logger->error("Password not found for account id " . $account->id); } - $account->activated = "1"; - if (!$account->update()) { + if (!$account->activate()) { $logger->error("Failed to activate account id " . $account->id); } } else {