Skip to content
Snippets Groups Projects
Commit 301d534c authored by Adylan Roaffa's avatar Adylan Roaffa
Browse files

register done'

parent 4e8c0f2a
No related merge requests found
Showing
with 374 additions and 268 deletions
This diff is collapsed.
......@@ -9,7 +9,7 @@
}
function getOrder(Request $request){
$user_id = (int)$_COOKIE["user_id"];
$user_id = (int)getJwtData($_COOKIE["Authorization"])->user_id;
$orders = $this->orderDb->getOrder($user_id);
......
......@@ -11,7 +11,7 @@
function getReviews(Request $request) {
$book_id = (int)$request->params["book_id"];
$reviews = $this->reviewDb->getReviewsByBookId($book_id);
writeResponse(200, "Success get reviews by book id : %" + $book_id + "%", $reviews);
writeResponse(200, "Success get reviews by book id : %".$book_id."%", $reviews);
}
function addReview(Request $request) {
......@@ -33,7 +33,7 @@
function getReviewBookDetail(Request $request) {
$book_id = (int)$request->params["book_id"];
$books = $this->reviewDb->getBookById($book_id);
$user_id = $_COOKIE["user_id"];
$user_id = getJwtData($_COOKIE["Authorization"])->user_id;
$books->user_id = $user_id;
$data = [
......
......@@ -9,7 +9,6 @@
$user_id = verifyJWT($_COOKIE["Authorization"]);
if ($user_id){
setcookie("user_id", $user_id, time()+300, "/");
$next($nextRequest);
exit;
}
......
......@@ -35,11 +35,11 @@
if ($user){
$payload = array(
"user_id"=> (int)$user->user_id,
"exp"=> time()+3000,
"exp"=> time()+APP_CONFIG["jwt_duration"],
"username" => $username
);
$jwt = generateJWT($payload);
setcookie("Authorization", $jwt["token"], time()+APP_CONFIG["jwt_duration"],"/");
setcookie("Authorization", $jwt["token"], time()+APP_CONFIG["cookie_duration"],"/");
var_dump($_COOKIE["Authorization"]);
header('Location: /browse/'); } else {
writeResponse(500, "Failed register user");
......
<?php
include __STATIC__.'/html/header.html';
render('header.php');
?>
<link rel="stylesheet" href="/static/css/base.css">
......
......@@ -18,7 +18,7 @@
<div class="edit-profile-picture">
<img src="<?= $user->imgPath ?>" class="edit-picture-img">
<div class="edit-picture-input">
<input type="text" class="picture-input-text" >
<span class="image-upload-label" >Update profile picture</span>
<input type="file" id="profile_picture" name="profile_picture" class="picture-input-file" >
</div>
</div>
......@@ -45,6 +45,7 @@
</form>
</body>
<script src="/static/js/edit-profile.js"></script>
<?php
include __STATIC__.'/html/footer.html';
?>
\ No newline at end of file
<?php
include __STATIC__.'/html/header.html';
render('header.php');
?>
<link rel="stylesheet" href="/static/css/base.css">
......
<?php
if ($_COOKIE["user_id"]){
if ($_COOKIE["Authorization"]){
unset($_COOKIE["Authorization"]);
unset($_COOKIE["user_id"]);
setcookie("Authorization",null,time()-3600,"/");
setcookie("user_id",null,time()-3600,"/");
}
$url = APP_CONFIG["base_url"]."/login/";
header('Location: '.$url);
die();
......
......@@ -71,7 +71,7 @@
id="rating"
/>
<?php
$user_id = $_COOKIE["user_id"];
$user_id = getJwtData($_COOKIE["Authorization"])->user_id;
echo("
<input
......
......@@ -3,12 +3,13 @@
"db" => array(
"host" => "localhost",
"user" => "root",
"password" => "06071998",
"password" => "rahasiailahi",
"db_name" => "tayo_book_store"
),
"base_url" => "http://localhost:4000/",
"jwt_alg"=>"sha256",
"jwt_key"=>"weirdgenius2018",
"jwt_duration"=>3000
"jwt_duration"=>300,
"cookie_duration" => 3000
)
?>
......@@ -12,6 +12,12 @@ input, textarea{
background-color: #ffffff;
color: black;
}
.image-upload-label{
margin-left: 10px;
font-weight: bold;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.edit-profile-headline {
color: #FF6029;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
......@@ -46,6 +52,7 @@ input, textarea{
.edit-picture-input {
display: flex;
flex-direction: column;
margin-left: 5%;
flex-grow: 1;
margin-top: auto;
......
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
nav {
display: flex;
flex-flow: column;
......
......@@ -24,9 +24,8 @@ body{
}
.profile-img {
min-height: 70%;
min-width: 50%;
max-height: 70%;
height: 70%;
width: 50%;
border-radius : 100%;
border: 10pt solid yellow;
background: url("/static/img/profile.png");
......
public/static/img/IMG_8749.JPG

708 KiB

const doOrder = function() {
const doOrder = function(user_id) {
let url_string = window.location.href;
let url = new URL(url_string);
let book_id = url.searchParams.get("book_id");
let item_count = document.getElementById("banyak-jumlah");
const user_id = $_COOKIE["user_id"];
let orderPayload = {
"userid": user_id,
......
let nameInput = document.getElementById('edit_name');
let addressInput = document.getElementById('edit_address');
let phoneInput = document.getElementById('edit_phone');
let saveButton = document.getElementById('save_button');
let isNameValid = false;
let isAddressValid = false;
let isPhoneValid = false;
const errorStyle = "1pt solid red";
function enableValidateName(){
nameInput.addEventListener("focusout", function(){
const nameValue = nameInput.value;
if (nameValue.length>0){
nameInput.style.border = "";
isNameValid = true;
} else {
name.style.border = errorStyle;
isNameValid = false;
}
});
}
function enableValidateAddress(){
addressInput.addEventListener("focusout", function(){
const addressValue = addressInput.value;
if (addressValue.length>0){
isAddressValid = true;
addressInput.style.border = "";
} else {
isAddressValid = false;
addressInput.style.border = errorStyle;
}
});
}
function enableValidatePhone(){
phoneInput.addEventListener("focusout", function(){
const phoneValue = phoneInput.value;
if (phoneValue.length>=9 && phoneValue.length<=12){
isPhoneValid = true;
phoneInput.style.border = "";
} else {
isPhoneValid = false;
phoneInput.style.border = errorStyle;
}
});
}
function validateForm(){
enableValidateName();
enableValidateAddress();
enableValidatePhone();
}
window.onload = function(){
validateForm();
saveButton.addEventListener('click', function(e) {
if (nameInput.value === '' || address.value=== '' || phoneInput.value === '') {
e.preventDefault();
alert("Data cannot be empty!")
}
})
}
......@@ -133,37 +133,12 @@ function validateForm(){
enableValidatePhone();
}
const doRegister = function(){
console.log("test");
if (isNameValid && isEmailValid && isPasswordValid && isUsernameValid && isConfirmPasswordValid && isAddressValid && isPhoneValid){
const nameValue = name.value;
const usernameValue = username.value;
const emailValue = email.value;
const passwordValue = password.value;
const addressValue = address.value;
const phoneValue = phone.value;
let registerPayload = {
"fullname" : nameValue,
"username" : usernameValue,
"email" : emailValue,
"password" : passwordValue,
"address" : addressValue,
"phone" : phoneValue
}
doAjax('/api/user/', "POST", registerPayload, function(response){
let loginPayload = {
"username" : usernameValue,
"password" : passwordValue
}
doAjax('/auth/login/',"POST", loginPayload, function(loginResponse){
setCookie("Authorization", loginResponse.data.token, 300);
window.location.replace('http://localhost:4000/browse/');
});
})
const doRegister = function(e){
if (!(isNameValid && isEmailValid && isPasswordValid && isUsernameValid && isConfirmPasswordValid && isAddressValid && isPhoneValid)){
e.preventDefault();
alert("Please fill in the form with the correct details!");
}
}
};
window.onload = function(){
validateForm();
......
function setCookie(key, value, seconds) {
console.log("test");
var d = new Date();
d.setTime(d.getTime() + seconds*1000);
var expires = "expires="+ d.toUTCString();
document.cookie = key + "=" + value + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function doAjax(url, method, data, successCallback,failCallback) {
let req = new XMLHttpRequest();
req.open(method, url, true);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment