Attempt to fix activation issue

This commit is contained in:
Sylvain Berfini 2021-04-16 10:48:53 +02:00
parent 43b34091af
commit 6d2cf23a80
8 changed files with 40 additions and 13 deletions

View file

@ -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"

View file

@ -63,7 +63,7 @@ function get_trial_expiration_date()
function is_activated($activated)
{
return $activated == "1" || $activated == 1 || $activated;
return $activated == "1";
}
// XMLRPC parameters

View file

@ -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'];

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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");
}

View file

@ -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 {