Change all the "new class" by "new Class"

This commit is contained in:
2021-05-07 13:10:37 +02:00
parent c8d275be31
commit c09fa961cd
39 changed files with 430 additions and 432 deletions

View File

@@ -44,25 +44,25 @@ class Authsql extends Auth
public function connect ()
{
if (! function_exists ("openssl_random_pseudo_bytes"))
throw new Exception (dgettext ("domframework",
throw new \Exception (dgettext ("domframework",
"No PHP support for openssl_random_pseudo_bytes"),
500);
$this->db = new dblayer ($this->dsn, $this->username, $this->password,
$this->db = new Dblayer ($this->dsn, $this->username, $this->password,
$this->driver_options);
if ($this->table === null)
throw new Exception (dgettext ("domframework", "No SQL table defined"),
throw new \Exception (dgettext ("domframework", "No SQL table defined"),
500);
if ($this->fieldIdentifier === null)
throw new Exception (dgettext ("domframework",
throw new \Exception (dgettext ("domframework",
"No fieldIdentifier defined"), 500);
if ($this->fieldPassword === null)
throw new Exception (dgettext ("domframework",
throw new \Exception (dgettext ("domframework",
"No fieldPassword defined"), 500);
if ($this->fieldLastname === null)
throw new Exception (dgettext ("domframework",
throw new \Exception (dgettext ("domframework",
"No fieldLastname defined"), 500);
if ($this->fieldFirstname === null)
throw new Exception (dgettext ("domframework",
throw new \Exception (dgettext ("domframework",
"No fieldFirstname defined"), 500);
$fields = array_merge (array ($this->fieldIdentifier, $this->fieldPassword,
$this->fieldLastname, $this->fieldFirstname),
@@ -81,7 +81,7 @@ class Authsql extends Auth
public function authentication ($email, $password)
{
if ($this->db === null)
throw new Exception (dgettext ("domframework",
throw new \Exception (dgettext ("domframework",
"The SQL database is not connected"), 500);
$data = $this->db->read (array (array ($this->fieldIdentifier, $email)),
array_merge (array ($this->fieldIdentifier,
@@ -90,16 +90,16 @@ class Authsql extends Auth
$this->fieldPassword),
$this->fieldsInfo));
if (count ($data) === 0)
throw new Exception (sprintf (dgettext ("domframework",
throw new \Exception (sprintf (dgettext ("domframework",
"Unable to find the user : '%s'"),
$email), 401);
if (! isset ($data[0][$this->fieldPassword]))
throw new Exception (dgettext ("domframework",
throw new \Exception (dgettext ("domframework",
"Unable to get the user password from database"),
500);
$cryptedPassword = $data[0][$this->fieldPassword];
if (crypt ($password, $cryptedPassword) !== $cryptedPassword)
throw new Exception (sprintf (dgettext ("domframework",
throw new \Exception (sprintf (dgettext ("domframework",
"Bad password for '%s'"), $email),
401);
// The password should never be stored by this function
@@ -124,11 +124,11 @@ class Authsql extends Auth
public function changepassword ($oldpassword, $newpassword)
{
if ($this->db === null)
throw new Exception (dgettext ("domframework",
throw new \Exception (dgettext ("domframework",
"The SQL database is not connected"), 500);
if ($this->details === null ||
! isset ($this->details[$this->fieldIdentifier]))
throw new Exception (dgettext ("domframework",
throw new \Exception (dgettext ("domframework",
"Can't change the password if the user is not authenticated"),
500);
$data = $this->db->read (array (array ($this->fieldIdentifier,
@@ -137,7 +137,7 @@ class Authsql extends Auth
$this->fieldPassword));
$cryptedPassword = $data[0][$this->fieldPassword];
if (crypt ($oldpassword, $cryptedPassword) !== $cryptedPassword)
throw new Exception (dgettext ("domframework",
throw new \Exception (dgettext ("domframework",
"Bad old password provided"), 401);
$cost = 11;
$salt = substr (base64_encode (openssl_random_pseudo_bytes (17)), 0, 22);
@@ -152,7 +152,7 @@ class Authsql extends Auth
$rc = $this->db->update ($this->details[$this->fieldIdentifier],
array ($this->fieldPassword => $cryptpassword));
if ($rc !== 1)
throw new Exception (dgettext ("domframework",
throw new \Exception (dgettext ("domframework",
"Can't change the password"), 500);
}
@@ -164,13 +164,13 @@ class Authsql extends Auth
public function overwritepassword ($email, $newpassword)
{
if ($this->db === null)
throw new Exception (dgettext ("domframework",
throw new \Exception (dgettext ("domframework",
"The SQL database is not connected"), 500);
$data = $this->db->read (array (array ($this->fieldIdentifier, $email)),
array ($this->fieldIdentifier,
$this->fieldPassword));
if (count ($data) === 0)
throw new Exception (sprintf (dgettext ("domframework",
throw new \Exception (sprintf (dgettext ("domframework",
"Unable to find the user : '%s'"),
$email), 401);
$cost = 11;
@@ -186,7 +186,7 @@ class Authsql extends Auth
$rc = $this->db->update ($email,
array ($this->fieldPassword => $cryptpassword));
if ($rc !== 1)
throw new Exception (dgettext ("domframework",
throw new \Exception (dgettext ("domframework",
"Can't change the password"), 500);
}
/** List all the users available in the database
@@ -194,7 +194,7 @@ class Authsql extends Auth
public function listusers ()
{
if ($this->db === null)
throw new Exception (dgettext ("domframework",
throw new \Exception (dgettext ("domframework",
"The SQL database is not connected"), 500);
$data = $this->db->read (null, array_merge (array ($this->fieldIdentifier,
$this->fieldFirstname,