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