<?php
include_once 'ldap.php';
include_once 'redis.php';
include_once 'config.php';
include_once 'utils.php';

$TEMPLATE = template_path();

function validate_username(string $username)
{
        global $TEMPLATE;
        include 'config.php';
        include $TEMPLATE . 'strings.php';
        $error = "";
        if (ldap_user_count($username)) {
                $error = $error . $USERNAME_VALIDATION_ERROR->registered;
        }
        if (preg_match("/\s/", $username)) {
                $error = $error . $USERNAME_VALIDATION_ERROR->no_whitespaces;
        }
        if (strlen($username) > $VAL_USER->max_username) {
                echo $VAL_USER->max_username;
                echo $USERNAME_VALIDATION_ERROR->smaller_than;
                $error = $error . format($USERNAME_VALIDATION_ERROR->smaller_than, ["num" => $VAL_USER->max_username + 1]);
                echo $error;
        }
        if (strlen($username) < $VAL_USER->min_username) {
                $error = $error . format($USERNAME_VALIDATION_ERROR->bigger_than, ["num" => $VAL_USER->min_username - 1]);
        }
        if (preg_match('/[\'\/~`\!@#\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/', $username)) {
                $error = $error . $USERNAME_VALIDATION_ERROR->no_special_chars;
        }
        if (preg_match('/^\d/', $username)) {
                $error = $error . $USERNAME_VALIDATION_ERROR->no_number_begining;
        }
        include "blacklists/usernames.php";
        if (in_array($username, $USERNAME_BLACKLIST)) {
                $error = $error . $USERNAME_VALIDATION_ERROR->blacklisted;
        }
        return $error;
}

function validate_name(string $name, object $ERRORS)
{
        global $TEMPLATE;
        include "config.php";
        include $TEMPLATE . 'strings.php';
        $error = "";
        if (preg_match("/\s/", $name)) {
                $error = $error . $ERRORS->no_whitespaces;
        }
        if (strlen($name) > $VAL_USER->max_first_name) {
                $error = $error . format($ERRORS->smaller_than, ["num" => $VAL_USER->max_first_name + 1]);
        }
        if (strlen($name) < $VAL_USER->min_first_name) {
                $error = $error . format($ERRORS->bigger_than, ["num" => $VAL_USER->min_first_name - 1]);
        }
        if (preg_match('/[\'\/~`\!@#\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\0-9]/', $name)) {
                $error = $error . $ERRORS->no_special_chars;
        }
        return $error;
}

function validate_email(string $email)
{
        global $TEMPLATE;
        include "config.php";
        include $TEMPLATE . 'strings.php';
        $error = "";

        if (ldap_mail_count($email)) {
                $error = $error . format($EMAIL_VALIDATION_ERROR->registered, ["link" => $BASE_URL . "?type=recover"]);
        }
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                $error = $error . $EMAIL_VALIDATION_ERROR->invalid;
        } elseif (in_array(explode("@", $email)[1], $MAIL_HOST_BLACKLIST)) {
                $error = $error . $EMAIL_VALIDATION_ERROR->blacklisted;
        }
        $pending = redis_get("pending");
        if ($pending) {
                $maillist = $pending->mails;
                if (in_array($email, $maillist)) {
                        $error = $error . $EMAIL_VALIDATION_ERROR->pending;
                }
        }
        return $error;
}


function validate_password(string $password)
{
        global $TEMPLATE;
        include "config.php";
        include $TEMPLATE . 'strings.php';
        $error = "";
        if ($_POST["password"] != $_POST["password_confirm"]) {;
                $error = $error . $PASSWORD_VALIDATION_ERROR->no_match;
        }
        if (strlen($password) < $VAL_USER->min_password) {
                $error = $error . format($PASSWORD_VALIDATION_ERROR->bigger_than, ["num" => $VAL_USER->min_password]);
        }
        if (strlen($password) > $VAL_USER->max_password) {
                $error = $error . format($PASSWORD_VALIDATION_ERROR->smaller_than, ["num" => $VAL_USER->max_password]);
        }
        include "blacklists/password.php";
        if (in_array($password, $PASSWORD_BLACKLIST)) {
                $error = $error . $PASSWORD_VALIDATION_ERROR->blacklisted;
        }
        foreach (array("username", "name", "last_name", "email") as &$field) {
                if (!isset($_POST[$field]))
                        continue;
                $value = strtoupper($_POST[$field]);
                $PASSWORD = strtoupper($password);
                if (strpos($value, $PASSWORD) !== false || strpos($PASSWORD, $value) !== false) {
                        $error = $error . $PASSWORD_VALIDATION_ERROR->shared_inclusion;
                        break;
                }
        }
        return $error;
}
