balise/login_saml.php: add addresses and phone numbers support
This commit is contained in:
parent
d82fa0f4ca
commit
ff3823ca72
|
@ -58,6 +58,43 @@ function generate_password($length = 15) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function update_numeros($titre, $type, $numero, $id_auteur) {
|
||||||
|
/* $type: cell, home, fax */
|
||||||
|
if ($numero) {
|
||||||
|
$id_numero = null;
|
||||||
|
spip_log("[auth_saml] sync numero $titre $type $numero $id_auteur");
|
||||||
|
$result = spip_query("SELECT id_numero, type FROM spip_numeros_liens WHERE id_objet=$id_auteur and objet='auteur'");
|
||||||
|
while ($row = spip_fetch_array($result)) {
|
||||||
|
if ($row['type'] == $type) {
|
||||||
|
$id_numero = $row['id_numero'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($id_numero) {
|
||||||
|
spip_log("[auth_saml] mise a jour du mobile $id_numero");
|
||||||
|
spip_query("UPDATE spip_numeros SET numero='$numero' WHERE id_numero='$id_numero'");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
spip_log("[auth_saml] ajout d'un numero $type");
|
||||||
|
$champs = pipeline('pre_insertion', array(
|
||||||
|
'args' => array(
|
||||||
|
'table' => 'spip_numeros',
|
||||||
|
),
|
||||||
|
'data' => array(
|
||||||
|
'numero' => $numero,
|
||||||
|
'titre' => $titre
|
||||||
|
)
|
||||||
|
));
|
||||||
|
$id_numero = sql_insertq("spip_numeros", $champs);
|
||||||
|
$c = array('objet' => 'auteur',
|
||||||
|
'id_objet' => $id_auteur,
|
||||||
|
'type' => $type,
|
||||||
|
'id_numero' => $id_numero
|
||||||
|
);
|
||||||
|
sql_insertq("spip_numeros_liens", $c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function login_saml_successfull()
|
function login_saml_successfull()
|
||||||
{
|
{
|
||||||
$simplesaml = new SimpleSAML_Auth_Simple('default-sp');
|
$simplesaml = new SimpleSAML_Auth_Simple('default-sp');
|
||||||
|
@ -71,6 +108,12 @@ function login_saml_successfull()
|
||||||
$email = $attributes['email'][0];
|
$email = $attributes['email'][0];
|
||||||
$nameid = $attributes['NameID'][0];
|
$nameid = $attributes['NameID'][0];
|
||||||
$display_name = $first_name . ' ' . $last_name;
|
$display_name = $first_name . ' ' . $last_name;
|
||||||
|
$street = $attributes['street'][0];
|
||||||
|
$zipcode = $attributes['postalCode'][0];
|
||||||
|
$city = $attributes['l'][0];
|
||||||
|
$mobile = $attributes['mobile'][0];
|
||||||
|
$phone = $attributes['telephoneNumber'][0];
|
||||||
|
$fax = $attributes['fax'][0];
|
||||||
|
|
||||||
if (!$nameid) {
|
if (!$nameid) {
|
||||||
spip_log("[auth_saml] no NameID found in SAML attributes, cancel login", _LOG_ERREUR);
|
spip_log("[auth_saml] no NameID found in SAML attributes, cancel login", _LOG_ERREUR);
|
||||||
|
@ -109,6 +152,42 @@ function login_saml_successfull()
|
||||||
$result = spip_query("SELECT * FROM spip_auteurs WHERE nameid=" ._q($nameid). " AND statut<>'6forum'" );
|
$result = spip_query("SELECT * FROM spip_auteurs WHERE nameid=" ._q($nameid). " AND statut<>'6forum'" );
|
||||||
$row_auteur = spip_fetch_array($result);
|
$row_auteur = spip_fetch_array($result);
|
||||||
}
|
}
|
||||||
|
if ($street || $zipcode || $city) {
|
||||||
|
$adresse_id = null;
|
||||||
|
spip_log("[auth_saml] sync address {$row_auteur['id_auteur']}");
|
||||||
|
$result = spip_query("SELECT id_adresse, type FROM spip_adresses_liens WHERE id_objet={$row_auteur['id_auteur']} and objet='auteur'");
|
||||||
|
while ($row = spip_fetch_array($result)) {
|
||||||
|
if ($row['type'] == 'pref') {
|
||||||
|
$adresse_id = $row['id_adresse'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($adresse_id) {
|
||||||
|
spip_log("[auth_saml] mise a jour de l'adresse $adresse_id");
|
||||||
|
spip_query("UPDATE spip_adresses SET voie=". _q($street) .", code_postal=". _q($zipcode) .", ville="._q($city)." WHERE id_adresse="._q($adresse_id));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
spip_log("[auth_saml] ajout d'une nouvelle adresse");
|
||||||
|
$champs = pipeline('pre_insertion', array(
|
||||||
|
'args' => array(
|
||||||
|
'table' => 'spip_adresses',
|
||||||
|
),
|
||||||
|
'data' => array('voie' => $street,
|
||||||
|
'code_postal' => $zipcode,
|
||||||
|
'ville' => $city)
|
||||||
|
));
|
||||||
|
$id_adresse = sql_insertq("spip_adresses", $champs);
|
||||||
|
$c = array('objet' => 'auteur',
|
||||||
|
'id_objet' => $row_auteur['id_auteur'],
|
||||||
|
'type' => 'pref',
|
||||||
|
'id_adresse' => $id_adresse
|
||||||
|
);
|
||||||
|
sql_insertq("spip_adresses_liens", $c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
update_numeros('Téléphone mobile', 'cell', $mobile, $row_auteur['id_auteur']);
|
||||||
|
update_numeros('Téléphone fixe', 'home', $phone, $row_auteur['id_auteur']);
|
||||||
|
update_numeros('Fax', 'fax', $fax, $row_auteur['id_auteur']);
|
||||||
|
|
||||||
// Debug
|
// Debug
|
||||||
spip_log('[auth_saml] nameid :' . $row_auteur['nameid'] . ' status : ' . $row_auteur['statut'] . ' email : ' . $row_auteur['email']);
|
spip_log('[auth_saml] nameid :' . $row_auteur['nameid'] . ' status : ' . $row_auteur['statut'] . ' email : ' . $row_auteur['email']);
|
||||||
// chargement de l'utilisateur en session
|
// chargement de l'utilisateur en session
|
||||||
|
|
Reference in New Issue