feat: introduce reporting system and two-factor authentication (2FA)
- Added `ReportDialog` component for user-generated content reporting. - Integrated `ReportService` with create, update, and fetch report functionalities. - Enhanced `AuthService` with 2FA setup, enable, disable, and verification methods. - Updated types to include 2FA responses and reporting-related data. - Enhanced `ContentCard` UI to support reporting functionality. - Improved admin services to manage user reports and statuses.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import {
|
||||
Edit,
|
||||
Eye,
|
||||
Flag,
|
||||
Heart,
|
||||
MoreHorizontal,
|
||||
Share2,
|
||||
@@ -34,6 +35,7 @@ import { useAuth } from "@/providers/auth-provider";
|
||||
import { ContentService } from "@/services/content.service";
|
||||
import { FavoriteService } from "@/services/favorite.service";
|
||||
import type { Content } from "@/types/content";
|
||||
import { ReportDialog } from "./report-dialog";
|
||||
import { UserContentEditDialog } from "./user-content-edit-dialog";
|
||||
|
||||
interface ContentCardProps {
|
||||
@@ -49,6 +51,7 @@ export function ContentCard({ content, onUpdate }: ContentCardProps) {
|
||||
const [isLiked, setIsLiked] = React.useState(content.isLiked || false);
|
||||
const [likesCount, setLikesCount] = React.useState(content.favoritesCount);
|
||||
const [editDialogOpen, setEditDialogOpen] = React.useState(false);
|
||||
const [reportDialogOpen, setReportDialogOpen] = React.useState(false);
|
||||
|
||||
const isAuthor = user?.uuid === content.authorId;
|
||||
const isVideo = !content.mimeType.startsWith("image/");
|
||||
@@ -188,6 +191,12 @@ export function ContentCard({ content, onUpdate }: ContentCardProps) {
|
||||
<Share2 className="h-4 w-4 mr-2" />
|
||||
Partager
|
||||
</DropdownMenuItem>
|
||||
{!isAuthor && (
|
||||
<DropdownMenuItem onClick={() => setReportDialogOpen(true)}>
|
||||
<Flag className="h-4 w-4 mr-2" />
|
||||
Signaler
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
|
||||
117
frontend/src/components/report-dialog.tsx
Normal file
117
frontend/src/components/report-dialog.tsx
Normal file
@@ -0,0 +1,117 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { ReportReason, ReportService } from "@/services/report.service";
|
||||
|
||||
interface ReportDialogProps {
|
||||
contentId?: string;
|
||||
tagId?: string;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}
|
||||
|
||||
export function ReportDialog({
|
||||
contentId,
|
||||
tagId,
|
||||
open,
|
||||
onOpenChange,
|
||||
}: ReportDialogProps) {
|
||||
const [reason, setReason] = useState<ReportReason>(ReportReason.INAPPROPRIATE);
|
||||
const [description, setDescription] = useState("");
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
await ReportService.create({
|
||||
contentId,
|
||||
tagId,
|
||||
reason,
|
||||
description,
|
||||
});
|
||||
toast.success("Signalement envoyé avec succès. Merci de nous aider à maintenir la communauté sûre.");
|
||||
onOpenChange(false);
|
||||
setDescription("");
|
||||
} catch (error) {
|
||||
toast.error("Erreur lors de l'envoi du signalement.");
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Signaler le contenu</DialogTitle>
|
||||
<DialogDescription>
|
||||
Pourquoi signalez-vous ce contenu ? Un modérateur examinera votre demande.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="grid gap-4 py-4">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="reason">Raison</Label>
|
||||
<Select
|
||||
value={reason}
|
||||
onValueChange={(value) => setReason(value as ReportReason)}
|
||||
>
|
||||
<SelectTrigger id="reason">
|
||||
<SelectValue placeholder="Sélectionnez une raison" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value={ReportReason.INAPPROPRIATE}>Inapproprié</SelectItem>
|
||||
<SelectItem value={ReportReason.SPAM}>Spam</SelectItem>
|
||||
<SelectItem value={ReportReason.COPYRIGHT}>Droit d'auteur</SelectItem>
|
||||
<SelectItem value={ReportReason.OTHER}>Autre</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="description">Description (optionnelle)</Label>
|
||||
<Textarea
|
||||
id="description"
|
||||
placeholder="Détaillez votre signalement..."
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => onOpenChange(false)}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
Annuler
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={handleSubmit}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
{isSubmitting ? "Envoi..." : "Signaler"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import api from "@/lib/api";
|
||||
import type { Report, ReportStatus } from "./report.service";
|
||||
|
||||
export interface AdminStats {
|
||||
users: number;
|
||||
@@ -11,4 +12,21 @@ export const adminService = {
|
||||
const response = await api.get("/admin/stats");
|
||||
return response.data;
|
||||
},
|
||||
|
||||
getReports: async (limit = 10, offset = 0): Promise<Report[]> => {
|
||||
const response = await api.get("/reports", { params: { limit, offset } });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
updateReportStatus: async (reportId: string, status: ReportStatus): Promise<void> => {
|
||||
await api.patch(`/reports/${reportId}/status`, { status });
|
||||
},
|
||||
|
||||
deleteUser: async (userId: string): Promise<void> => {
|
||||
await api.delete(`/users/${userId}`);
|
||||
},
|
||||
|
||||
updateUser: async (userId: string, data: any): Promise<void> => {
|
||||
await api.patch(`/users/admin/${userId}`, data);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import api from "@/lib/api";
|
||||
import type { LoginResponse, RegisterPayload } from "@/types/auth";
|
||||
import type { LoginResponse, RegisterPayload, TwoFactorSetupResponse } from "@/types/auth";
|
||||
|
||||
export const AuthService = {
|
||||
async login(email: string, password: string): Promise<LoginResponse> {
|
||||
@@ -10,6 +10,14 @@ export const AuthService = {
|
||||
return data;
|
||||
},
|
||||
|
||||
async verify2fa(userId: string, token: string): Promise<LoginResponse> {
|
||||
const { data } = await api.post<LoginResponse>("/auth/verify-2fa", {
|
||||
userId,
|
||||
token,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
|
||||
async register(payload: RegisterPayload): Promise<void> {
|
||||
await api.post("/auth/register", payload);
|
||||
},
|
||||
@@ -21,4 +29,17 @@ export const AuthService = {
|
||||
async refresh(): Promise<void> {
|
||||
await api.post("/auth/refresh");
|
||||
},
|
||||
|
||||
async setup2fa(): Promise<TwoFactorSetupResponse> {
|
||||
const { data } = await api.post<TwoFactorSetupResponse>("/users/me/2fa/setup");
|
||||
return data;
|
||||
},
|
||||
|
||||
async enable2fa(token: string): Promise<void> {
|
||||
await api.post("/users/me/2fa/enable", { token });
|
||||
},
|
||||
|
||||
async disable2fa(token: string): Promise<void> {
|
||||
await api.post("/users/me/2fa/disable", { token });
|
||||
},
|
||||
};
|
||||
|
||||
40
frontend/src/services/report.service.ts
Normal file
40
frontend/src/services/report.service.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import api from "@/lib/api";
|
||||
|
||||
export enum ReportReason {
|
||||
INAPPROPRIATE = "inappropriate",
|
||||
SPAM = "spam",
|
||||
COPYRIGHT = "copyright",
|
||||
OTHER = "other",
|
||||
}
|
||||
|
||||
export enum ReportStatus {
|
||||
PENDING = "pending",
|
||||
REVIEWED = "reviewed",
|
||||
RESOLVED = "resolved",
|
||||
DISMISSED = "dismissed",
|
||||
}
|
||||
|
||||
export interface CreateReportPayload {
|
||||
contentId?: string;
|
||||
tagId?: string;
|
||||
reason: ReportReason;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export interface Report {
|
||||
uuid: string;
|
||||
reporterId: string;
|
||||
contentId?: string;
|
||||
tagId?: string;
|
||||
reason: ReportReason;
|
||||
description?: string;
|
||||
status: ReportStatus;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export const ReportService = {
|
||||
async create(payload: CreateReportPayload): Promise<void> {
|
||||
await api.post("/reports", payload);
|
||||
},
|
||||
};
|
||||
@@ -1,6 +1,8 @@
|
||||
export interface LoginResponse {
|
||||
message: string;
|
||||
userId: string;
|
||||
userId?: string;
|
||||
access_token?: string;
|
||||
refresh_token?: string;
|
||||
}
|
||||
|
||||
export interface RegisterPayload {
|
||||
@@ -17,6 +19,12 @@ export interface AuthStatus {
|
||||
username: string;
|
||||
displayName?: string;
|
||||
avatarUrl?: string;
|
||||
role?: string;
|
||||
};
|
||||
isLoading: boolean;
|
||||
}
|
||||
|
||||
export interface TwoFactorSetupResponse {
|
||||
qrCodeUrl: string;
|
||||
secret: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user