authsql : add the firstname/lastname instead of gecos

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2060 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2015-03-23 15:05:54 +00:00
parent 97ede7f03b
commit 98bbcdd1a6

View File

@@ -22,6 +22,10 @@ class authsql extends auth
public $fieldPassword = "password"; public $fieldPassword = "password";
/** The identifier field name (maybe email) */ /** The identifier field name (maybe email) */
public $fieldIdentifier = "email"; public $fieldIdentifier = "email";
/** The field name containing the lastname of the user */
public $fieldLastname = null;
/** The field name containing the Firstname of the user */
public $fieldFirstname = null;
/** The informations fields (in an array) */ /** The informations fields (in an array) */
public $fieldsInfo = array (); public $fieldsInfo = array ();
@@ -48,6 +52,12 @@ class authsql extends auth
if ($this->fieldPassword === null) if ($this->fieldPassword === null)
throw new Exception (dgettext("domframework", throw new Exception (dgettext("domframework",
"No fieldPassword defined"), 500); "No fieldPassword defined"), 500);
if ($this->fieldLastname === null)
throw new Exception (dgettext("domframework",
"No fieldLastname defined"), 500);
if ($this->fieldFirstname === null)
throw new Exception (dgettext("domframework",
"No fieldFirstname defined"), 500);
$fields = array_merge (array ($this->fieldIdentifier, $this->fieldPassword), $fields = array_merge (array ($this->fieldIdentifier, $this->fieldPassword),
$this->fieldsInfo); $this->fieldsInfo);
$fields = array_flip ($fields); $fields = array_flip ($fields);
@@ -68,6 +78,8 @@ class authsql extends auth
"The SQL database is not connected"), 500); "The SQL database is not connected"), 500);
$data = $this->db->read (array (array ($this->fieldIdentifier, $email)), $data = $this->db->read (array (array ($this->fieldIdentifier, $email)),
array_merge (array ($this->fieldIdentifier, array_merge (array ($this->fieldIdentifier,
$this->fieldFirstname,
$this->fieldLastname,
$this->fieldPassword), $this->fieldPassword),
$this->fieldsInfo)); $this->fieldsInfo));
if (count ($data) === 0) if (count ($data) === 0)
@@ -83,8 +95,13 @@ class authsql extends auth
throw new Exception (sprintf (dgettext("domframework", throw new Exception (sprintf (dgettext("domframework",
"Bad password for '%s'"), $email), "Bad password for '%s'"), $email),
401); 401);
// The password should never be stored by this function
unset ($data[0][$this->fieldPassword]); unset ($data[0][$this->fieldPassword]);
$this->details = $data[0]; $content = $data[0];
$content["email"] = $data[0][$this->fieldIdentifier];
$content["lastname"] = $data[0][$this->fieldLastname];
$content["firstname"] = $data[0][$this->fieldFirstname];
$this->details = $content;
} }
/** Return all the parameters recorded for the authenticate user */ /** Return all the parameters recorded for the authenticate user */
@@ -109,9 +126,8 @@ class authsql extends auth
500); 500);
$data = $this->db->read (array (array ($this->fieldIdentifier, $data = $this->db->read (array (array ($this->fieldIdentifier,
$this->details[$this->fieldIdentifier])), $this->details[$this->fieldIdentifier])),
array_merge (array ($this->fieldIdentifier, array ($this->fieldIdentifier,
$this->fieldPassword), $this->fieldPassword));
$this->fieldsInfo));
$cryptedPassword = $data[0][$this->fieldPassword]; $cryptedPassword = $data[0][$this->fieldPassword];
if (crypt ($oldpassword, $cryptedPassword) !== $cryptedPassword) if (crypt ($oldpassword, $cryptedPassword) !== $cryptedPassword)
throw new Exception (dgettext("domframework", throw new Exception (dgettext("domframework",
@@ -144,9 +160,8 @@ class authsql extends auth
throw new Exception (dgettext("domframework", throw new Exception (dgettext("domframework",
"The SQL database is not connected"), 500); "The SQL database is not connected"), 500);
$data = $this->db->read (array (array ($this->fieldIdentifier, $email)), $data = $this->db->read (array (array ($this->fieldIdentifier, $email)),
array_merge (array ($this->fieldIdentifier, array ($this->fieldIdentifier,
$this->fieldPassword), $this->fieldPassword));
$this->fieldsInfo));
if (count ($data) === 0) if (count ($data) === 0)
throw new Exception (sprintf (dgettext("domframework", throw new Exception (sprintf (dgettext("domframework",
"Unable to find the user : '%s'"), "Unable to find the user : '%s'"),
@@ -174,7 +189,9 @@ class authsql extends auth
if ($this->db === null) if ($this->db === null)
throw new Exception (dgettext("domframework", throw new Exception (dgettext("domframework",
"The SQL database is not connected"), 500); "The SQL database is not connected"), 500);
$data = $this->db->read (null, array_merge (array ($this->fieldIdentifier), $data = $this->db->read (null, array_merge (array ($this->fieldIdentifier,
$this->fieldFirstname,
$this->fieldLastname),
$this->fieldsInfo)); $this->fieldsInfo));
return $data; return $data;
} }