![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/.cursor-server/data/User/History/28865ccd/ |
<?php
/**
* User Model
* Migrated from Prisma User model
*/
require_once __DIR__ . '/../config/database.php';
class User {
private $conn;
private $table_name = "users";
public $id;
public $email;
public $name;
public $password;
public $role;
public $createdAt;
public $updatedAt;
public $resetPasswordToken;
public $resetPasswordTokenExpiry;
public $reminders;
public $username;
public $profilePicture;
public $bio;
public $title;
public $specialization;
public $barNumber;
public $yearsOfExperience;
public $education;
public $certifications;
public $officeLocation;
public $workPhone;
public $linkedinUrl;
public $websiteUrl;
public $availability;
public $timezone;
public $pronouns;
public $isProfilePublic;
public $lastActive;
public $hourlyRate;
public $proBono;
public $boldnessRating;
public $transparencyRating;
public $winRate;
public $totalCases;
public $wonCases;
public $lostCases;
public $averageRating;
public $isVerified;
public $xpPoints;
public $level;
public $currentStreak;
public $totalBadges;
public $reviewsWritten;
public $forumPosts;
public $helpedOthers;
public $totalEndorsements;
public $profileViews;
public $observationHours;
public $reformProposals;
public $wisdomScore;
public $civicEngagement;
public $accountBalance;
public $isPaymentVerified;
public $donationTotal;
public $subscriptionTier;
public $subscriptionExpiry;
public $theme;
public $gender;
public $phone;
public $address;
public $emergencyContact;
public $emergencyPhone;
public $dateOfBirth;
public $occupation;
public $language;
public $notifications;
public $lawFirmId;
public $isActive;
public $status;
public $experience;
public $rating;
public function __construct($db) {
$this->conn = $db;
$this->setDefaults();
}
private function setDefaults() {
$this->isProfilePublic = false;
$this->isVerified = false;
$this->isActive = true;
$this->isPaymentVerified = false;
$this->notifications = true;
$this->role = 'USER';
$this->status = 'ACTIVE';
$this->theme = 'light';
$this->language = 'en';
$this->totalCases = 0;
$this->wonCases = 0;
$this->lostCases = 0;
$this->xpPoints = 0;
$this->level = 1;
$this->currentStreak = 0;
$this->totalBadges = 0;
$this->reviewsWritten = 0;
$this->forumPosts = 0;
$this->helpedOthers = 0;
$this->totalEndorsements = 0;
$this->profileViews = 0;
$this->observationHours = 0;
$this->reformProposals = 0;
$this->wisdomScore = 0;
$this->civicEngagement = 0;
$this->accountBalance = 0;
$this->donationTotal = 0;
}
// Create user
public function create() {
$query = "INSERT INTO " . $this->table_name . "
(id, email, name, password, role, createdAt, updatedAt, username, language, theme, isProfilePublic, isVerified, isActive, status, totalCases, wonCases, lostCases, xpPoints, level, currentStreak, totalBadges, reviewsWritten, forumPosts, helpedOthers, totalEndorsements, profileViews, observationHours, reformProposals, wisdomScore, civicEngagement, accountBalance, isPaymentVerified, donationTotal, notifications)
VALUES
(:id, :email, :name, :password, :role, :createdAt, :updatedAt, :username, :language, :theme, :isProfilePublic, :isVerified, :isActive, :status, :totalCases, :wonCases, :lostCases, :xpPoints, :level, :currentStreak, :totalBadges, :reviewsWritten, :forumPosts, :helpedOthers, :totalEndorsements, :profileViews, :observationHours, :reformProposals, :wisdomScore, :civicEngagement, :accountBalance, :isPaymentVerified, :donationTotal, :notifications)";
$stmt = $this->conn->prepare($query);
// Generate UUID for id
$this->id = $this->generateUUID();
$this->createdAt = date('Y-m-d H:i:s');
$this->updatedAt = date('Y-m-d H:i:s');
// Hash password
$this->password = password_hash($this->password, PASSWORD_DEFAULT);
// Bind values
$stmt->bindParam(':id', $this->id);
$stmt->bindParam(':email', $this->email);
$stmt->bindParam(':name', $this->name);
$stmt->bindParam(':password', $this->password);
$stmt->bindParam(':role', $this->role);
$stmt->bindParam(':createdAt', $this->createdAt);
$stmt->bindParam(':updatedAt', $this->updatedAt);
$stmt->bindParam(':username', $this->username);
$stmt->bindParam(':language', $this->language);
$stmt->bindParam(':theme', $this->theme);
$stmt->bindParam(':isProfilePublic', $this->isProfilePublic);
$stmt->bindParam(':isVerified', $this->isVerified);
$stmt->bindParam(':isActive', $this->isActive);
$stmt->bindParam(':status', $this->status);
$stmt->bindParam(':totalCases', $this->totalCases);
$stmt->bindParam(':wonCases', $this->wonCases);
$stmt->bindParam(':lostCases', $this->lostCases);
$stmt->bindParam(':xpPoints', $this->xpPoints);
$stmt->bindParam(':level', $this->level);
$stmt->bindParam(':currentStreak', $this->currentStreak);
$stmt->bindParam(':totalBadges', $this->totalBadges);
$stmt->bindParam(':reviewsWritten', $this->reviewsWritten);
$stmt->bindParam(':forumPosts', $this->forumPosts);
$stmt->bindParam(':helpedOthers', $this->helpedOthers);
$stmt->bindParam(':totalEndorsements', $this->totalEndorsements);
$stmt->bindParam(':profileViews', $this->profileViews);
$stmt->bindParam(':observationHours', $this->observationHours);
$stmt->bindParam(':reformProposals', $this->reformProposals);
$stmt->bindParam(':wisdomScore', $this->wisdomScore);
$stmt->bindParam(':civicEngagement', $this->civicEngagement);
$stmt->bindParam(':accountBalance', $this->accountBalance);
$stmt->bindParam(':isPaymentVerified', $this->isPaymentVerified);
$stmt->bindParam(':donationTotal', $this->donationTotal);
$stmt->bindParam(':notifications', $this->notifications);
if($stmt->execute()) {
return true;
}
return false;
}
// Read user by email
public function findByEmail($email) {
$query = "SELECT * FROM " . $this->table_name . " WHERE email = :email LIMIT 1";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(':email', $email);
$stmt->execute();
if($stmt->rowCount() > 0) {
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$this->id = $row['id'];
$this->email = $row['email'];
$this->name = $row['name'];
$this->password = $row['password'];
$this->role = $row['role'];
$this->createdAt = $row['createdAt'];
$this->updatedAt = $row['updatedAt'];
$this->username = $row['username'];
$this->language = $row['language'];
$this->theme = $row['theme'];
$this->isProfilePublic = $row['isProfilePublic'];
$this->isVerified = $row['isVerified'];
$this->isActive = $row['isActive'];
$this->status = $row['status'];
return true;
}
return false;
}
// Read user by ID
public function findById($id) {
$query = "SELECT * FROM " . $this->table_name . " WHERE id = :id LIMIT 1";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(':id', $id);
$stmt->execute();
if($stmt->rowCount() > 0) {
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$this->id = $row['id'];
$this->email = $row['email'];
$this->name = $row['name'];
$this->password = $row['password'];
$this->role = $row['role'];
$this->createdAt = $row['createdAt'];
$this->updatedAt = $row['updatedAt'];
$this->username = $row['username'];
$this->language = $row['language'];
$this->theme = $row['theme'];
$this->isProfilePublic = $row['isProfilePublic'];
$this->isVerified = $row['isVerified'];
$this->isActive = $row['isActive'];
$this->status = $row['status'];
return true;
}
return false;
}
// Update user
public function update() {
$query = "UPDATE " . $this->table_name . "
SET name = :name,
updatedAt = :updatedAt,
username = :username,
profilePicture = :profilePicture,
bio = :bio,
title = :title,
specialization = :specialization,
barNumber = :barNumber,
yearsOfExperience = :yearsOfExperience,
education = :education,
certifications = :certifications,
officeLocation = :officeLocation,
workPhone = :workPhone,
linkedinUrl = :linkedinUrl,
websiteUrl = :websiteUrl,
availability = :availability,
timezone = :timezone,
pronouns = :pronouns,
isProfilePublic = :isProfilePublic,
lastActive = :lastActive,
hourlyRate = :hourlyRate,
proBono = :proBono,
boldnessRating = :boldnessRating,
transparencyRating = :transparencyRating,
winRate = :winRate,
totalCases = :totalCases,
wonCases = :wonCases,
lostCases = :lostCases,
averageRating = :averageRating,
isVerified = :isVerified,
xpPoints = :xpPoints,
level = :level,
currentStreak = :currentStreak,
totalBadges = :totalBadges,
reviewsWritten = :reviewsWritten,
forumPosts = :forumPosts,
helpedOthers = :helpedOthers,
totalEndorsements = :totalEndorsements,
profileViews = :profileViews,
observationHours = :observationHours,
reformProposals = :reformProposals,
wisdomScore = :wisdomScore,
civicEngagement = :civicEngagement,
accountBalance = :accountBalance,
isPaymentVerified = :isPaymentVerified,
donationTotal = :donationTotal,
subscriptionTier = :subscriptionTier,
subscriptionExpiry = :subscriptionExpiry,
theme = :theme,
gender = :gender,
phone = :phone,
address = :address,
emergencyContact = :emergencyContact,
emergencyPhone = :emergencyPhone,
dateOfBirth = :dateOfBirth,
occupation = :occupation,
language = :language,
notifications = :notifications,
lawFirmId = :lawFirmId,
isActive = :isActive,
status = :status,
experience = :experience,
rating = :rating
WHERE id = :id";
$stmt = $this->conn->prepare($query);
$this->updatedAt = date('Y-m-d H:i:s');
// Bind values
$stmt->bindParam(':id', $this->id);
$stmt->bindParam(':name', $this->name);
$stmt->bindParam(':updatedAt', $this->updatedAt);
$stmt->bindParam(':username', $this->username);
$stmt->bindParam(':profilePicture', $this->profilePicture);
$stmt->bindParam(':bio', $this->bio);
$stmt->bindParam(':title', $this->title);
$stmt->bindParam(':specialization', $this->specialization);
$stmt->bindParam(':barNumber', $this->barNumber);
$stmt->bindParam(':yearsOfExperience', $this->yearsOfExperience);
$stmt->bindParam(':education', $this->education);
$stmt->bindParam(':certifications', $this->certifications);
$stmt->bindParam(':officeLocation', $this->officeLocation);
$stmt->bindParam(':workPhone', $this->workPhone);
$stmt->bindParam(':linkedinUrl', $this->linkedinUrl);
$stmt->bindParam(':websiteUrl', $this->websiteUrl);
$stmt->bindParam(':availability', $this->availability);
$stmt->bindParam(':timezone', $this->timezone);
$stmt->bindParam(':pronouns', $this->pronouns);
$stmt->bindParam(':isProfilePublic', $this->isProfilePublic);
$stmt->bindParam(':lastActive', $this->lastActive);
$stmt->bindParam(':hourlyRate', $this->hourlyRate);
$stmt->bindParam(':proBono', $this->proBono);
$stmt->bindParam(':boldnessRating', $this->boldnessRating);
$stmt->bindParam(':transparencyRating', $this->transparencyRating);
$stmt->bindParam(':winRate', $this->winRate);
$stmt->bindParam(':totalCases', $this->totalCases);
$stmt->bindParam(':wonCases', $this->wonCases);
$stmt->bindParam(':lostCases', $this->lostCases);
$stmt->bindParam(':averageRating', $this->averageRating);
$stmt->bindParam(':isVerified', $this->isVerified);
$stmt->bindParam(':xpPoints', $this->xpPoints);
$stmt->bindParam(':level', $this->level);
$stmt->bindParam(':currentStreak', $this->currentStreak);
$stmt->bindParam(':totalBadges', $this->totalBadges);
$stmt->bindParam(':reviewsWritten', $this->reviewsWritten);
$stmt->bindParam(':forumPosts', $this->forumPosts);
$stmt->bindParam(':helpedOthers', $this->helpedOthers);
$stmt->bindParam(':totalEndorsements', $this->totalEndorsements);
$stmt->bindParam(':profileViews', $this->profileViews);
$stmt->bindParam(':observationHours', $this->observationHours);
$stmt->bindParam(':reformProposals', $this->reformProposals);
$stmt->bindParam(':wisdomScore', $this->wisdomScore);
$stmt->bindParam(':civicEngagement', $this->civicEngagement);
$stmt->bindParam(':accountBalance', $this->accountBalance);
$stmt->bindParam(':isPaymentVerified', $this->isPaymentVerified);
$stmt->bindParam(':donationTotal', $this->donationTotal);
$stmt->bindParam(':subscriptionTier', $this->subscriptionTier);
$stmt->bindParam(':subscriptionExpiry', $this->subscriptionExpiry);
$stmt->bindParam(':theme', $this->theme);
$stmt->bindParam(':gender', $this->gender);
$stmt->bindParam(':phone', $this->phone);
$stmt->bindParam(':address', $this->address);
$stmt->bindParam(':emergencyContact', $this->emergencyContact);
$stmt->bindParam(':emergencyPhone', $this->emergencyPhone);
$stmt->bindParam(':dateOfBirth', $this->dateOfBirth);
$stmt->bindParam(':occupation', $this->occupation);
$stmt->bindParam(':language', $this->language);
$stmt->bindParam(':notifications', $this->notifications);
$stmt->bindParam(':lawFirmId', $this->lawFirmId);
$stmt->bindParam(':isActive', $this->isActive);
$stmt->bindParam(':status', $this->status);
$stmt->bindParam(':experience', $this->experience);
$stmt->bindParam(':rating', $this->rating);
if($stmt->execute()) {
return true;
}
return false;
}
// Delete user
public function delete() {
$query = "DELETE FROM " . $this->table_name . " WHERE id = :id";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(':id', $this->id);
if($stmt->execute()) {
return true;
}
return false;
}
// Verify password
public function verifyPassword($password) {
return password_verify($password, $this->password);
}
// Generate UUID
private function generateUUID() {
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0x0fff) | 0x4000,
mt_rand(0, 0x3fff) | 0x8000,
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
// Get all users with pagination
public function getAll($page = 1, $limit = 10, $filters = []) {
$offset = ($page - 1) * $limit;
$whereClause = "WHERE 1=1";
$params = [];
// Apply filters
if (!empty($filters['role'])) {
$whereClause .= " AND role = :role";
$params[':role'] = $filters['role'];
}
if (!empty($filters['isVerified'])) {
$whereClause .= " AND isVerified = :isVerified";
$params[':isVerified'] = $filters['isVerified'];
}
if (!empty($filters['search'])) {
$whereClause .= " AND (name LIKE :search OR email LIKE :search OR specialization LIKE :search)";
$params[':search'] = '%' . $filters['search'] . '%';
}
$query = "SELECT * FROM " . $this->table_name . " " . $whereClause . " ORDER BY createdAt DESC LIMIT :limit OFFSET :offset";
$stmt = $this->conn->prepare($query);
foreach ($params as $key => $value) {
$stmt->bindValue($key, $value);
}
$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
$stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
// Count total users
public function count($filters = []) {
$whereClause = "WHERE 1=1";
$params = [];
// Apply filters
if (!empty($filters['role'])) {
$whereClause .= " AND role = :role";
$params[':role'] = $filters['role'];
}
if (!empty($filters['isVerified'])) {
$whereClause .= " AND isVerified = :isVerified";
$params[':isVerified'] = $filters['isVerified'];
}
if (!empty($filters['search'])) {
$whereClause .= " AND (name LIKE :search OR email LIKE :search OR specialization LIKE :search)";
$params[':search'] = '%' . $filters['search'] . '%';
}
$query = "SELECT COUNT(*) as total FROM " . $this->table_name . " " . $whereClause;
$stmt = $this->conn->prepare($query);
foreach ($params as $key => $value) {
$stmt->bindValue($key, $value);
}
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
return $row['total'];
}
}
?>