diff --git a/api/app/Http/Controllers/UserController.php b/api/app/Http/Controllers/UserController.php
index 4e6a608..29eec09 100644
--- a/api/app/Http/Controllers/UserController.php
+++ b/api/app/Http/Controllers/UserController.php
@@ -18,23 +18,23 @@ class UserController extends Controller
*/
public function index(Request $request)
{
- $this->authorize('viewAny', User::class);
+ $this->authorize("viewAny", User::class);
$query = User::query();
- if ($request->has('type')) {
- $query->where('type', $request->type);
+ if ($request->has("type")) {
+ $query->where("type", $request->type);
}
- if ($request->has('blocked')) {
- $query->where('blocked', $request->type);
+ if ($request->has("blocked")) {
+ $query->where("blocked", $request->type);
}
- if ($request->has('search')) {
+ if ($request->has("search")) {
$query->where(function ($q) use ($request) {
- $q->where('name', 'like', '%'.$request->search.'%')
- ->orWhere('email', 'like', '%'.$request->search.'%')
- ->orWhere('nickname', 'like', '%'.$request->search.'%');
+ $q->where("name", "like", "%" . $request->search . "%")
+ ->orWhere("email", "like", "%" . $request->search . "%")
+ ->orWhere("nickname", "like", "%" . $request->search . "%");
});
}
@@ -47,16 +47,16 @@ class UserController extends Controller
*/
public function store(Request $request)
{
- $this->authorize('create', User::class);
+ $this->authorize("create", User::class);
$validated = $request->validate([
- 'name' => 'required|string|max:255',
- 'email' => 'required|email|unique:users,email',
- 'password' => 'required|string|min:3',
- 'type' => 'required|in:A,U',
+ "name" => "required|string|max:255",
+ "email" => "required|email|unique:users,email",
+ "password" => "required|string|min:3",
+ "type" => "required|in:A,U",
]);
- $validated['password'] = Hash::make($validated['password']);
+ $validated["password"] = Hash::make($validated["password"]);
$user = User::create($validated);
@@ -82,15 +82,15 @@ class UserController extends Controller
$currentUser = Auth::user();
// Admins and owners get full profile, others get limited view
- if ($currentUser->type === 'A' || $currentUser->id === $user->id) {
+ if ($currentUser->type === "A" || $currentUser->id === $user->id) {
return response()->json($user);
} else {
return response()->json([
- 'id' => $user->id,
- 'name' => $user->name,
- 'nickname' => $user->nickname,
- 'photo_avatar_filename' => $user->photo_avatar_filename,
- 'type' => $user->type,
+ "id" => $user->id,
+ "name" => $user->name,
+ "nickname" => $user->nickname,
+ "photo_avatar_filename" => $user->photo_avatar_filename,
+ "type" => $user->type,
]);
}
}
@@ -101,22 +101,22 @@ class UserController extends Controller
*/
public function update(Request $request, User $user)
{
- $this->authorize('update', $user);
-
+ $this->authorize("update", $user);
+
$validated = $request->validate([
- 'name' => 'sometimes|string|max:255',
- 'nickname' => [
- 'sometimes',
- 'string',
- 'max:20',
- Rule::unique('users')->ignore($user->id),
+ "name" => "sometimes|string|max:255",
+ "nickname" => [
+ "sometimes",
+ "string",
+ "max:20",
+ Rule::unique("users")->ignore($user->id),
],
- 'email' => [
- 'sometimes',
- 'email',
- Rule::unique('users')->ignore($user->id),
+ "email" => [
+ "sometimes",
+ "email",
+ Rule::unique("users")->ignore($user->id),
],
- 'password' => 'sometimes|string|min:3',
+ "password" => "sometimes|string|min:3",
]);
// Lógica de Upload de Foto (Exemplo Básico)
@@ -130,26 +130,28 @@ class UserController extends Controller
return response()->json($user);
}
-
public function updatePassword(Request $request, User $user)
{
- $this->authorize('update', $user);
+ $this->authorize("update", $user);
$validated = $request->validate([
- 'current_password' => 'required|string',
- 'new_password' => 'required|string|min:3|confirmed',
+ "current_password" => "required|string",
+ "new_password" => "required|string|min:3|confirmed",
]);
// Verificar se a password atual está correta
- if (!Hash::check($validated['current_password'], $user->password)) {
- return response()->json(['message' => 'Current password is incorrect'], 403);
+ if (!Hash::check($validated["current_password"], $user->password)) {
+ return response()->json(
+ ["message" => "Current password is incorrect"],
+ 403,
+ );
}
// Atualizar para a nova password
- $user->password = Hash::make($validated['new_password']);
+ $user->password = Hash::make($validated["new_password"]);
$user->save();
- return response()->json(['message' => 'Password updated successfully']);
+ return response()->json(["message" => "Password updated successfully"]);
}
/**
@@ -158,24 +160,27 @@ class UserController extends Controller
*/
public function destroy(User $user)
{
- $this->authorize('delete', $user);
+ $this->authorize("delete", $user);
// Check if user has transactions or games - if so, soft delete
$hasTransactions = $user->transactions()->exists();
$hasGames = Game::where(function ($q) use ($user) {
- $q->where('player1_user_id', $user->id)
- ->orWhere('player2_user_id', $user->id);
+ $q->where("player1_user_id", $user->id)->orWhere(
+ "player2_user_id",
+ $user->id,
+ );
})->exists();
if ($hasTransactions || $hasGames) {
$user->delete(); // Soft delete
- $message = 'User account deactivated (soft-deleted due to transaction/game history)';
+ $message =
+ "User account deactivated (soft-deleted due to transaction/game history)";
} else {
$user->forceDelete(); // Hard delete
- $message = 'User permanently deleted';
+ $message = "User permanently deleted";
}
- return response()->json(['message' => $message]);
+ return response()->json(["message" => $message]);
}
/**
@@ -184,37 +189,61 @@ class UserController extends Controller
*/
public function getGames(Request $request, User $user)
{
- $this->authorize('view', $user);
+ $this->authorize("view", $user);
// Define a query base para GAMES
$query = \App\Models\Game::query()
->where(function ($q) use ($user) {
- $q->where('player1_user_id', $user->id)
- ->orWhere('player2_user_id', $user->id);
+ $q->where("player1_user_id", $user->id)->orWhere(
+ "player2_user_id",
+ $user->id,
+ );
})
- ->with(['winner', 'player1', 'player2']);
+ ->with(["winner", "player1", "player2"]);
- if ($request->has('type')) {
- $query->where('type', $request->type);
+ if ($request->has("type")) {
+ $query->where("type", $request->type);
}
- if ($request->has('status')) {
- $query->where('status', $request->status);
+ if ($request->has("status")) {
+ $query->where("status", $request->status);
}
- $sortDirection = $request->get('sort_direction', 'desc');
- $query->orderBy('began_at', $sortDirection);
+ // Date filtering
+ if ($request->has("date_from")) {
+ $query->whereDate("began_at", ">=", $request->date_from);
+ }
+
+ if ($request->has("date_to")) {
+ $query->whereDate("began_at", "<=", $request->date_to);
+ }
+
+ // Flexible sorting
+ $sortColumn = $request->get("sort_by", "began_at");
+ $sortDirection = $request->get("sort_direction", "desc");
+
+ // Whitelist sortable columns for security
+ $allowedColumns = [
+ "began_at",
+ "ended_at",
+ "total_time",
+ "total_points",
+ ];
+ if (in_array($sortColumn, $allowedColumns)) {
+ $query->orderBy($sortColumn, $sortDirection);
+ } else {
+ $query->orderBy("began_at", $sortDirection);
+ }
-
$games = $query->paginate(10);
$games->getCollection()->transform(function ($game) use ($user) {
if ($game->winner_user_id == $user->id) {
- $game->outcome = 'win';
+ $game->outcome = "win";
} elseif ($game->is_draw) {
- $game->outcome = 'draw';
+ $game->outcome = "draw";
} else {
- $game->outcome = 'loss';
+ $game->outcome = "loss";
}
return $game;
});
@@ -228,35 +257,58 @@ class UserController extends Controller
*/
public function getMatches(Request $request, User $user)
{
- $this->authorize('view', $user);
+ $this->authorize("view", $user);
- $query = MatchGame::query()
+ $query = MatchGame::query()
->where(function ($q) use ($user) {
- $q->where('player1_user_id', $user->id)
- ->orWhere('player2_user_id', $user->id);
+ $q->where("player1_user_id", $user->id)->orWhere(
+ "player2_user_id",
+ $user->id,
+ );
})
- ->with(['winner', 'player1', 'player2']);
+ ->with(["winner", "player1", "player2"]);
- if ($request->has('type')) {
- $query->where('type', $request->type);
- }
-
- if ($request->has('status')) {
- $query->where('status', $request->status);
+ if ($request->has("type")) {
+ $query->where("type", $request->type);
}
- $sortDirection = $request->get('sort_direction', 'desc');
- $query->orderBy('began_at', $sortDirection);
+ if ($request->has("status")) {
+ $query->where("status", $request->status);
+ }
+
+ // Date filtering
+ if ($request->has("date_from")) {
+ $query->whereDate("began_at", ">=", $request->date_from);
+ }
+
+ if ($request->has("date_to")) {
+ $query->whereDate("began_at", "<=", $request->date_to);
+ }
+
+ // Flexible sorting
+ $sortColumn = $request->get("sort_by", "began_at");
+ $sortDirection = $request->get("sort_direction", "desc");
+
+ // Whitelist sortable columns for security
+ $allowedColumns = ["began_at", "ended_at", "stake", "total_time"];
+ if (in_array($sortColumn, $allowedColumns)) {
+ $query->orderBy($sortColumn, $sortDirection);
+ } else {
+ $query->orderBy("began_at", $sortDirection);
+ }
$matches = $query->paginate(10);
$matches->getCollection()->transform(function ($match) use ($user) {
if ($match->winner_user_id == $user->id) {
- $match->outcome = 'win';
- } elseif ($match->winner_user_id && $match->winner_user_id != $user->id) {
- $match->outcome = 'loss';
+ $match->outcome = "win";
+ } elseif (
+ $match->winner_user_id &&
+ $match->winner_user_id != $user->id
+ ) {
+ $match->outcome = "loss";
} else {
- $match->outcome = 'interrupted'; // Matches geralmente não empatam (alguém chega a 4 marcas)
+ $match->outcome = "interrupted"; // Matches geralmente não empatam (alguém chega a 4 marcas)
}
return $match;
});
@@ -266,7 +318,7 @@ class UserController extends Controller
public function block(User $user)
{
- $this->authorize('block', $user);
+ $this->authorize("block", $user);
$user->blocked = true;
$user->save();
@@ -274,43 +326,51 @@ class UserController extends Controller
// Revoke all active tokens for immediate effect
$user->tokens()->delete();
- return response()->json(['message' => 'User blocked successfully']);
+ return response()->json(["message" => "User blocked successfully"]);
}
public function unblock(User $user)
{
- $this->authorize('unblock', $user);
+ $this->authorize("unblock", $user);
$user->blocked = false;
$user->save();
- return response()->json(['message' => 'User unblocked successfully']);
+ return response()->json(["message" => "User unblocked successfully"]);
}
public function getTransactions(Request $request, User $user)
{
- if ($request->user()->id !== $user->id && $request->user()->type !== 'A') {
- return response()->json(['message' => 'Forbidden'], 403);
+ if (
+ $request->user()->id !== $user->id &&
+ $request->user()->type !== "A"
+ ) {
+ return response()->json(["message" => "Forbidden"], 403);
}
- $query = $user->transactions()->with('type');
+ $query = $user->transactions()->with("type");
- if ($request->has('type')) {
- $query->whereHas('type', function ($q) use ($request) {
- $q->where('type', $request->type);
+ if ($request->has("type")) {
+ $query->whereHas("type", function ($q) use ($request) {
+ $q->where("type", $request->type);
});
}
- if ($request->has('date_from')) {
- $query->whereDate('transaction_datetime', '>=', $request->date_from);
+ if ($request->has("date_from")) {
+ $query->whereDate(
+ "transaction_datetime",
+ ">=",
+ $request->date_from,
+ );
}
- if ($request->has('date_to')) {
- $query->whereDate('transaction_datetime', '<=', $request->date_to);
+ if ($request->has("date_to")) {
+ $query->whereDate("transaction_datetime", "<=", $request->date_to);
}
- $transactions = $query->orderBy('transaction_datetime', 'desc')
- ->paginate(10);
+ $transactions = $query
+ ->orderBy("transaction_datetime", "desc")
+ ->paginate(10);
return response()->json($transactions);
}
diff --git a/frontend/src/components/layout/NavBar.vue b/frontend/src/components/layout/NavBar.vue
index 60230b9..c012324 100644
--- a/frontend/src/components/layout/NavBar.vue
+++ b/frontend/src/components/layout/NavBar.vue
@@ -1,64 +1,54 @@
-
- Player Card:
- {{ playerCard ? `${playerCard.suit}${playerCard.rank}` : 'None' }}
-
- Opponent Card:
- {{ opponentCard ? `${opponentCard.suit}${opponentCard.rank}` : 'None' }}
- Winner: {{ winner || 'None' }} First Player: {{ firstPlayer || 'None' }} Player Hand: {{ playerHand.length }} cards Opponent Hand: {{ opponentHand.length }} cards Cards Remaining: {{ cardsRemaining }} Dealing: {{ isDealing ? 'Yes' : 'No' }} Next Recipient: {{ nextRecipient }} Turn: {{ currentTurn === 'player' ? 'You' : 'Bot' }} Deck: {{ cardsRemaining }} cards
- All Animations Test Page
-
-
-
- Controls
-
-
- Score Count-Up Animation
- Turn Transition Animation
- Trump Reveal Animation
- Game Over Screen
- Complete Sequence
- Trump Card
- Instructions:
-
-
- Animation Test Page
-
-
- Controls
- Play Area
- Instructions:
-
-
- Card Dealing Test Page
-
-
- Controls
- Opponent Hand
- Deck
- Your Hand
- Instructions:
-
-
- Test Controls
-