From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: ** X-Spam-Status: No, score=2.2 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by gnuweeb.org (Postfix) with ESMTPS id E28CF817D0 for ; Sun, 27 Nov 2022 20:33:03 +0000 (UTC) Received: by mail-pf1-f173.google.com with SMTP id a9so5204878pfr.0 for ; Sun, 27 Nov 2022 12:33:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=99f4CKF2PGIJ0l7/L4EAO3t8dUENWSf2FOijhOY4sAY=; b=WSWVsq72P+fHv3vNO+zpn2vu2eC4tKBo9lZk4MJKXouvtNNY/jLnSU0H8evQ4lQTum BrlCL3q2wtvWzo1e1ENa9K024Y34WF3p3GhkGyL2TfifQgGOGMY7+DnGB3Q/EvPS938x Q15dHlQOb635X4s8AZuAHpSjwmA5+w8dLQCSg/7I7h5Jtf9lDFOPu4LMJpS/YGtqplAq 9iJanbW0ILE1tCrhVbRlKYrBsaiSh2LHZarvphx5wBcccfEPn3I+wzi7f3W95G7tmmgV EbqtWrZ+QRyS4RYyk3BD6o1gPv6gzvIShjo9HuuvITaLR1GFdqXO/ijuHxjUvrecV6/j Ygug== X-Gm-Message-State: ANoB5pmPRuEwSlKr8XDNaUXzEODrMltYsUPIs9sSGq5BTzSKsLG0uMpD CVDap0Yvk+PqE+Lpj6SX0Ek= X-Google-Smtp-Source: AA0mqf6jtV84d/HkfIqfYXswSremr6j5r5owPp1rTEbTdqRXEFQX5SnBnFUuhErXPgqWxw0utXvf3w== X-Received: by 2002:a63:4081:0:b0:46f:e657:7d25 with SMTP id n123-20020a634081000000b0046fe6577d25mr41830308pga.347.1669581183321; Sun, 27 Nov 2022 12:33:03 -0800 (PST) Received: from localhost.localdomain ([2404:8000:1021:2a9:da99:231d:4dfa:7f54]) by smtp.gmail.com with ESMTPSA id ij13-20020a170902ab4d00b0018685257c0dsm7234904plb.58.2022.11.27.12.33.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Nov 2022 12:33:03 -0800 (PST) From: Ammar Faizi To: Gilang Fachrezy Cc: Ammar Faizi , Taufiq Pohan , Aldy Prastyo , Muhammad Fitrah Pandjalu , Nauvalsa Yanandana , GNU/Weeb Mailing List , VNLX Kernel Department Subject: [PATCH v1 13/13] index: Make sure there is no duplicate submission in the same day Date: Mon, 28 Nov 2022 03:32:16 +0700 Message-Id: <20221127203216.408808-14-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221127203216.408808-1-ammarfaizi2@gnuweeb.org> References: <20221127203216.408808-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: It's possible that a user resubmit the same data in the same day. Avoid it! Co-authored-by: Muhammad Fitrah Pandjalu Signed-off-by: Muhammad Fitrah Pandjalu Co-authored-by: Taufiq Pohan Signed-off-by: Taufiq Pohan Signed-off-by: Ammar Faizi --- public/api.php | 21 ++++++++++++++++++++- public/index.php | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/public/api.php b/public/api.php index 8305552..7250075 100644 --- a/public/api.php +++ b/public/api.php @@ -2,7 +2,7 @@ require __DIR__."/../helpers.php"; -date_default_timezone_set("UTC"); +date_default_timezone_set("Asia/Jakarta"); function err_msg(int $code, string $msg): array { @@ -25,6 +25,21 @@ const SOCIAL_MEDIA = [ "github_username", ]; +function has_email_been_saved(PDO $pdo, string $email): bool +{ + $st = $pdo->prepare(<<execute([$email, (int)date("d"), (int)date("m"), date("Y")]); + return (bool)(int)$st->fetch(PDO::FETCH_NUM)[0]; +} + function submit_attendance(): array { if ($_SERVER["REQUEST_METHOD"] !== "POST") @@ -62,6 +77,10 @@ function submit_attendance(): array try { $pdo = pdo(); + + if (has_email_been_saved($pdo, $j["email"])) + return [400, err_msg(400, "Your data has already been recorded, please don't submit a duplicate submission!")]; + $st = $pdo->prepare(<<