From 596b3dd9a28b02bc752ca86f55ff2dd94cf763fb Mon Sep 17 00:00:00 2001
From: Fawwaz Anugrah Wiradhika Dharmasatya <13520086.std.stei.itb.ac.id>
Date: Fri, 28 Oct 2022 14:54:45 +0700
Subject: [PATCH] feat:menambahkan session max 3 kali
---
Controller/HomeController.php | 4 ++++
Controller/LaguController.php | 11 ++++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/Controller/HomeController.php b/Controller/HomeController.php
index 6d70431..0da1fdd 100644
--- a/Controller/HomeController.php
+++ b/Controller/HomeController.php
@@ -14,6 +14,10 @@ class HomeController {
$songs = self::getSong($req->db);
$albums = self::getAlbum($req->db);
+ if(!isset($req->auth) && !isset($req->session->occurence) && $req->session->occurence<=0){
+ $req->session->occurence = 0;
+ }
+
return $res->view("Pages/Home", [
"auth" => $req->auth,
"songs" => $songs,
diff --git a/Controller/LaguController.php b/Controller/LaguController.php
index 9bed7df..589a096 100644
--- a/Controller/LaguController.php
+++ b/Controller/LaguController.php
@@ -16,6 +16,15 @@ use Throwable;
const SONG_sIZE = 10;
class LaguController {
static function getLagu(IRequest $req,IResponse $res){
+ //cek session
+ if(!$req->auth){
+ $req->session->occurence +=1;
+ if($req->session->occurence>3){
+ $res->redirect("/",404);
+ }
+ }
+
+
$idLagu = $req->getParam("/lagu/:id","id");
$lagu_db = new Song($req->db);
$transaction = $lagu_db->transaction();
@@ -163,7 +172,7 @@ const SONG_sIZE = 10;
return $res->json(["hasil"=>$hasil,"page"=>$page,"total_page"=>$total_page]);
}
// print_r($hasil);
- print_r($total_page);
+ // print_r($total_page);
return $res->view("Pages/SearchLagu",
[ "songs" =>$hasil,
"sortsType"=>$sortType,
--
GitLab