Address changes.
This commit is contained in:
parent
a5949e0401
commit
635b3ddcbc
59 changed files with 7249 additions and 2745 deletions
|
@ -32,6 +32,9 @@ class CDN
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function uploadFile(string $localPath, string $remotePath, string $mimeType, string $acl = 'private')
|
||||
{
|
||||
try {
|
||||
|
@ -48,6 +51,9 @@ class CDN
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function renameFile(string $oldRemotePath, string $newRemotePath)
|
||||
{
|
||||
// S3 does not support renaming directly. Copy then delete.
|
||||
|
|
|
@ -49,4 +49,18 @@ class DJs
|
|||
$stmt->close();
|
||||
return $djs;
|
||||
}
|
||||
|
||||
public function search(string $query, int $page = 1, int $resultsPerPage = 10): array {
|
||||
$offset = ($page - 1) * $resultsPerPage;
|
||||
$likeQuery = "%" . $query . "%";
|
||||
$stmt = $this->db->prepare("SELECT * FROM djs WHERE name LIKE ? OR bio LIKE ? LIMIT ?, ?");
|
||||
$stmt->bind_param("ssii", $likeQuery, $likeQuery, $offset, $resultsPerPage);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$djs = $result->fetch_all(MYSQLI_ASSOC);
|
||||
$stmt->close();
|
||||
return $djs;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -4,32 +4,32 @@ namespace DJMixHosting;
|
|||
|
||||
class DownloadMix
|
||||
{
|
||||
private $db;
|
||||
private $mix;
|
||||
private $ready = false;
|
||||
private $name;
|
||||
private $djs;
|
||||
private $filename;
|
||||
private $url;
|
||||
private $mix_id;
|
||||
private Database $db;
|
||||
private Mix $mix;
|
||||
private bool $ready = false;
|
||||
private string $name;
|
||||
private string $djs;
|
||||
private string $filename;
|
||||
private string $url;
|
||||
private int $mix_id;
|
||||
private $content;
|
||||
private $filesize = 0;
|
||||
private $ext;
|
||||
private int $filesize = 0;
|
||||
private string $ext;
|
||||
|
||||
|
||||
public function __construct($mix, $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->mix = $mix;
|
||||
$this->mix_id = $mix->get_id();
|
||||
$this->mix_id = $mix->getId();
|
||||
$this->preDownload();
|
||||
}
|
||||
|
||||
private function preDownload()
|
||||
private function preDownload(): void
|
||||
{
|
||||
$this->name = $this->mix->get_name();
|
||||
$buildDJs = $this->mix->get_djs();
|
||||
$this->url = $this->mix->get_url();
|
||||
$this->name = $this->mix->getName();
|
||||
$buildDJs = $this->mix->getDJs();
|
||||
$this->url = $this->mix->getUrl();
|
||||
$this->djs = '';
|
||||
$djCount = 0;
|
||||
foreach ($buildDJs as $dj) {
|
||||
|
@ -42,7 +42,7 @@ class DownloadMix
|
|||
|
||||
}
|
||||
|
||||
public function download()
|
||||
public function download(): void
|
||||
{
|
||||
$this->loadDownload();
|
||||
if (!$this->ready) {
|
||||
|
@ -56,23 +56,24 @@ class DownloadMix
|
|||
}
|
||||
header("Content-Description: File Transfer");
|
||||
header("Content-Type: application/octet-stream");
|
||||
header("Content-Length: " . $this->filesize);
|
||||
header("Content-Disposition: attachment; filename=\"" . $this->filename . "\"");
|
||||
echo $this->content;
|
||||
}
|
||||
}
|
||||
|
||||
private function loadDownload()
|
||||
private function loadDownload(): void
|
||||
{
|
||||
$this->content = file_get_contents($this->url);
|
||||
$this->filesize = strlen($this->content);
|
||||
$this->ext = pathinfo(basename($this->url), PATHINFO_EXTENSION);
|
||||
$this->filename = $this->djs . ' - ' . $this->name . ' (Downloaded from UtahsDJs.com).' . pathinfo(basename($this->url), PATHINFO_EXTENSION);
|
||||
$this->filename = $this->djs . ' - ' . $this->name . ' (Downloaded from UtahsDJs.com).' . $this->ext;
|
||||
if ($this->filesize > 0) {
|
||||
$this->ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
private function checkForMixDownloadCount()
|
||||
private function checkForMixDownloadCount(): bool
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM mix_meta WHERE attribute = 'downloads' and mix_id = ?");
|
||||
$stmt->bind_param('i', $this->mix_id);
|
||||
|
@ -87,7 +88,7 @@ class DownloadMix
|
|||
}
|
||||
}
|
||||
|
||||
private function incrementMixDownloadCount()
|
||||
private function incrementMixDownloadCount(): void
|
||||
{
|
||||
$stmt = $this->db->prepare("UPDATE mix_meta SET value = value + 1 WHERE attribute = 'downloads' and mix_id = ?");
|
||||
$stmt->bind_param('i', $this->mix_id);
|
||||
|
@ -95,7 +96,7 @@ class DownloadMix
|
|||
$stmt->close();
|
||||
}
|
||||
|
||||
private function addMixDownloadCount()
|
||||
private function addMixDownloadCount(): void
|
||||
{
|
||||
$stmt = $this->db->prepare("INSERT INTO mix_meta (mix_id, attribute, value) VALUES (?, 'downloads', 1)");
|
||||
$stmt->bind_param('i', $this->mix_id);
|
||||
|
@ -103,4 +104,9 @@ class DownloadMix
|
|||
$stmt->close();
|
||||
}
|
||||
|
||||
public function getExt(): string
|
||||
{
|
||||
return $this->ext;
|
||||
}
|
||||
|
||||
}
|
|
@ -52,4 +52,17 @@ class Genres
|
|||
$stmt->close();
|
||||
return $genres;
|
||||
}
|
||||
|
||||
public function search(string $query, int $page = 1, int $resultsPerPage = 10): array {
|
||||
$offset = ($page - 1) * $resultsPerPage;
|
||||
$likeQuery = "%" . $query . "%";
|
||||
$stmt = $this->db->prepare("SELECT * FROM genres WHERE name LIKE ? LIMIT ?, ?");
|
||||
$stmt->bind_param("sii", $likeQuery, $offset, $resultsPerPage);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$genres = $result->fetch_all(MYSQLI_ASSOC);
|
||||
$stmt->close();
|
||||
return $genres;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
73
classes/Mixes.php
Normal file
73
classes/Mixes.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
namespace DJMixHosting;
|
||||
|
||||
class Mixes
|
||||
{
|
||||
private $db;
|
||||
private $mixes = [];
|
||||
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
// Automatically load all mixes upon instantiation.
|
||||
if (!$this->load_all_mixes()) {
|
||||
// Optionally, handle errors or fallback logic here.
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all mixes from the database.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function load_all_mixes(): bool
|
||||
{
|
||||
$mixes = $this->get_all_mixes();
|
||||
if ($mixes) {
|
||||
$this->mixes = $mixes;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all mixes.
|
||||
*
|
||||
* @param string $order The sort order (ASC or DESC).
|
||||
* @return array
|
||||
*/
|
||||
public function get_all_mixes(string $order = "ASC"): array
|
||||
{
|
||||
// Assuming your mix table has a column called "name"
|
||||
$stmt = $this->db->prepare("SELECT * FROM mix ORDER BY title $order");
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$mixes = $result->fetch_all(MYSQLI_ASSOC);
|
||||
$stmt->close();
|
||||
return $mixes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search mixes by name and description.
|
||||
*
|
||||
* @param string $query The search keyword.
|
||||
* @param int $page The current page number.
|
||||
* @param int $resultsPerPage The number of results per page.
|
||||
* @return array
|
||||
*/
|
||||
public function search(string $query, int $page = 1, int $resultsPerPage = 10): array
|
||||
{
|
||||
$offset = ($page - 1) * $resultsPerPage;
|
||||
$likeQuery = "%" . $query . "%";
|
||||
// Adjust the SQL if your mix table uses different column names (e.g., title instead of name)
|
||||
$stmt = $this->db->prepare("SELECT * FROM mix WHERE title LIKE ? OR description LIKE ? LIMIT ?, ?");
|
||||
$stmt->bind_param("ssii", $likeQuery, $likeQuery, $offset, $resultsPerPage);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$mixes = $result->fetch_all(MYSQLI_ASSOC);
|
||||
$stmt->close();
|
||||
return $mixes;
|
||||
}
|
||||
}
|
|
@ -52,4 +52,17 @@ class Mixshows
|
|||
$stmt->close();
|
||||
return $mixshows;
|
||||
}
|
||||
|
||||
public function search(string $query, int $page = 1, int $resultsPerPage = 10): array {
|
||||
$offset = ($page - 1) * $resultsPerPage;
|
||||
$likeQuery = "%" . $query . "%";
|
||||
$stmt = $this->db->prepare("SELECT * FROM shows WHERE name LIKE ? OR description LIKE ? LIMIT ?, ?");
|
||||
$stmt->bind_param("ssii", $likeQuery, $likeQuery, $offset, $resultsPerPage);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$mixshows = $result->fetch_all(MYSQLI_ASSOC);
|
||||
$stmt->close();
|
||||
return $mixshows;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,36 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
class RSS
|
||||
{
|
||||
class RSS {
|
||||
private string $channelTitle;
|
||||
private string $channelLink;
|
||||
private string $channelDescription;
|
||||
private array $items = [];
|
||||
private string $pubDateFormat = "D, d M Y H:i:s O";
|
||||
|
||||
private $db;
|
||||
private string $header = '<?xml version="1.0" encoding="UTF-8" ?>';
|
||||
private string $rss = '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"
|
||||
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
|
||||
xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0">';
|
||||
|
||||
|
||||
private function itemMix($mix)
|
||||
{
|
||||
$output = new Mix($mix, $this->db);
|
||||
|
||||
if ($output->get_recorded() != "") {
|
||||
$pubdate = date('D, d M Y H:i:s O', strtotime($output->get_recorded()));
|
||||
} elseif ($output->get_created() != "") {
|
||||
$pubdate = date('D, d M Y H:i:s O', strtotime($output->get_created()));
|
||||
} else {
|
||||
$pubdate = date('D, d M Y H:i:s O', strtotime('2008-01-01 12:00:00'));
|
||||
}
|
||||
|
||||
echo '<item>';
|
||||
echo '<title>' . $output->get_name() . '</title>';
|
||||
echo '<description>' . $output->get_description() . '</description>';
|
||||
echo '<link>' . $output->get_url() . '</link>';
|
||||
echo '<guid>' . $output->get_slug() . '</guid>';
|
||||
echo '<pubDate>' . $pubdate . '</pubDate>';
|
||||
echo '</item>';
|
||||
public function __construct(string $title, string $link, string $description) {
|
||||
$this->channelTitle = $title;
|
||||
$this->channelLink = $link;
|
||||
$this->channelDescription = $description;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Add an item to the RSS feed.
|
||||
*
|
||||
* @param string $title Item title.
|
||||
* @param string $description Item description.
|
||||
* @param string $link Item URL.
|
||||
* @param string $pubDate A date/time string (accepted by strtotime).
|
||||
*/
|
||||
public function addItem(string $title, string $description, string $link, string $pubDate): void {
|
||||
$this->items[] = [
|
||||
'title' => htmlspecialchars($title),
|
||||
'description' => htmlspecialchars($description),
|
||||
'link' => $link,
|
||||
'guid' => $link,
|
||||
'pubDate' => date($this->pubDateFormat, strtotime($pubDate))
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the complete RSS XML.
|
||||
*
|
||||
* @return string The RSS XML string.
|
||||
*/
|
||||
public function generateXML(): string {
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
||||
$xml .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">' . "\n";
|
||||
$xml .= " <channel>\n";
|
||||
$xml .= " <title>{$this->channelTitle}</title>\n";
|
||||
$xml .= " <link>{$this->channelLink}</link>\n";
|
||||
$xml .= " <description>{$this->channelDescription}</description>\n";
|
||||
$xml .= " <lastBuildDate>" . date($this->pubDateFormat) . "</lastBuildDate>\n";
|
||||
// Optionally add additional channel tags here
|
||||
|
||||
foreach ($this->items as $item) {
|
||||
$xml .= " <item>\n";
|
||||
$xml .= " <title>{$item['title']}</title>\n";
|
||||
$xml .= " <description>{$item['description']}</description>\n";
|
||||
$xml .= " <link>{$item['link']}</link>\n";
|
||||
$xml .= " <guid>{$item['guid']}</guid>\n";
|
||||
$xml .= " <pubDate>{$item['pubDate']}</pubDate>\n";
|
||||
$xml .= " </item>\n";
|
||||
}
|
||||
|
||||
$xml .= " </channel>\n";
|
||||
$xml .= "</rss>";
|
||||
return $xml;
|
||||
}
|
||||
}
|
||||
|
|
160
classes/User.php
160
classes/User.php
|
@ -2,29 +2,27 @@
|
|||
|
||||
namespace DJMixHosting;
|
||||
|
||||
use DateMalformedStringException;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Random\RandomException;
|
||||
use Aws\Ses\SesClient;
|
||||
use Aws\Exception\AwsException;
|
||||
|
||||
class User {
|
||||
|
||||
private $db;
|
||||
private $id;
|
||||
private $username;
|
||||
private $firstName;
|
||||
private $lastName;
|
||||
private $email;
|
||||
private $location;
|
||||
private $bio;
|
||||
private $created;
|
||||
private $updated;
|
||||
private $verified;
|
||||
private $role;
|
||||
|
||||
private $img = "";
|
||||
private $api_key;
|
||||
private Database $db;
|
||||
private string $id;
|
||||
private string $username;
|
||||
private string $firstName;
|
||||
private string $lastName;
|
||||
private string $email;
|
||||
private string $location;
|
||||
private string $bio;
|
||||
private string $created;
|
||||
private string $updated;
|
||||
private bool $verified;
|
||||
private string $role;
|
||||
private string $img = "";
|
||||
private string $api_key;
|
||||
|
||||
public function __construct($db, $id = null) {
|
||||
$this->db = $db;
|
||||
|
@ -36,7 +34,8 @@ class User {
|
|||
/**
|
||||
* Load user data from the database by id.
|
||||
*/
|
||||
private function loadUserById($id) {
|
||||
private function loadUserById($id): void
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM users WHERE id = ?");
|
||||
$stmt->bind_param("i", $id);
|
||||
$stmt->execute();
|
||||
|
@ -56,9 +55,9 @@ class User {
|
|||
$this->updated = $user_data['lastupdated'];
|
||||
$this->role = $user_data['isAdmin'] ? 'admin' : 'user';
|
||||
|
||||
// These fields are not in your table; assign defaults or remove them.
|
||||
$this->location = "";
|
||||
$this->bio = "";
|
||||
// New fields loaded from the database
|
||||
$this->location = $user_data['location'] ?? "";
|
||||
$this->bio = $user_data['bio'] ?? "";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +68,7 @@ class User {
|
|||
*/
|
||||
public function newUser(string $username, string $password, string $email, string $firstName, string $lastName): int {
|
||||
if ($this->check_existing_user($username, $email)) {
|
||||
throw new \Random\RandomException("User already exists");
|
||||
throw new RandomException("User already exists");
|
||||
}
|
||||
$this->username = $username;
|
||||
$this->email = $email;
|
||||
|
@ -87,8 +86,8 @@ class User {
|
|||
$this->img = "";
|
||||
$this->api_key = bin2hex(random_bytes(32));
|
||||
|
||||
$stmt = $this->db->prepare("INSERT INTO users (username, password, email, firstName, lastName, img, emailVerified) VALUES (?, ?, ?, ?, ?, '', 0)");
|
||||
$stmt->bind_param("sssss", $this->username, $password_hashed, $this->email, $this->firstName, $this->lastName);
|
||||
$stmt = $this->db->prepare("INSERT INTO users (username, password, email, firstName, lastName, img, emailVerified, apiKey, location, bio) VALUES (?, ?, ?, ?, ?, ?, 0, ?, ?, ?)");
|
||||
$stmt->bind_param("sssssssss", $this->username, $password_hashed, $this->email, $this->firstName, $this->lastName, $this->img, $this->api_key, $this->location, $this->bio);
|
||||
$stmt->execute();
|
||||
$userId = $stmt->insert_id;
|
||||
$stmt->close();
|
||||
|
@ -97,8 +96,8 @@ class User {
|
|||
return $userId;
|
||||
}
|
||||
|
||||
|
||||
private function check_existing_user($username, $email) {
|
||||
private function check_existing_user($username, $email): false|array|null
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM users WHERE username = ? OR email = ?");
|
||||
$stmt->bind_param("ss", $username, $email);
|
||||
$stmt->execute();
|
||||
|
@ -113,8 +112,10 @@ class User {
|
|||
*
|
||||
* Returns the user data array if successful. In case of failure,
|
||||
* a string error message is returned.
|
||||
* @throws DateMalformedStringException
|
||||
*/
|
||||
public function login($email, $password) {
|
||||
public function login($email, $password): array|string
|
||||
{
|
||||
// Retrieve user record by email
|
||||
$stmt = $this->db->prepare("SELECT * FROM users WHERE email = ?");
|
||||
$stmt->bind_param("s", $email);
|
||||
|
@ -161,6 +162,7 @@ class User {
|
|||
* Update (or create) a record in the login_attempts table for a failed attempt.
|
||||
* If attempts reach 3, set a lockout that doubles each time.
|
||||
* Returns the current number of attempts.
|
||||
* @throws DateMalformedStringException
|
||||
*/
|
||||
private function updateFailedAttempt($email) {
|
||||
// Check for an existing record
|
||||
|
@ -187,31 +189,27 @@ class User {
|
|||
$stmt = $this->db->prepare("UPDATE login_attempts SET attempts = ?, lockouts = ?, last_attempt = NOW(), lockout_until = ? WHERE email = ?");
|
||||
$lockout_until_str = $lockout_until->format('Y-m-d H:i:s');
|
||||
$stmt->bind_param("iiss", $attempts, $lockouts, $lockout_until_str, $email);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
} else {
|
||||
$stmt = $this->db->prepare("UPDATE login_attempts SET attempts = ?, last_attempt = NOW() WHERE email = ?");
|
||||
$stmt->bind_param("is", $attempts, $email);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
}
|
||||
return $attempts;
|
||||
} else {
|
||||
// Create a new record for this email
|
||||
$attempts = 1;
|
||||
$lockouts = 0;
|
||||
$stmt = $this->db->prepare("INSERT INTO login_attempts (email, attempts, lockouts, last_attempt) VALUES (?, ?, ?, NOW())");
|
||||
$stmt->bind_param("sii", $email, $attempts, $lockouts);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
return $attempts;
|
||||
}
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
return $attempts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the login_attempts record for the given email.
|
||||
*/
|
||||
private function resetLoginAttempts($email) {
|
||||
private function resetLoginAttempts($email): void
|
||||
{
|
||||
$stmt = $this->db->prepare("DELETE FROM login_attempts WHERE email = ?");
|
||||
$stmt->bind_param("s", $email);
|
||||
$stmt->execute();
|
||||
|
@ -224,12 +222,12 @@ class User {
|
|||
* @param string $newEmail
|
||||
* @param array $config Configuration array for AWS SES and app settings.
|
||||
* @return string Success message.
|
||||
* @throws \Exception on validation or email-sending failure.
|
||||
* @throws Exception on validation or email-sending failure.
|
||||
*/
|
||||
public function updateEmail(string $newEmail, array $config): string {
|
||||
$newEmail = filter_var($newEmail, FILTER_VALIDATE_EMAIL);
|
||||
if (!$newEmail) {
|
||||
throw new \Exception("Invalid email format.");
|
||||
throw new Exception("Invalid email format.");
|
||||
}
|
||||
|
||||
// Update email and mark as unverified.
|
||||
|
@ -258,7 +256,11 @@ class User {
|
|||
return "Email updated. A verification email has been sent to your new address.";
|
||||
}
|
||||
|
||||
public function updateName($firstName, $lastName) {
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function updateName($firstName, $lastName): string
|
||||
{
|
||||
// Update the user's name.
|
||||
$stmt = $this->db->prepare("UPDATE users SET firstName = ?, lastName = ? WHERE id = ?");
|
||||
$stmt->bind_param("ssi", $firstName, $lastName, $this->id);
|
||||
|
@ -274,7 +276,11 @@ class User {
|
|||
return "Name updated successfully.";
|
||||
}
|
||||
|
||||
public function updatePassword($currentPassword, $newPassword, $confirmPassword) {
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function updatePassword($currentPassword, $newPassword, $confirmPassword): string
|
||||
{
|
||||
// Retrieve the current password hash.
|
||||
$stmt = $this->db->prepare("SELECT password FROM users WHERE id = ?");
|
||||
$stmt->bind_param("i", $this->id);
|
||||
|
@ -307,7 +313,11 @@ class User {
|
|||
return "Password updated successfully.";
|
||||
}
|
||||
|
||||
public function updateUsername($newUsername) {
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function updateUsername($newUsername): string
|
||||
{
|
||||
// Validate username format.
|
||||
if (!preg_match('/^[a-zA-Z0-9_]{3,25}$/', $newUsername)) {
|
||||
throw new Exception("Invalid username format.");
|
||||
|
@ -339,7 +349,7 @@ class User {
|
|||
*
|
||||
* @param string $verification_code The code submitted by the user.
|
||||
* @return string Success message.
|
||||
* @throws \Exception If the code is invalid or expired.
|
||||
* @throws Exception If the code is invalid or expired.
|
||||
*/
|
||||
public function verifyEmail(string $verification_code): string {
|
||||
// Look up the verification record for this user and code
|
||||
|
@ -351,14 +361,14 @@ class User {
|
|||
$stmt->close();
|
||||
|
||||
if (!$record) {
|
||||
throw new \Exception("Invalid verification code.");
|
||||
throw new Exception("Invalid verification code.");
|
||||
}
|
||||
|
||||
// Check if the verification code has expired
|
||||
$current_time = new \DateTime();
|
||||
$expires_at = new \DateTime($record['expires_at']);
|
||||
$current_time = new DateTime();
|
||||
$expires_at = new DateTime($record['expires_at']);
|
||||
if ($current_time > $expires_at) {
|
||||
throw new \Exception("Verification code has expired. Please request a new one.");
|
||||
throw new Exception("Verification code has expired. Please request a new one.");
|
||||
}
|
||||
|
||||
// Update the user's record to mark the email as verified
|
||||
|
@ -379,18 +389,50 @@ class User {
|
|||
return "Email verified successfully.";
|
||||
}
|
||||
|
||||
// New setters for location and bio
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setLocation(string $location): string {
|
||||
$stmt = $this->db->prepare("UPDATE users SET location = ? WHERE id = ?");
|
||||
$stmt->bind_param("si", $location, $this->id);
|
||||
if ($stmt->execute()) {
|
||||
$this->location = $location;
|
||||
$stmt->close();
|
||||
return "Location updated successfully.";
|
||||
}
|
||||
$stmt->close();
|
||||
throw new Exception("Failed to update location.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setBio(string $bio): string {
|
||||
$stmt = $this->db->prepare("UPDATE users SET bio = ? WHERE id = ?");
|
||||
$stmt->bind_param("si", $bio, $this->id);
|
||||
if ($stmt->execute()) {
|
||||
$this->bio = $bio;
|
||||
$stmt->close();
|
||||
return "Bio updated successfully.";
|
||||
}
|
||||
$stmt->close();
|
||||
throw new Exception("Failed to update bio.");
|
||||
}
|
||||
|
||||
// Getter methods
|
||||
public function getId() { return $this->id; }
|
||||
public function getUsername() { return $this->username; }
|
||||
public function getFirstName() { return $this->firstName; }
|
||||
public function getLastName() { return $this->lastName; }
|
||||
public function getEmail() { return $this->email; }
|
||||
public function getLocation() { return $this->location; }
|
||||
public function getBio() { return $this->bio; }
|
||||
public function getCreated() { return $this->created; }
|
||||
public function getUpdated() { return $this->updated; }
|
||||
public function getVerified() { return $this->verified; }
|
||||
public function getRole() { return $this->role; }
|
||||
public function getImg() { return $this->img; }
|
||||
public function getApiKey() { return $this->api_key; }
|
||||
public function getId(): string { return $this->id; }
|
||||
public function getUsername(): string { return $this->username; }
|
||||
public function getFirstName(): string { return $this->firstName; }
|
||||
public function getLastName(): string { return $this->lastName; }
|
||||
public function getEmail(): string { return $this->email; }
|
||||
public function getLocation(): string { return $this->location; }
|
||||
public function getBio(): string { return $this->bio; }
|
||||
public function getCreated(): string { return $this->created; }
|
||||
public function getUpdated(): string { return $this->updated; }
|
||||
public function getVerified(): string { return $this->verified; }
|
||||
public function getRole(): string { return $this->role; }
|
||||
public function getImg(): string { return $this->img; }
|
||||
public function getApiKey(): string { return $this->api_key; }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue