File size: 3,247 Bytes
4ca3337
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from flask import Flask, request, render_template_string
import pandas as pd
from datetime import datetime
import os

app = Flask(__name__)

CSV_FILE = "people.csv"

HTML_TEMPLATE = """
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <title>Vérification d'enregistrement</title>
    <style>
        body {
            font-family: 'Segoe UI', sans-serif;
            background: linear-gradient(to right, #f8f9fa, #e9ecef);
            text-align: center;
            padding: 2rem;
            color: #212529;
        }
        .container {
            max-width: 600px;
            margin: auto;
            background-color: white;
            padding: 2rem;
            border-radius: 15px;
            box-shadow: 0 4px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #007bff;
        }
        .status {
            font-size: 1.5rem;
            margin-top: 1rem;
        }
        .timestamp {
            color: #6c757d;
            font-size: 0.95rem;
            margin-top: 0.5rem;
        }
        @media (max-width: 600px) {
            body {
                padding: 1rem;
            }
            .container {
                padding: 1.5rem;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Vérification d'enregistrement</h1>
        {% if person %}
            <p><strong>Nom:</strong> {{ person.name }}</p>
            <p><strong>Email:</strong> {{ person.email }}</p>
            <p class="status">{{ status }}</p>
            {% if timestamp %}
                <p class="timestamp">Enregistré le {{ timestamp }}</p>
            {% endif %}
        {% else %}
            <p class="status">❌ Utilisateur non trouvé.</p>
        {% endif %}
    </div>
</body>
</html>
"""

@app.route('/')
def check_registration():
    email = request.args.get("email")
    phone = request.args.get("phone")

    if not os.path.exists(CSV_FILE):
        return "Fichier CSV non trouvé."

    df = pd.read_csv(CSV_FILE)

    # Recherche par email ou téléphone
    if email:
        person_row = df[df['email'] == email]
    elif phone:
        person_row = df[df['phone'] == phone]
    else:
        person_row = pd.DataFrame()

    if not person_row.empty:
        index = person_row.index[0]
        registered = person_row.at[index, "registered"]

        if not registered:
            # Marquer comme enregistré
            df.at[index, "registered"] = True
            timestamp = datetime.now().strftime("%d/%m/%Y à %Hh%M")
            df.at[index, "timestamp"] = timestamp
            df.to_csv(CSV_FILE, index=False)
            status = "✅ Enregistrement effectué avec succès."
        else:
            timestamp = person_row.at[index, "timestamp"]
            status = "✅ Utilisateur déjà enregistré."
        
        person = {
            "name": person_row.at[index, "name"],
            "email": person_row.at[index, "email"]
        }
        return render_template_string(HTML_TEMPLATE, person=person, status=status, timestamp=timestamp)
    else:
        return render_template_string(HTML_TEMPLATE, person=None, status=None, timestamp=None)

if __name__ == '__main__':
    app.run(debug=True, host="0.0.0.0", port=8000)