From ce7bf0918cb66f09ef1ce48f771f7a5db6007680 Mon Sep 17 00:00:00 2001 From: Dslak Date: Thu, 9 Sep 2021 17:39:29 +0200 Subject: [PATCH] register form --- api/user_add.php | 36 ++++++++--- components/account/account.html | 106 +++++++++++++++++++++++++------- components/account/account.js | 76 +++++++++++++++++++++++ components/account/account.scss | 20 ++++++ components/header/header.html | 2 +- pages/index.ejs | 4 ++ src/js/index.js | 11 ++++ src/scss/global.scss | 23 +++++++ 8 files changed, 246 insertions(+), 32 deletions(-) diff --git a/api/user_add.php b/api/user_add.php index cfd7f7b..55706bc 100644 --- a/api/user_add.php +++ b/api/user_add.php @@ -15,21 +15,37 @@ $conn = $databaseService->getConnection(); $data = json_decode(file_get_contents("php://input")); -$query = "INSERT INTO `users` +$query = "SELECT * FROM `users` WHERE email = '".trim($data->email)."'"; +$stmt = $conn->prepare($query); + +if($stmt->execute()) { + + if($stmt->rowCount()) { + http_response_code(400); + echo json_encode( + array( + "status" => 400, + "message" => "User exists" + )); + } else { + + $query = "INSERT INTO `users` (`id`, `first_name`, `last_name`, `email`, `phone`, `address`, `city`, `zip_code`, `province`, `password`) VALUES (NULL, '".trim($data->first_name)."', '".trim($data->last_name)."', '".trim($data->email)."', '".trim($data->phone)."', '".trim($data->address)."', '".trim($data->city)."', '".trim($data->zip_code)."', '".trim($data->province)."', '".md5(trim($data->password))."')"; -$stmt = $conn->prepare($query); - -if($stmt->execute()) { - http_response_code(200); - echo json_encode( - array( - "status" => 200, - "id" => $conn->lastInsertId() - )); + $stmt = $conn->prepare($query); + + if($stmt->execute()) { + http_response_code(200); + echo json_encode( + array( + "status" => 200, + "id" => $conn->lastInsertId() + )); + } + } } else { http_response_code(400); echo json_encode( diff --git a/components/account/account.html b/components/account/account.html index c90dc2d..0783f67 100644 --- a/components/account/account.html +++ b/components/account/account.html @@ -50,28 +50,96 @@ } ?> -
- - +
+ aaa +
+ diff --git a/src/js/index.js b/src/js/index.js index 6a0d258..5766164 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -180,3 +180,14 @@ window.Apis.saveOrder = (profile, cart, token, uid, total, paid = false) => { }) }) } + + +window.Apis.notification = (text) => { + const notification = $('.notification') + notification.text(text).fadeIn(10, () => { + setTimeout(() => { + notification.fadeOut(300) + },5000) + }) +} + diff --git a/src/scss/global.scss b/src/scss/global.scss index 8094303..ba3f806 100644 --- a/src/scss/global.scss +++ b/src/scss/global.scss @@ -27,6 +27,21 @@ body { animation: spinner 2s linear infinite; } } + + .notification { + display: none; + position: fixed; + top: 0; + left: 0; + width: 100%; + padding: 10px 20px; + @include font-style($font-sans, 'regular-italic', $font-16); + color: $white; + text-align: center; + background: $olive-dark; + animation: blink 3s linear; + z-index: 200; + } } @@ -164,6 +179,14 @@ button { 100% {opacity: 1;} } +@keyframes blink { + 0% { opacity: 1; } + 25% { opacity: .6; } + 50% { opacity: 1; } + 75% { opacity: .6; } + 100% { opacity: 1; } +} + .debug-border { border: 1px solid red; }