Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit b41f841

Browse files
-M
1 parent 684f2c7 commit b41f841

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1000
-8163
lines changed

.htaccess

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
RewriteEngine On
2+
RewriteCond %{SCRIPT_FILENAME} !-f
3+
RewriteCond %{SCRIPT_FILENAME} !-d
4+
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
5+
6+
Options -Indexes

Assets/LOGO.png

330 KB
Loading
60.1 KB
Loading

Assets/Temp/asdsad.jpg

54.1 KB
Loading
382 KB
Loading
25.3 KB
Loading

Controllers/Controller.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Controllers;
4+
5+
use Views\MainView;
6+
use Helpers\Router;
7+
8+
abstract class Controller {
9+
/** Reference to a view class */
10+
protected object $view;
11+
12+
/** Reference to a model class */
13+
protected object $model;
14+
15+
public function __construct(
16+
protected string $pageName,
17+
) {}
18+
19+
/** Execution function */
20+
public function execute(): void {
21+
$this -> view = new MainView($this -> pageName);
22+
$this -> view -> render(['css' => $this -> pageName . '.css']);
23+
}
24+
}

Controllers/HomeController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Controllers;
4+
5+
use Helpers\Router;
6+
7+
class HomeController extends Controller {
8+
use Router;
9+
}

Controllers/LoginController.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace Controllers;
4+
5+
use Exception;
6+
use Helpers\Response;
7+
use Helpers\Router;
8+
use Helpers\ImageUploader;
9+
use Models\UserFields;
10+
use Models\UserModel;
11+
use MySql;
12+
use Positions;
13+
14+
class LoginController extends Controller {
15+
use Router;
16+
17+
public function __construct(
18+
protected string $pageName = "",
19+
) {
20+
parent::__construct($pageName);
21+
22+
$this -> model = new UserModel(new MySql);
23+
}
24+
25+
public static function initSession(string $user, string $password, string $position): void {
26+
$_SESSION['isLogged'] = true;
27+
$_SESSION['user'] = $user;
28+
$_SESSION['password'] = $password;
29+
$_SESSION['position'] = $position;
30+
}
31+
32+
public static function isLogged(): bool {
33+
return isset($_SESSION['isLogged']);
34+
}
35+
36+
public static function logout(): void {
37+
session_destroy();
38+
setcookie('remember', 'true', time() - 1, '/');
39+
40+
header('Location:' . INCLUDE_PATH);
41+
die;
42+
}
43+
44+
public function login(): void {
45+
$username = $_POST['username'];
46+
$password = $_POST['password'];
47+
48+
$user = $this -> model -> findData($username, $password);
49+
50+
if ($user->rowCount() == 1) {
51+
$info = $user -> fetch();
52+
self::initSession($username, $password, $info[UserFields::$position]);
53+
54+
header('Location: ' . INCLUDE_PATH);
55+
die;
56+
}
57+
58+
Response::simpleResponse('error', 'Nome de usuário ou senha incorretos');
59+
}
60+
61+
public function register(): void {
62+
$username = $_POST['username'];
63+
$password = $_POST['password'];
64+
$description = $_POST['description'];
65+
66+
try {
67+
$profilePic = ImageUploader::receiveUserImageFromPost('profile_pic');
68+
} catch (Exception $e) {
69+
// TODO if exception caught user Helpers\Response to display error to client
70+
// or give the option to use the default profile pic
71+
echo $e->getMessage();
72+
$profilePic = '';
73+
}
74+
75+
$this -> model -> insertData([
76+
$username, $password, $description, Positions::User->value, $profilePic
77+
]);
78+
}
79+
80+
public function rememberMe(string $user, string $password, int $position): void {
81+
$user = $this -> model -> findData($user, $password);
82+
83+
if ($user->rowCount() == 1) {
84+
self::initSession($user, $password, $position);
85+
}
86+
}
87+
}

Controllers/PostController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Controllers;
4+
5+
use Helpers\Router;
6+
7+
class PostController extends Controller {
8+
use Router;
9+
}

0 commit comments

Comments
 (0)