Do not try to update emails if the user can modify it herself.
[platal.git] / include / security.inc.php
index e5c0b19..1d54167 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2009 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -66,10 +66,11 @@ function check_ip($level)
 
 function check_email($email, $message)
 {
-    $res = XDB::query("SELECT state, description
-        FROM emails_watch
-        WHERE state != 'safe' AND email = {?}", $email);
-    if ($res->numRows()) {
+    $res = XDB::fetchOneCell('SELECT  COUNT(*)
+                                FROM  email_watch
+                               WHERE  state != \'safe\' AND email = {?}',
+                             $email);
+    if ($res) {
         send_warning_mail($message);
         return true;
     }
@@ -78,7 +79,10 @@ function check_email($email, $message)
 
 function check_account()
 {
-    return S::v('watch_account');
+    if (S::user()) {
+        return S::user()->watch;
+    }
+    return false;
 }
 
 function check_redirect($red = null)
@@ -94,14 +98,14 @@ function check_redirect($red = null)
     }
 }
 
-function send_warning_mail($title)
+function send_warning_mail($title, $body = '')
 {
     global $globals;
     $mailer = new PlMailer();
     $mailer->setFrom("webmaster@" . $globals->mail->domain);
     $mailer->addTo($globals->core->admin_email);
     $mailer->setSubject("[Plat/al Security Alert] $title");
-    $mailer->setTxtBody("Identifiants de session :\n" . var_export($_SESSION, true) . "\n\n"
+    $mailer->setTxtBody($body . "Identifiants de session :\n" . var_export($_SESSION, true) . "\n\n"
         ."Identifiants de connexion :\n" . var_export($_SERVER, true));
     $mailer->send();
 }