summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérôme Schneider <jschneider@entrouvert.com>2013-06-07 17:47:53 (GMT)
committerJérôme Schneider <jschneider@entrouvert.com>2013-06-07 17:47:53 (GMT)
commit554b3d97480a17931ca5a3df66798fa0c85c7898 (patch)
tree7303a184328b19ce1fce04ac7e1436a66237889e
parent1b99445f0d87c59e67d41d0754c75bd209a689c0 (diff)
downloadspip-saml-554b3d97480a17931ca5a3df66798fa0c85c7898.zip
spip-saml-554b3d97480a17931ca5a3df66798fa0c85c7898.tar.gz
spip-saml-554b3d97480a17931ca5a3df66798fa0c85c7898.tar.bz2
add user creation
-rw-r--r--balise/login_saml.php32
1 files changed, 24 insertions, 8 deletions
diff --git a/balise/login_saml.php b/balise/login_saml.php
index 0d44d22..031705a 100644
--- a/balise/login_saml.php
+++ b/balise/login_saml.php
@@ -46,6 +46,18 @@ function balise_LOGIN_SAML_dyn()
else return login_saml_successfull();
}
+function generate_password($length = 15) {
+ $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789*\_-~#/!+={[]}()&$%';
+ $count = mb_strlen($chars);
+
+ for ($i = 0, $result = ''; $i < $length; $i++) {
+ $index = rand(0, $count - 1);
+ $result .= mb_substr($chars, $index, 1);
+ }
+
+ return $result;
+}
+
function login_saml_successfull()
{
$simplesaml = new SimpleSAML_Auth_Simple('default-sp');
@@ -74,18 +86,22 @@ function login_saml_successfull()
spip_log("[auth_saml] display name : $display_name and email : $email");
spip_query("UPDATE spip_auteurs SET nom=" . _q($display_name) . ", email=" . _q($email) . " WHERE login="._q($login));
- $session = charger_fonction('session', 'inc');
- $cookie_session = $session($row_auteur);
- spip_setcookie('spip_session', $cookie_session);
- $redirect = _DIR_RESTREINT_ABS. "?bonjour=oui";
- redirige_par_entete($redirect);
}
else
{
- // Logout SAML au cas ou
- spip_log("[auth_saml] logout");
- $simplesaml->logout();
+ spip_log("[auth_saml] creating user [" . $login . "]");
+ spip_log("[auth_saml] display name : $display_name and email : $email");
+ $pass = generate_password();
+ spip_query("INSERT INTO spip_auteurs (nom, login, email, pass, statut) VALUES ('$display_name', '$login', '$email', '$pass', '1comite')");
+ // Si l'utilisateur figure deja dans la base, y recuperer les infos
+ $result = spip_query("SELECT * FROM spip_auteurs WHERE login=" ._q($login). " AND statut<>'5poubelle'" );
+ $row_auteur = spip_fetch_array($result);
}
+ $session = charger_fonction('session', 'inc');
+ $cookie_session = $session($row_auteur);
+ spip_setcookie('spip_session', $cookie_session);
+ $redirect = _DIR_RESTREINT_ABS. "?bonjour=oui";
+ redirige_par_entete($redirect);
}
?>