set_tracked_topics(null); // Try to determine if the data in redirect_url is valid (if not, we redirect to index.php after login) $redirect_url = validate_redirect($_POST['redirect_url'], panther_link($panther_url['index'])); redirect($redirect_url, $lang_login['Login redirect']); } } else { if ($action == 'out') { if ($panther_user['is_guest'] || !isset($_GET['id']) || $_GET['id'] != $panther_user['id']) { header('Location: ' . panther_link($panther_url['index'])); exit; } confirm_referrer('login.php'); $data = array(':id' => $panther_user['id']); // Remove user from "users online" list $db->delete('online', 'user_id=:id', $data); generate_login_key(); // Update last_visit (make sure there's something to update it with) if (isset($panther_user['logged'])) { $update = array('last_visit' => $panther_user['logged']); $data = array(':id' => $panther_user['id']); $db->update('users', $update, 'id=:id', $data); } panther_setcookie(1, panther_hash(uniqid(rand(), true)), time() + 31536000); redirect(panther_link($panther_url['index']), $lang_login['Logout redirect']); } else { if ($action == 'forget') { if (!$panther_user['is_guest']) { header('Location: ' . panther_link($panther_url['index'])); exit; } if (isset($_POST['form_sent'])) {
$timezone = isset($_POST['timezone']) ? round($_POST['timezone'], 1) : ''; $dst = isset($_POST['dst']) ? 1 : 0; $email_setting = isset($_POST['email_setting']) && ($_POST['email_setting'] > 0 && $_POST['email_setting'] < 2) ? intval($_POST['email_setting']) : $panther_config['o_default_email_setting']; ($hook = get_extensions('register_after_validation')) ? eval($hook) : null; $url_username = url_friendly($username); // Did everything go according to plan? if (empty($errors)) { // Insert the new user into the database. We do this now to get the last inserted ID for later use $now = time(); $initial_group_id = $panther_config['o_regs_verify'] == '0' ? $panther_config['o_default_user_group'] : PANTHER_UNVERIFIED; $password_hash = panther_hash($password1 . $password_salt); // Add the user $insert = array('username' => $username, 'group_id' => $initial_group_id, 'password' => $password_hash, 'salt' => $password_salt, 'email' => $email1, 'email_setting' => $email_setting, 'timezone' => $timezone, 'dst' => $dst, 'language' => $language, 'style' => $panther_config['o_default_style'], 'registered' => $now, 'registration_ip' => get_remote_address(), 'last_visit' => $now); $db->insert('users', $insert); $new_uid = $db->lastInsertId($db->prefix . 'users'); $login_key = generate_login_key($new_uid); if ($panther_config['o_regs_verify'] == '0') { // Regenerate the users info cache if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) { require PANTHER_ROOT . 'include/cache.php'; } generate_users_info_cache(); } // If the mailing list isn't empty, we may need to send out some alerts if ($panther_config['o_mailing_list'] != '') { // If we previously found out that the email was banned if ($banned_email) { $info = array('message' => array('<username>' => $username, '<email>' => $email1, '<profile_url>' => panther_link($panther_url['profile'], array($new_uid, $url_username)))); $mail_tpl = $mailer->parse(PANTHER_ROOT . 'lang/' . $panther_user['language'] . '/mail_templates/banned_email_register.tpl', $info); $mailer->send($panther_config['o_mailing_list'], $mail_tpl['subject'], $mail_tpl['message']); }
function generate_login_key($uid = 1) { global $db, $panther_user; $key = random_pass(60); $data = array(':key' => $key); $ps = $db->select('users', 1, $data, 'login_key=:key'); if ($ps->rowCount()) { // There is already a key with this string (keys are unique) generate_login_key(); } else { $data = array(':id' => $uid != 1 ? $uid : $panther_user['id']); $update = array('login_key' => $key); $db->update('users', $update, 'id=:id', $data); return $key; } }