Skip to content

Commit

Permalink
Added files
Browse files Browse the repository at this point in the history
  • Loading branch information
blackbird7112 committed Jun 23, 2021
1 parent b73591c commit cb403f2
Show file tree
Hide file tree
Showing 38 changed files with 1,366 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
19 changes: 19 additions & 0 deletions app/controller/adminbook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Controller;
session_start();

class AdminBook{

public function get(){
if($_SESSION["admin"]==null){
header("Location: /illegal");
}else{
$books = \Models\Admin::get_books();
$books["users"] = str_replace(";",",",$books["users"]);
echo \View\Loader::make()->render("templates/adminbook.twig", array(
books => $books
));
}
}
}
17 changes: 17 additions & 0 deletions app/controller/adminhome.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Controller;
session_start();

class AdminHome{
public function get(){
if($_SESSION["admin"]==null){
header("Location: /illegal");
}else{
echo \View\Loader::make()->render("templates/adminhome.twig",array(
name => $_SESSION["admin"],
));
}
}

}
30 changes: 30 additions & 0 deletions app/controller/adminlog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Controller;
session_start();
$_SESSION["user"] = null;
$_SESSION["admin"] = null ;


class AdminLog{
public function get(){
echo \View\Loader::make()->render("templates/adminsignin.twig", array(
error => false
));
}
public function post(){
$usr = $_POST["usr"];
$pass = $_POST["pass"];
$passhash = hash("sha256",$pass);

if(\Models\Admin::login($usr,$passhash)){
$_SESSION["admin"] = $usr;
header("Location: /adminhome");
}
else{
echo \View\Loader::make()->render("templates/adminsignin.twig", array(
error => true
));
}
}
}
26 changes: 26 additions & 0 deletions app/controller/adminreq.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Controller;
session_start();

class AdminReq{
public function get(){
if($_SESSION["admin"]==null){
header("Location: /illegal");
}else{
echo \View\Loader::make()->render("templates/adminreq.twig",array(
requests => \Models\Admin::get_req()
));
}
}
public function post(){
$data = json_decode(file_get_contents('php://input'), true);
$reqid = $data["reqid"];
$action = $data["action"];
if(\Models\Admin::admin_req($reqid,$action)){
echo "{\"status\":\"Request processed successful\"}";
}else{
echo "{\"status\":\"Request has failed\"}";
}
}
}
26 changes: 26 additions & 0 deletions app/controller/bookdel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Controller;
session_start();

class BookDel{
public function get(){
if($_SESSION["admin"]==null){
header("Location: /illegal");
}else{
echo \View\Loader::make()->render("templates/bookdel.twig");
}
}
public function post(){
$bid = $_POST['bid'];
if(\Models\Admin::book_del($bid)){
echo \View\Loader::make()->render("templates/bookdel.twig",array(
stat => 1
));
}else{
echo \View\Loader::make()->render("templates/bookdel.twig",array(
stat => 2
));
}
}
}
29 changes: 29 additions & 0 deletions app/controller/bookreg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Controller;
session_start();

class BookReg{
public function get(){
if($_SESSION["admin"]==null){
header("Location: /illegal");
}else{
echo \View\Loader::make()->render("templates/bookreg.twig");
}
}
public function post(){
$name = $_POST['name'];
$author = $_POST['author'];
$publisher = $_POST['publisher'];
$maxqty = $_POST['qty'];
if(\Models\Admin::book_reg($name,$author,$publisher,$maxqty)){
echo \View\Loader::make()->render("templates/bookreg.twig",array(
stat => 2
));
}else{
echo \View\Loader::make()->render("templates/bookreg.twig",array(
stat => 1
));
}
}
}
13 changes: 13 additions & 0 deletions app/controller/home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Controller;
session_start();

$_SESSION["user"] = null;
$_SESSION["admin"] = null;

class Home{
public function get(){
echo \View\Loader::make()->render("templates/welcome.twig");
}
}
9 changes: 9 additions & 0 deletions app/controller/illegalaccess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Controller;

class IllegalAccess{
public function get(){
echo \View\Loader::make()->render("templates/illaccess.twig");
}
}
16 changes: 16 additions & 0 deletions app/controller/userbook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Controller;
session_start();

class UserBook{
public function get(){
if($_SESSION["user"]==null){
header("Location: /illegal");
}else{
echo \View\Loader::make()->render("templates/userbook.twig",array(
books => \Models\User::get_books()
));
}
}
}
29 changes: 29 additions & 0 deletions app/controller/userdets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Controller;
session_start();

class UserDets{
public function get(){
if($_SESSION["admin"]==null){
header("Location: /illegal");
}else{
echo \View\Loader::make()->render("templates/userdets.twig");
}
}
public function post(){
$usr = $_POST["usr"];
$row = \Models\Admin::user_dets($usr);
if($row==false){
echo \View\Loader::make()->render("templates/userdets.twig",array(
stat => 2,
));
}else{
echo \View\Loader::make()->render("templates/userdets.twig",array(
stat => 1,
dat => $row
));
}
}

}
19 changes: 19 additions & 0 deletions app/controller/userhome.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Controller;
session_start();

class UserHome{
public function get(){
if($_SESSION["user"]==null){
header("Location: /illegal");
}else{
echo \View\Loader::make()->render("templates/userhome.twig",array(
name => $_SESSION["user"],
checkout => \Models\User::get_checkout($_SESSION["user"]),
pendreqs => \Models\User::get_pendreq($_SESSION["user"]),
));
}
}

}
21 changes: 21 additions & 0 deletions app/controller/userrequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Controller;
session_start();

class UserRequest{
public function post(){
$data = json_decode(file_get_contents('php://input'), true);
$bid = $data['bid'];
$type = $data['type'];
$usr = $_SESSION['user'];
$dt = date("Y-m-d h:i:sa");
$res = \Models\User::set_req($usr,$bid,$type,$dt);
if(res){
echo "{\"status\":\"Request successful\"}";
}
else{
echo "{\"status\":\"Request unsuccessful\"}";
}
}
}
31 changes: 31 additions & 0 deletions app/controller/usersignin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Controller;
session_start();
$_SESSION["user"] = null;
$_SESSION["admin"] = null ;


class UserLog{
public function get(){
echo \View\Loader::make()->render("templates/usersignin.twig", array(
error => false
));
}

public function post(){
$usr = $_POST["usr"];
$pass = $_POST["pass"];
$passhash = hash("sha256",$pass);

if(\Models\User::login($usr,$passhash)){
$_SESSION["user"] = $usr;
header("Location: /userhome");
}
else{
echo \View\Loader::make()->render("templates/usersignin.twig", array(
error => true
));
}
}
}
36 changes: 36 additions & 0 deletions app/controller/usersignup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Controller;

class UserSignUp{
public function get(){
echo \View\Loader::make()->render("templates/usersignup.twig", array(
error => false
));
}

public function post(){
$name = $_POST["name"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$usr = $_POST["usr"];
$pass = $_POST["pass"];
$repass = $_POST["repass"];
if($pass==$repass && preg_match("/^[a-zA-Z0-9 ]+$/",$name) && preg_match("/^[a-zA-Z0-9]+$/",$usr) && preg_match("/^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+$/",$email) && preg_match("/^[0-9]+$/",$phone)){
$pass = hash("sha256",$pass);
if(\Models\User::user_reg($usr,$name,$email,$phone,$pass)){
echo \View\Loader::make()->render("templates/usersignup.twig", array(
error => 1
));
}else{
echo \View\Loader::make()->render("templates/usersignup.twig", array(
error => 2
));
}
}else{
echo \View\Loader::make()->render("templates/usersignup.twig", array(
error => 2
));
}
}
}
Loading

0 comments on commit cb403f2

Please sign in to comment.