Introduce logging

Change-Id: I5ac91cc195a46d666714904b56e9f89f56f9c2c0
diff --git a/index.php b/index.php
index 0ffa33c..ba273e4 100755
--- a/index.php
+++ b/index.php
@@ -6,6 +6,15 @@
 include_once 'mail.php';
 include_once 'ldap.php';
 include_once 'validators.php';
+include_once 'User.php';
+require __DIR__ . '/vendor/autoload.php';
+use Monolog\Level;
+use Monolog\Logger as Logger;
+use Monolog\Handler\StreamHandler;
+use Monolog\Handler\RotatingFileHandler;
+use \User as User;
+$log = new Logger('signup');
+$log->pushHandler(new RotatingFileHandler(__DIR__ . '/logs/signup.log', 0, Logger::DEBUG));
 
 if (!$DEBUG)    error_reporting(0);
 else error_reporting(1);
@@ -95,7 +104,7 @@
 }
 
 
-function verify_request($user)
+function verify_request(User $user)
 {
     $TEMPLATE = template_path();
     unset($_SESSION['captcha_token']);
@@ -127,9 +136,11 @@
     $_SESSION['organization'] = $user->organization;
 }
 
-function approve_request($user)
+function approve_request(User $user)
 {
     include 'config.php';
+    global $log;
+
     $token = generateRandomString();
     redis_set($token, $user, $MAIL_CONFIRMATION_AWAIT_DELAY);
     $pending = redis_get("pending");
@@ -151,6 +162,7 @@
     backup_user_in_session($user);
     $TEMPLATE = template_path();
     include $TEMPLATE . "confirm_your_email.htm";
+    $log->info("Registration process started for " . user_to_string($user));
 }
 
 function recover_form($error = null)
@@ -229,6 +241,7 @@
                         $TEMPLATE = template_path();
                         send_recovery_email($email, $smtp, $url);
                         include $TEMPLATE . "confirm_your_email.htm";
+                        $log->info("Password recovery email sent to " . $email);
                     }
                 }
                 break;
@@ -249,6 +262,7 @@
                         else
                             $smtp = $SMTP;
                         send_mail($email, $smtp, $PASSWORD_CHANGED_EMAIL_TEMPLATE);
+                        $log->info("Password changed for " . $email);
                     } else {
                         include $TEMPLATE . "strings.php";
                         echo $STRINGS->change_password_ldap_error;
@@ -266,7 +280,7 @@
                 echo $RUNTIME_ERROR->user_trying_invalid_get;
             } else {
                 $token = $_GET["token"];
-                $user = redis_get($token);
+                $user = redis_get_user($token);
                 if ($user && gettype($user) == "object") {
                     if (ldap_add_user($user)) {
                         if ($REDIRECT_TO)
@@ -281,10 +295,12 @@
                             }
                         }
                         redis_inc_ipdata(getClientIP(), "register");
+                        $log->info("User registered: " . user_to_string($user));
                         echo $STRINGS->email_confirmation;
                         if (isset($POST_REGISTER_HOOK)) $POST_REGISTER_HOOK($user);
                         include $TEMPLATE . "mail_confirmed.htm";
                     } else {
+                        $log->error("User registration failed for: " . user_to_string($user));
                         echo $STRINGS->email_confirmation;
                         include $TEMPLATE . "registration_error.htm";
                     }