diff --git a/Dockerfile b/Dockerfile index ed963e0d7ba40f22abc61916e935d34f4b65e5ba..4a99758304cf6d67bf337c51109ad2abfde5968b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,17 @@ COPY ./app /var/www/html RUN echo "ServerName localhost:80" >> /etc/apache2/apache2.conf CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"] +RUN sudo chown www-data:www-data /var/www/html/public/img/anime/ +RUN sudo chmod 755 /var/www/html/public/img/anime/ + +RUN sudo chown www-data:www-data /var/www/html/public/img/client/ +RUN sudo chmod 755 /var/www/html/public/img/client/ + +RUN sudo chown www-data:www-data /var/www/html/public/img/studio/ +RUN sudo chmod 755 /var/www/html/public/img/studio/ + +RUN sudo chown www-data:www-data /var/www/html/public/vid/ +RUN sudo chmod 755 /var/www/html/public/vid/ + + RUN service apache2 restart \ No newline at end of file diff --git a/app/api/auth/signup.php b/app/api/auth/signup.php index 4c706f345a35056ffdf5a223d99f9c7058a84eb0..945f2ff1c316382cfbe6f6ca15a65c7ab80adcc5 100644 --- a/app/api/auth/signup.php +++ b/app/api/auth/signup.php @@ -2,16 +2,42 @@ require_once(dirname(__DIR__,2).'/define.php'); require_once(BASE_DIR.'/models/Client.php'); -session_start(); -if (isset($_POST['username']) && isset($_POST['email'])){ - $c = new Client(); - $username = $c->getClientByUsername($_POST['username']); - $email = $c->getClientByEmail($_POST['email']); - // echo $username['client_id']; - if (!$username || !$email){ - $_SESSION['error'] = 'Username or Email already exists'; - header('Location: /?signup'); +$c = new Client(); +$xml = file_get_contents('php://input'); +$data = json_decode($xml, true); + +if (isset($data['email'])){ + $email = $c->getClientByEmail($data['email']); + if (!$email){ + http_response_code(200); + echo json_encode(array( + 'status' => 'success', + 'message' => 'Email is allowed' + )); + // $_SESSION['error'] = 'Username or Email already exists'; + // header('Location: /?signup'); + } else { + echo json_encode(array( + 'status' => 'error', + 'message' => 'Email already exists' + )); + } +} + +if (isset($data['username'])){ + $username = $c->getClientByUsername($data['username']); + if (!$username){ + http_response_code(200); + echo json_encode(array( + 'status' => 'success', + 'message' => 'Username is allowed' + )); + } else { + echo json_encode(array( + 'status' => 'error', + 'message' => 'Username already exists' + )); } } diff --git a/app/api/client/edit.php b/app/api/client/edit.php index bbbcd2497b049e8006b538b78f7f04dc438f0bde..365dc61434907e06a2e8e520c238a5710afa04fb 100644 --- a/app/api/client/edit.php +++ b/app/api/client/edit.php @@ -62,6 +62,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { $counter = 1; while (file_exists($target_file)) { $info = pathinfo($original_name); + chown($$info['dirname'], 0755); $target_file = $info['dirname'] . '/' . $info['filename'] . '_' . $counter . '.' . $info['extension']; $counter++; } diff --git a/app/public/handler/signup.js b/app/public/handler/signup.js index 78b376ca33b89ff69d6c67aa77c7ea3186c5c848..dbc8e831cbffe0bde403e9bbd66ee034faff324a 100644 --- a/app/public/handler/signup.js +++ b/app/public/handler/signup.js @@ -13,8 +13,23 @@ function checkEmail() { document.getElementById("email").style.borderColor = 'red'; document.getElementById("email-errmsg").innerHTML = "Invalid email detected"; } else { - document.getElementById("email").style.borderColor = 'blue'; - document.getElementById("email-errmsg").innerHTML = ""; + const xhr = new XMLHttpRequest(); + xhr.open('POST', '../../api/auth/signup.php', true); + xhr.onload = function(){ + if (this.status == 200){ + let response = JSON.parse(this.responseText); + console.log(response); + if (response.status == "success"){ + document.getElementById("email").style.borderColor = 'blue'; + document.getElementById("email-errmsg").innerHTML = ""; + } else { + document.getElementById("email").style.borderColor = 'red'; + document.getElementById("email-errmsg").innerHTML = response.message; + } + } + checkSubmitButton(); + } + xhr.send(JSON.stringify({"email": email})); } checkSubmitButton(); } @@ -23,12 +38,26 @@ function checkUsername() { let username = document.getElementById("username").value; let passed = username.match(/^[0-9a-zA-Z]*$/) && username.length >=5; - if (!passed){ - document.getElementById('username').style.borderColor = 'red'; - document.getElementById('username-errmsg').innerHTML = "Username can only be alphanumeric with at lease 5 characters long"; + if (!passed) { + document.getElementById("username").style.borderColor = 'red'; + document.getElementById("username-errmsg").innerHTML = "Invalid username detected"; } else { - document.getElementById("username").style.borderColor = 'blue'; - document.getElementById('username-errmsg').innerHTML = ""; + const xhr = new XMLHttpRequest(); + xhr.open('POST', '../../api/auth/signup.php', true); + xhr.onload = function(){ + if (this.status == 200){ + let response = JSON.parse(this.responseText); + if (response.status == "success"){ + document.getElementById("username").style.borderColor = 'blue'; + document.getElementById("username-errmsg").innerHTML = ""; + } else { + document.getElementById("username").style.borderColor = 'red'; + document.getElementById("username-errmsg").innerHTML = response.message; + } + } + checkSubmitButton(); + } + xhr.send(JSON.stringify({"username": username})); } checkSubmitButton(); } diff --git a/app/public/img/client/1204138.jpg b/app/public/img/client/1204138.jpg new file mode 100644 index 0000000000000000000000000000000000000000..499678ac20123181b9d4f735d60622998f4e54d0 Binary files /dev/null and b/app/public/img/client/1204138.jpg differ diff --git a/app/public/img/client/test.jpg b/app/public/img/client/test.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1f42713deb1a43654cb743714f8095d64d0248e0 Binary files /dev/null and b/app/public/img/client/test.jpg differ diff --git a/app/views/Client/detail.php b/app/views/Client/detail.php index f5d9070feefa33bc7e41a4dca5ce63e72b8746a7..1edaaa7dd605e7d5465d23bed2d9bbc3093abf75 100644 --- a/app/views/Client/detail.php +++ b/app/views/Client/detail.php @@ -135,9 +135,9 @@ $isUser = $c->getClientByUsername($_SESSION['username'])['client_id'] == $id; <div class='client-right-container'> <div class='client-bio-container'> <?php - $bio = $client['bio'] ?? "No bio details"; + $bio = (!$client['bio'] || $client['bio'] == "") ? "No bio details" : $client['bio']; echo " - <div style='margin:20px 20px'> $client[bio] </div> + <div style='margin:20px 20px'> $bio</div> "; ?> </div> diff --git a/app/views/signup/index.php b/app/views/signup/index.php index bf7a4fd910dd3d4aba84de1954403fe2ebf968db..06b8ac3a69196450cc1ebc93387fe901d21585e7 100644 --- a/app/views/signup/index.php +++ b/app/views/signup/index.php @@ -23,15 +23,17 @@ require_once(dirname(__DIR__,2).'/define.php'); <form action="/api/auth/signup.php" method="post" class='form'> <div class="form-group"> <label class='form-label' for="email">E-mail</label> - <input - class="form-input" - type="email" - id="email" - name="email" - placeholder="Enter your email." - onkeyup="checkEmail()" + <input + class='form-input' + type='email' + id='email' + name='email' + placeholder='Enter your email.' + onkeyup='checkEmail()' required /> + + <div id="email-errmsg" class='form-err-message'></div> </div>