matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 1 | <?php |
| 2 | require_once 'vendor/autoload.php'; |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 3 | include 'config.php'; |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 4 | include_once 'redis.php'; |
| 5 | include_once 'utils.php'; |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 6 | include_once 'mail.php'; |
| 7 | include_once 'ldap.php'; |
Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 8 | include_once 'db_backend.php'; |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 9 | include_once 'validators.php'; |
Marc Kupietz | 0215a44 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 10 | include_once 'User.php'; |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 11 | include_once 'invoice.php'; |
Marc Kupietz | 0215a44 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 12 | require __DIR__ . '/vendor/autoload.php'; |
| 13 | use Monolog\Level; |
| 14 | use Monolog\Logger as Logger; |
| 15 | use Monolog\Handler\StreamHandler; |
| 16 | use Monolog\Handler\RotatingFileHandler; |
| 17 | use \User as User; |
Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 18 | use \DB as DB; |
Marc Kupietz | a707440 | 2023-03-06 07:04:59 +0100 | [diff] [blame] | 19 | include $TEMPLATE . "strings.php"; |
Marc Kupietz | 0215a44 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 20 | $log = new Logger('signup'); |
| 21 | $log->pushHandler(new RotatingFileHandler(__DIR__ . '/logs/signup.log', 0, Logger::DEBUG)); |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 22 | |
| 23 | if (!$DEBUG) error_reporting(0); |
matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 24 | else error_reporting(1); |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 25 | session_start(); |
| 26 | |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 27 | use Gregwar\Captcha\PhraseBuilder; |
| 28 | |
matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 29 | $URI = array_slice(explode("/", explode('?', $_SERVER['REQUEST_URI'], 2)[0]), -1)[0]; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 30 | if (strlen($URI) == 2) { |
matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 31 | $GLOBALS["cc"] = $URI; |
| 32 | $_SESSION["cc"] = $URI; |
| 33 | } |
| 34 | |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 35 | if (isset($_GET["lang"])) { |
matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 36 | $GLOBALS["cc"] = $_GET["lang"]; |
| 37 | $_SESSION["cc"] = $_GET["lang"]; |
| 38 | } |
| 39 | |
| 40 | $TEMPLATE = template_path(); |
| 41 | |
| 42 | |
Marc Kupietz | a707440 | 2023-03-06 07:04:59 +0100 | [diff] [blame] | 43 | function send_welcome_email(User $user) |
| 44 | { |
| 45 | global $SMTP, $SERVICE_ACRONYM, $WELCOME_TEMPLATE, $TEMPLATE; |
| 46 | $TEMPLATE = template_path(); |
| 47 | include $TEMPLATE . "email.php"; |
| 48 | $url = ""; |
| 49 | |
| 50 | send_mail($user->email, $SMTP, (object) [ |
| 51 | "subject" => $WELCOME_TEMPLATE->subject, |
| 52 | "text" => replace_all_user_variables($WELCOME_TEMPLATE->text, $user, $url), |
| 53 | "html" => replace_all_user_variables($WELCOME_TEMPLATE->html, $user, $url) |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 54 | ], $user); |
Marc Kupietz | a707440 | 2023-03-06 07:04:59 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Marc Kupietz | a3f3fdb | 2023-03-04 18:13:26 +0100 | [diff] [blame] | 57 | function send_confirmation_email(string $mail, object $smtp, string $url, User $user) |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 58 | { |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 59 | include 'config.php'; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 60 | $TEMPLATE = template_path(); |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 61 | include $TEMPLATE . "email.php"; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 62 | |
| 63 | send_mail($mail, $smtp, (object) [ |
| 64 | "subject" => $MAIL_TEMPLATE->subject, |
Marc Kupietz | a3f3fdb | 2023-03-04 18:13:26 +0100 | [diff] [blame] | 65 | "text" => replace_all_user_variables($MAIL_TEMPLATE->text, $user, $url), |
| 66 | "html" => replace_all_user_variables($MAIL_TEMPLATE->html, $user, $url) |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 67 | ]); |
| 68 | } |
| 69 | |
| 70 | function send_recovery_email(string $mail, object $smtp, string $url) |
| 71 | { |
| 72 | include 'config.php'; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 73 | $TEMPLATE = template_path(); |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 74 | include $TEMPLATE . "email.php"; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 75 | |
| 76 | send_mail($mail, $smtp, (object) [ |
| 77 | "subject" => $RECOVERY_EMAIL_TEMPLATE->subject, |
| 78 | "text" => str_replace("{{url}}", $url, $RECOVERY_EMAIL_TEMPLATE->text), |
| 79 | "html" => str_replace("{{url}}", $url, $RECOVERY_EMAIL_TEMPLATE->html) |
| 80 | ]); |
| 81 | } |
| 82 | |
| 83 | function reload_captcha_script() |
| 84 | { |
| 85 | include 'config.php'; |
Marc Kupietz | a707440 | 2023-03-06 07:04:59 +0100 | [diff] [blame] | 86 | |
| 87 | if ($CAPTCHA_LENGTH > 0) { |
| 88 | $TEMPLATE = template_path(); |
| 89 | include $TEMPLATE . "strings.php"; |
| 90 | echo ' |
| 91 | <script> |
| 92 | const reload_captcha = async (e) => { |
| 93 | var cont = document.getElementById("reload_captcha"); |
| 94 | cont.innerHTML = "<div class=\'spinner-border text-info\' role=\'status\'><span class=\'sr-only\'>' . $STRINGS->reloading_captcha . '</span></div>"; |
| 95 | var img = document.getElementById("captcha") |
| 96 | var url = "' . $BASE_URL . '/captcha.php?token=' . $_SESSION["captcha_token"] . '" |
| 97 | await fetch(url, { cache: "reload", mode: "no-cors" }) |
| 98 | .then(() => { |
| 99 | img.src = url+"&t=" + new Date().getTime(); |
| 100 | setTimeout( () => { |
| 101 | cont.innerHTML = "<button id=\'reload\' class=\'btn btn-outline-info\' type=\'button\'> <span class=\'glyphicon glyphicon-refresh\' aria-hidden=\'true\'></span></button>"; |
| 102 | bindButton() |
| 103 | }, 500); |
| 104 | }) |
| 105 | } |
| 106 | function bindButton(){ |
| 107 | var button = document.getElementById("reload"); |
| 108 | button.addEventListener("click", reload_captcha) |
| 109 | } |
| 110 | bindButton() |
| 111 | </script> |
| 112 | '; |
| 113 | } |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 114 | } |
| 115 | |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 116 | function register_page($error = false) |
| 117 | { |
| 118 | $TEMPLATE = template_path(); |
| 119 | include 'config.php'; |
| 120 | if ($error) |
| 121 | include $TEMPLATE . 'error.htm'; |
| 122 | $_SESSION["captcha_token"] = generateRandomString(12); |
| 123 | include $TEMPLATE . "register.htm"; |
| 124 | reload_captcha_script(); |
| 125 | } |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 126 | |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 127 | |
Marc Kupietz | 0215a44 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 128 | function verify_request(User $user) |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 129 | { |
Marc Kupietz | d5513b1 | 2023-03-30 17:12:22 +0200 | [diff] [blame^] | 130 | global $log, $CONFERENCE_REGISTRATION, $CAPTCHA_LENGTH, $DEBUG; |
Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 131 | |
matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 132 | $TEMPLATE = template_path(); |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 133 | unset($_SESSION['captcha_token']); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 134 | include $TEMPLATE . 'strings.php'; |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 135 | $password = $_POST["password"]; |
matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 136 | $error = ""; |
| 137 | |
Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 138 | if (!$CONFERENCE_REGISTRATION) { |
| 139 | $error .= validate_username($user->username); |
| 140 | $error .= validate_password($password); |
| 141 | } |
| 142 | $log->debug("validating request"); |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 143 | $error .= validate_name($user->first_name, $FIRST_NAME_VALIDATION_ERROR); |
matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 144 | $error .= validate_name($user->last_name, $LAST_NAME_VALIDATION_ERROR); |
Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 145 | $log->debug("request validated: $error"); |
matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 146 | $error .= validate_email($user->email); |
matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 147 | |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 148 | |
Marc Kupietz | 493198f | 2023-03-04 14:59:16 +0100 | [diff] [blame] | 149 | if ($CAPTCHA_LENGTH > 0 && !(isset($_SESSION['captcha']) && PhraseBuilder::comparePhrases($_SESSION['captcha'], $_POST['captcha']))) { |
Marc Kupietz | d5513b1 | 2023-03-30 17:12:22 +0200 | [diff] [blame^] | 150 | $error = $error . $STRINGS->wrong_captcha . ($DEBUG ? " expected: " . $_SESSION['captcha'] . " actual: " . $_POST['captcha'] : ""); |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 151 | } |
| 152 | unset($_SESSION["captcha"]); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 153 | |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 154 | return $error; |
| 155 | } |
| 156 | |
Marc Kupietz | a3f3fdb | 2023-03-04 18:13:26 +0100 | [diff] [blame] | 157 | |
Marc Kupietz | 0215a44 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 158 | function approve_request(User $user) |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 159 | { |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 160 | include 'config.php'; |
Marc Kupietz | 8e6a8df | 2023-03-07 13:05:23 +0100 | [diff] [blame] | 161 | global $log, $_SESSION; |
Marc Kupietz | 0215a44 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 162 | |
matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 163 | $token = generateRandomString(); |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 164 | redis_set($token, $user, $MAIL_CONFIRMATION_AWAIT_DELAY); |
| 165 | $pending = redis_get("pending"); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 166 | if ($pending) { |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 167 | $maillist = $pending->mails; |
Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 168 | if(is_array($maillist)) |
| 169 | array_push($maillist, $user->email); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 170 | } else |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 171 | $maillist = [$user->email]; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 172 | redis_set("pending", (object)["mails" => $maillist], $MAIL_CONFIRMATION_AWAIT_DELAY); |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 173 | |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 174 | $url = $BASE_URL . "?type=confirmation&token=" . $token; |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 175 | if (in_array(explode("@", $user->email)[1], $MAIL_HOST_DIRECT_FALLBACK)) |
| 176 | $smtp = $FALLBACK_SMTP; |
| 177 | else |
| 178 | $smtp = $SMTP; |
Marc Kupietz | a3f3fdb | 2023-03-04 18:13:26 +0100 | [diff] [blame] | 179 | send_confirmation_email($user->email, $smtp, $url, $user); |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 180 | $_SESSION['resend'] = generateRandomString(12); |
| 181 | $_SESSION['token'] = $token; |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 182 | $user->backup_in_session(); |
matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 183 | $TEMPLATE = template_path(); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 184 | include $TEMPLATE . "confirm_your_email.htm"; |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 185 | $log->info("Registration process started for " . $user->to_string()); |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 186 | } |
| 187 | |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 188 | function recover_form($error = null) |
| 189 | { |
| 190 | $TEMPLATE = template_path(); |
| 191 | include 'config.php'; |
| 192 | $_SESSION["captcha_token"] = generateRandomString(12); |
| 193 | if ($error) |
| 194 | include $TEMPLATE . 'error.htm'; |
| 195 | include $TEMPLATE . "recover_email_form.htm"; |
| 196 | reload_captcha_script(); |
| 197 | } |
| 198 | |
| 199 | function new_password_form($error = null) |
| 200 | { |
| 201 | $TEMPLATE = template_path(); |
| 202 | if ($error) |
| 203 | include $TEMPLATE . 'error.htm'; |
| 204 | include $TEMPLATE . "recover_new_password_form.htm"; |
| 205 | } |
| 206 | |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 207 | |
| 208 | // PAGE |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 209 | include $TEMPLATE . "header.htm"; |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 210 | |
| 211 | if ($_SERVER["REQUEST_METHOD"] == "POST") { |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 212 | if (isset($_POST['type'])) { |
| 213 | switch ($_POST['type']) { |
| 214 | case "register": |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 215 | $log->info("Registration request from " . array_to_string($_POST)); |
| 216 | $user = new User(); |
| 217 | $user->init_from_array($_POST); |
| 218 | $log->info("Registration request from " . $user->to_string()); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 219 | if (redis_inc_ipdata(getClientIP(), "register", true) > $HOURLY_REGISTRATIONS) { |
| 220 | include $TEMPLATE . "registration_limit.htm"; |
| 221 | } else { |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 222 | $error = verify_request($user); |
| 223 | if ($error) |
| 224 | register_page($error); |
| 225 | else |
| 226 | approve_request($user); |
| 227 | } |
| 228 | break; |
matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 229 | case "recover": |
Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 230 | if ($CONFERENCE_REGISTRATION) |
| 231 | break; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 232 | $TEMPLATE = template_path(); |
| 233 | unset($_SESSION['captcha_token']); |
| 234 | include $TEMPLATE . 'strings.php'; |
| 235 | |
| 236 | $email = $_POST["email"]; |
Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 237 | if (($CONFERENCE_REGISTRATION & ! (new DB($log))->mail_count($email)) || !ldap_mail_count($email)) { |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 238 | unset($_POST['email']); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 239 | $error = $error . $STRINGS->recover_email_not_registered; |
| 240 | } |
| 241 | |
Marc Kupietz | 493198f | 2023-03-04 14:59:16 +0100 | [diff] [blame] | 242 | if ($CAPTCHA_LENGTH > 0 && !(isset($_SESSION['captcha']) && PhraseBuilder::comparePhrases($_SESSION['captcha'], $_POST['captcha']))) { |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 243 | $error = $error . $STRINGS->wrong_captcha; |
| 244 | } |
| 245 | |
| 246 | unset($_SESSION["captcha"]); |
| 247 | if (redis_inc_ipdata(getClientIP(), "register", true) > $HOURLY_REGISTRATIONS) { |
| 248 | include $TEMPLATE . "registration_limit.htm"; |
| 249 | } else { |
| 250 | if ($error) { |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 251 | recover_form($error); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 252 | } else { |
| 253 | include $TEMPLATE . 'strings.php'; |
| 254 | $token = generateRandomString(); |
| 255 | redis_set($token, $email, $MAIL_CONFIRMATION_AWAIT_DELAY); |
| 256 | |
| 257 | $url = $BASE_URL . "?type=password_change&token=" . $token; |
| 258 | if (in_array(explode("@", $email)[1], $MAIL_HOST_DIRECT_FALLBACK)) |
| 259 | $smtp = $FALLBACK_SMTP; |
| 260 | else |
| 261 | $smtp = $SMTP; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 262 | $_SESSION['resend'] = generateRandomString(12); |
| 263 | $_SESSION['token'] = $token; |
| 264 | $_SESSION['email'] = $email; |
| 265 | $_SESSION['recover'] = $email; |
| 266 | $TEMPLATE = template_path(); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 267 | send_recovery_email($email, $smtp, $url); |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 268 | include $TEMPLATE . "confirm_your_email.htm"; |
Marc Kupietz | 0215a44 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 269 | $log->info("Password recovery email sent to " . $email); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 270 | } |
| 271 | } |
matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 272 | break; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 273 | |
| 274 | case "password_change": |
Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 275 | if ($CONFERENCE_REGISTRATION) |
| 276 | break; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 277 | $password = $_POST['password']; |
| 278 | $error = validate_password($password); |
| 279 | if ($error) { |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 280 | new_password_form($error); |
| 281 | } else { |
| 282 | $TEMPLATE = template_path(); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 283 | include $TEMPLATE . "recover_success.htm"; |
| 284 | include $TEMPLATE . "email.php"; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 285 | $email = $_SESSION["email_change"]; |
| 286 | if (change_password($email, $password)) { |
| 287 | if (in_array(explode("@", $email)[1], $MAIL_HOST_DIRECT_FALLBACK)) |
| 288 | $smtp = $FALLBACK_SMTP; |
| 289 | else |
| 290 | $smtp = $SMTP; |
| 291 | send_mail($email, $smtp, $PASSWORD_CHANGED_EMAIL_TEMPLATE); |
Marc Kupietz | 0215a44 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 292 | $log->info("Password changed for " . $email); |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 293 | } else { |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 294 | include $TEMPLATE . "strings.php"; |
| 295 | echo $STRINGS->change_password_ldap_error; |
| 296 | } |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 297 | unset($_SESSION["email_change"]); |
| 298 | redis_delete($_SESSION['token']); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 299 | } |
| 300 | break; |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 301 | } |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 302 | } |
| 303 | } elseif (isset($_GET['type'])) { |
| 304 | switch ($_GET['type']) { |
| 305 | case "confirmation": |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 306 | if (!isset($_GET["token"])) { |
matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 307 | echo $RUNTIME_ERROR->user_trying_invalid_get; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 308 | } else { |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 309 | $token = $_GET["token"]; |
Marc Kupietz | 0215a44 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 310 | $user = redis_get_user($token); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 311 | if ($user && gettype($user) == "object") { |
Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 312 | if (($CONFERENCE_REGISTRATION && (new DB($log))->add_user($user)) || (!$CONFERENCE_REGISTRATION && ldap_add_user($user))) { |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 313 | if ($REDIRECT_TO) |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 314 | header("refresh:5;url=" . $REDIRECT_TO); |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 315 | |
| 316 | $pending = redis_get("pending"); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 317 | if ($pending) { |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 318 | $maillist = $pending->mails; |
Marc Kupietz | 49f677c | 2023-03-10 08:29:41 +0100 | [diff] [blame] | 319 | if (is_array($maillist) && in_array($user->email, $maillist)) { |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 320 | unset($maillist[array_search($user->email, $maillist)]); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 321 | redis_set("pending", (object)["mails" => $maillist], $MAIL_CONFIRMATION_AWAIT_DELAY); |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | redis_inc_ipdata(getClientIP(), "register"); |
Marc Kupietz | 145f5b9 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 325 | $log->info("User registration completed: " . $user->to_string()); |
matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 326 | echo $STRINGS->email_confirmation; |
Matheus Fillipe | 5ad0cd5 | 2022-05-05 06:10:41 +0300 | [diff] [blame] | 327 | if (isset($POST_REGISTER_HOOK)) $POST_REGISTER_HOOK($user); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 328 | include $TEMPLATE . "mail_confirmed.htm"; |
| 329 | } else { |
Marc Kupietz | 0314662 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 330 | $log->error("User registration failed for: " . $user->to_string()); |
matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 331 | echo $STRINGS->email_confirmation; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 332 | include $TEMPLATE . "registration_error.htm"; |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 333 | } |
| 334 | redis_delete($token); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 335 | } else { |
| 336 | include $TEMPLATE . "token_expired.htm"; |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | break; |
| 340 | case "resend": |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 341 | if (isset($_GET['token']) && isset($_SESSION['resend']) && $_GET['token'] == $_SESSION['resend']) { |
Marc Kupietz | 8e6a8df | 2023-03-07 13:05:23 +0100 | [diff] [blame] | 342 | $log->info("Resending confirmation email to " . $_SESSION['email']); |
| 343 | $user = new User(); |
| 344 | $user->init_from_array($_SESSION); |
| 345 | $log->info("Resending confirmation email to " . $user->to_string()); |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 346 | $token = $_SESSION['token']; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 347 | $url = $BASE_URL . "?type=confirmation&token=" . $token; |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 348 | $smtp = $FALLBACK_SMTP; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 349 | $address = $_SESSION["email"]; |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 350 | if (isset($_SESSION['recover'])) { |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 351 | $url = $BASE_URL . "?type=password_change&token=" . $token; |
Marc Kupietz | a3f3fdb | 2023-03-04 18:13:26 +0100 | [diff] [blame] | 352 | send_recovery_email($address, $smtp, $url, $user); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 353 | unset($_SESSION['recover']); |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 354 | } else |
Marc Kupietz | a3f3fdb | 2023-03-04 18:13:26 +0100 | [diff] [blame] | 355 | send_confirmation_email($address, $smtp, $url, $user); |
Marc Kupietz | 8e6a8df | 2023-03-07 13:05:23 +0100 | [diff] [blame] | 356 | echo "<div class='alert alert-info' role='alert'> Another email has been sent to ". $_SESSION['email']. " </div>"; |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 357 | unset($_SESSION['resend']); |
| 358 | unset($_SESSION['token']); |
Marc Kupietz | a3f3fdb | 2023-03-04 18:13:26 +0100 | [diff] [blame] | 359 | # unset($_SESSION['email']); |
| 360 | } else { |
Marc Kupietz | 8e6a8df | 2023-03-07 13:05:23 +0100 | [diff] [blame] | 361 | echo "<div class='alert alert-warning' role='alert'>A second email has already been sent.</div>"; |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 362 | } |
| 363 | break; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 364 | |
matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 365 | case "recover": |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 366 | recover_form(); |
matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 367 | break; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 368 | |
| 369 | case "password_change": |
| 370 | $TEMPLATE = template_path(); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 371 | $token = $_GET["token"]; |
| 372 | $email = redis_get($token); |
| 373 | $_SESSION["email_change"] = $email; |
Matheus Fillipe | 301684b | 2021-05-14 09:09:43 +0300 | [diff] [blame] | 374 | $_SESSION["token"] = $token; |
| 375 | if ($email && gettype($email) == "string") { |
| 376 | new_password_form(); |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 377 | } else { |
| 378 | include $TEMPLATE . "token_expired.htm"; |
| 379 | } |
matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 380 | break; |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 381 | } |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 382 | } else { |
| 383 | unset($_SESSION['captcha_token']); |
| 384 | register_page(); |
| 385 | } |
| 386 | |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 387 | include $TEMPLATE . "bottom.htm"; |