/** * function show * render and return content */ function show() { $data = json_decode(file_get_contents("php://input"), true); Mailer::send_reset_password($data['email']); $forgot_object = new stdClass(); $forgot_object->email = $data['email']; return json_encode($forgot_object); }
/** * function change mail * chgange the email * @param array $data * @param int $user_id * @return bool */ static function change_email($data = [], $user_id = 0) { if (self::change_password($data, $user_id, true, false) == true) { $query_two = Adapter::secure_query("SELECT * FROM users WHERE `mail` = :mail LIMIT 1", [':mail' => Misc::escape_text($data['newEmail'])]); if (Adapter::row_count($query_two) == 0) { $row_two = Adapter::fetch_array(Adapter::secure_query('SELECT * FROM users WHERE id = :userid', [':userid' => $user_id])); Mailer::send_change_email($row_two['mail'], $data['newEmail']); Adapter::secure_query("UPDATE cms_azure_id SET `mail` = :newmail WHERE `mail` = :oldmail", [':newmail' => Misc::escape_text($data['newEmail']), ':oldmail' => $row_two['mail']]); Adapter::secure_query("UPDATE users SET `mail` = :newmail WHERE `mail` = :oldmail", [':newmail' => Misc::escape_text($data['newEmail']), ':oldmail' => $row_two['mail']]); header('HTTP/1.1 204 No Content'); echo '{"email":"' . Misc::escape_text($data['newEmail']) . '"}'; return true; } } header('HTTP/1.1 400 Bad Request'); echo '{"error":"registration_email"}'; return false; }
/** * function user_create_instance * create instance and get data of a user * @param $user_id * @param bool $return * @return User */ static function user_create_instance($user_id, $return = false) { // get user_data $row = is_numeric($user_id) ? Adapter::fetch_object(Adapter::secure_query("SELECT * FROM users WHERE id = :userid LIMIT 1", [':userid' => $user_id])) : Adapter::fetch_object(Adapter::secure_query("SELECT * FROM users WHERE username = :userid LIMIT 1", [':userid' => $user_id])); $verified = Adapter::fetch_array(Adapter::secure_query('SELECT verified FROM cms_users_verification WHERE user_id = :userid', [':userid' => $row->id])); $new_verify = $verified['verified']; if ($new_verify != 'false' && $new_verify != 'true') { Mailer::send_nux_mail($row->mail); $new_verify = 'false'; } $is_admin = $row->rank >= 7 ? true : false; $pref = new JsonPreferences(true, $row->hide_online, $row->hide_inroom, $row->block_newfriends); $user_preferences = json_decode($pref->get_json()); $count = 0; $badge = []; foreach (Adapter::secure_query("SELECT * FROM users_badges WHERE user_id = :userid", [':userid' => $row->id]) as $row_a) { $f = new JsonBadge($row_a['badge_id'], $row_a['badge_id'], $row_a['badge_id']); $badge[$count] = json_decode($f->get_json()); if (!empty($badge[$count])) { $count++; } else { unset($badge[$count]); } } $count = 0; $badge_used = []; foreach (Adapter::secure_query("SELECT * FROM users_badges WHERE user_id = :userid AND badge_slot != 0", [':userid' => $row->id]) as $row_a) { $f = new JsonUsedBadge($row_a['badge_slot'], $row_a['badge_id'], $row_a['badge_id'], $row_a['badge_id']); $badge_used[$count] = json_decode($f->get_json()); if (!empty($badge_used[$count])) { $count++; } else { unset($badge_used[$count]); } } $count = 0; $user_friends = []; foreach (Adapter::secure_query("SELECT user_two_id FROM messenger_friendships WHERE user_one_id = :userid", [':userid' => $row->id]) as $row_a) { $row_b = Adapter::fetch_object(Adapter::secure_query("SELECT username,motto,id,look FROM users WHERE id = :userid LIMIT 1", [':userid' => $row_a['user_two_id']])); $f = new JsonFriend($row_b->username, $row_b->motto, $row_b->id, $row_b->look); $user_friends[$count] = json_decode($f->get_json()); if (!empty($user_friends[$count])) { $count++; } else { unset($user_friends[$count]); } } $count = 0; $user_rooms = []; foreach (Adapter::secure_query("SELECT * FROM rooms_data WHERE owner = :userid", [':userid' => $row->username]) as $row_a) { $f = new JsonRoom($row_a['id'], $row_a['caption'], $row_a['description'], $row->id); $user_rooms[$count] = json_decode($f->get_json()); if (!empty($user_rooms[$count])) { $count++; } else { unset($user_rooms[$count]); } } $count = 0; $user_groups = []; foreach (Adapter::secure_query("SELECT * FROM groups_members WHERE user_id = :userid", [':userid' => $row->username]) as $row_a) { $row_b = Adapter::fetch_object(Adapter::secure_query("SELECT * FROM groups_data WHERE id = :userid LIMIT 1", [':userid' => $row_a['group_id']])); $f = new JsonGroup($row_a['group_id'], $row_b->name, $row_b->desc, 'NORMAL', $row_b->badge, $row_b->room_id, $row_b->colour1, $row_b->colour2, false); $user_groups[$count] = json_decode($f->get_json()); if (!empty($user_groups[$count])) { $count++; } else { unset($user_groups[$count]); } } $user_json = new JsonUser($row->id, $row->username, $row->mail, $row->gender, $row->motto, $row->look, $badge_used, date('Y-m-d', $row->account_created) . 'T' . date('H:i:s', $row->account_created) . '.000+0000', $new_verify); self::$user_instance = new User($user_id, $row->username, $row->mail, $row->gender, $row->motto, $row->credits, $row->activity_points, "127.0.0.1", "Default", $row->look, $is_admin, $row->builders_expire, $badge, $user_friends, $user_rooms, $badge_used, $user_groups, $user_json, $user_preferences, $new_verify, $row->novato); if ($return) { return self::$user_instance; } $_SESSION['user_data'] = serialize(self::$user_instance); return null; }