| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 1 | <?php | 
| matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 2 | include_once 'ldap.php'; | 
|  | 3 | include_once 'redis.php'; | 
|  | 4 | include_once 'config.php'; | 
|  | 5 | include_once 'utils.php'; | 
| Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 6 | include_once 'db_backend.php'; | 
|  | 7 |  | 
|  | 8 | use \DB as DB; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 9 |  | 
| matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 10 | $TEMPLATE = template_path(); | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 11 |  | 
|  | 12 | function validate_username(string $username) | 
|  | 13 | { | 
| matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 14 | global $TEMPLATE; | 
|  | 15 | include 'config.php'; | 
|  | 16 | include $TEMPLATE . 'strings.php'; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 17 | $error = ""; | 
|  | 18 | if (ldap_user_count($username)) { | 
|  | 19 | $error = $error . $USERNAME_VALIDATION_ERROR->registered; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 20 | } | 
|  | 21 | if (preg_match("/\s/", $username)) { | 
|  | 22 | $error = $error . $USERNAME_VALIDATION_ERROR->no_whitespaces; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 23 | } | 
|  | 24 | if (strlen($username) > $VAL_USER->max_username) { | 
| matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 25 | echo $VAL_USER->max_username; | 
|  | 26 | echo $USERNAME_VALIDATION_ERROR->smaller_than; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 27 | $error = $error . format($USERNAME_VALIDATION_ERROR->smaller_than, ["num" => $VAL_USER->max_username + 1]); | 
| matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 28 | echo $error; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 29 | } | 
|  | 30 | if (strlen($username) < $VAL_USER->min_username) { | 
|  | 31 | $error = $error . format($USERNAME_VALIDATION_ERROR->bigger_than, ["num" => $VAL_USER->min_username - 1]); | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 32 | } | 
|  | 33 | if (preg_match('/[\'\/~`\!@#\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/', $username)) { | 
|  | 34 | $error = $error . $USERNAME_VALIDATION_ERROR->no_special_chars; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 35 | } | 
|  | 36 | if (preg_match('/^\d/', $username)) { | 
|  | 37 | $error = $error . $USERNAME_VALIDATION_ERROR->no_number_begining; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 38 | } | 
| matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 39 | include "blacklists/usernames.php"; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 40 | if (in_array($username, $USERNAME_BLACKLIST)) { | 
| matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 41 | $error = $error . $USERNAME_VALIDATION_ERROR->blacklisted; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 42 | } | 
|  | 43 | return $error; | 
|  | 44 | } | 
|  | 45 |  | 
|  | 46 | function validate_name(string $name, object $ERRORS) | 
|  | 47 | { | 
| matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 48 | global $TEMPLATE; | 
|  | 49 | include "config.php"; | 
|  | 50 | include $TEMPLATE . 'strings.php'; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 51 | $error = ""; | 
| Marc Kupietz | f1acf58 | 2023-04-22 09:21:10 +0200 | [diff] [blame] | 52 | if (preg_match("/^\s/", $name)) { | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 53 | $error = $error . $ERRORS->no_whitespaces; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 54 | } | 
|  | 55 | if (strlen($name) > $VAL_USER->max_first_name) { | 
|  | 56 | $error = $error . format($ERRORS->smaller_than, ["num" => $VAL_USER->max_first_name + 1]); | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 57 | } | 
|  | 58 | if (strlen($name) < $VAL_USER->min_first_name) { | 
|  | 59 | $error = $error . format($ERRORS->bigger_than, ["num" => $VAL_USER->min_first_name - 1]); | 
| Marc Kupietz | f1acf58 | 2023-04-22 09:21:10 +0200 | [diff] [blame] | 60 | $error += "actual length: " . strlen($name); | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 61 | } | 
| Marc Kupietz | f1acf58 | 2023-04-22 09:21:10 +0200 | [diff] [blame] | 62 | if (preg_match('/[\'\/~`\!@#\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\0-9]-/', $name)) { | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 63 | $error = $error . $ERRORS->no_special_chars; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 64 | } | 
|  | 65 | return $error; | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | function validate_email(string $email) | 
|  | 69 | { | 
| Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 70 | global $CONFERENCE_REGISTRATION, $TEMPLATE, $log, $MAIL_HOST_BLACKLIST, $EMAIL_VALIDATION_ERROR, $BASE_URL; | 
| matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 71 | include $TEMPLATE . 'strings.php'; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 72 | $error = ""; | 
|  | 73 |  | 
| Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 74 | if (($CONFERENCE_REGISTRATION && (new DB(null))->mail_count($email)) || (!$CONFERENCE_REGISTRATION && ldap_mail_count($email))) { | 
|  | 75 | $log->info("Email already registered"); | 
| matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 76 | $error = $error . format($EMAIL_VALIDATION_ERROR->registered, ["link" => $BASE_URL . "?type=recover"]); | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 77 | } | 
| Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 78 | if (in_array(explode("@", $email)[1], $MAIL_HOST_BLACKLIST)) { | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 79 | $error = $error . $EMAIL_VALIDATION_ERROR->blacklisted; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 80 | } | 
| Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 81 | $log->debug("Checking if email is pending"); | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 82 | $pending = redis_get("pending"); | 
|  | 83 | if ($pending) { | 
| Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 84 | $log->debug("Email might be pending"); | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 85 | $maillist = $pending->mails; | 
| Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 86 | if (is_array($maillist) && in_array($email, $maillist)) { | 
|  | 87 | if ($CONFERENCE_REGISTRATION) { | 
|  | 88 | unset($maillist[array_search($user->email, $maillist)]); | 
|  | 89 | redis_set("pending", (object)["mails" => $maillist], $MAIL_CONFIRMATION_AWAIT_DELAY); | 
|  | 90 | $log->debug("Email was pending, but let participant change details."); | 
|  | 91 | echo '<div class="alert alert-warning" role="alert">A confirmation request has already been sent to this email, but no problem.</div>'; | 
|  | 92 | } else { | 
|  | 93 | $error = $error . $EMAIL_VALIDATION_ERROR->pending; | 
|  | 94 | $log->debug("Email is pending"); | 
|  | 95 | } | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 96 | } | 
|  | 97 | } | 
| Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 98 | $log->debug("email validated, result: $error"); | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 99 | return $error; | 
|  | 100 | } | 
|  | 101 |  | 
|  | 102 |  | 
|  | 103 | function validate_password(string $password) | 
|  | 104 | { | 
| matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 105 | global $TEMPLATE; | 
|  | 106 | include "config.php"; | 
|  | 107 | include $TEMPLATE . 'strings.php'; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 108 | $error = ""; | 
|  | 109 | if ($_POST["password"] != $_POST["password_confirm"]) {; | 
|  | 110 | $error = $error . $PASSWORD_VALIDATION_ERROR->no_match; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 111 | } | 
|  | 112 | if (strlen($password) < $VAL_USER->min_password) { | 
|  | 113 | $error = $error . format($PASSWORD_VALIDATION_ERROR->bigger_than, ["num" => $VAL_USER->min_password]); | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 114 | } | 
|  | 115 | if (strlen($password) > $VAL_USER->max_password) { | 
|  | 116 | $error = $error . format($PASSWORD_VALIDATION_ERROR->smaller_than, ["num" => $VAL_USER->max_password]); | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 117 | } | 
| matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 118 | include "blacklists/password.php"; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 119 | if (in_array($password, $PASSWORD_BLACKLIST)) { | 
|  | 120 | $error = $error . $PASSWORD_VALIDATION_ERROR->blacklisted; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 121 | } | 
|  | 122 | foreach (array("username", "name", "last_name", "email") as &$field) { | 
|  | 123 | if (!isset($_POST[$field])) | 
|  | 124 | continue; | 
|  | 125 | $value = strtoupper($_POST[$field]); | 
|  | 126 | $PASSWORD = strtoupper($password); | 
|  | 127 | if (strpos($value, $PASSWORD) !== false || strpos($PASSWORD, $value) !== false) { | 
|  | 128 | $error = $error . $PASSWORD_VALIDATION_ERROR->shared_inclusion; | 
| matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 129 | break; | 
|  | 130 | } | 
|  | 131 | } | 
|  | 132 | return $error; | 
|  | 133 | } |