create-berna-stencil 2.0.4 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_tools/res/templates/template.js +5 -3
- package/bin/create.js +213 -35
- package/docs/Backend.md +15 -108
- package/docs/Javascript.md +3 -2
- package/package.json +2 -2
- package/src/backend/config.example.php +3 -2
- package/src/backend/config.php +2 -1
- package/src/frontend/404.njk +1 -1
- package/src/frontend/components/welcome.njk +220 -187
- package/src/frontend/js/pages/404.js +5 -3
- package/src/frontend/js/pages/homepage.js +5 -3
- package/src/frontend/llms.njk +1 -1
- package/src/frontend/scss/modules/_global.scss +6 -0
- package/src/frontend/scss/pages/404.scss +9 -4
- package/src/frontend/scss/pages/homepage.scss +1 -1
- package/src/backend/api/protected/auth-system.php +0 -67
- package/src/backend/api/public/auth/login.php +0 -38
- package/src/backend/api/public/auth/register.php +0 -44
- package/src/backend/database/migrations/create_users_table.sql +0 -9
- package/src/backend/database/models/User.php +0 -61
- /package/src/backend/api/protected/{subfolder/example-protected.php → example-protected.php} +0 -0
|
@@ -13,11 +13,16 @@
|
|
|
13
13
|
@import "../modules/notification";
|
|
14
14
|
|
|
15
15
|
//==========================
|
|
16
|
-
// PAGE CUSTOM CSS RULES
|
|
16
|
+
// PAGE CUSTOM CSS RULES
|
|
17
17
|
//==========================
|
|
18
18
|
|
|
19
19
|
// Add any custom rule specific to this page below
|
|
20
20
|
// These rules override the framework and module styles
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
.center {
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-direction: column;
|
|
24
|
+
justify-content: center;
|
|
25
|
+
align-items: center;
|
|
26
|
+
min-height: 60vh;
|
|
27
|
+
text-align: center;
|
|
28
|
+
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
declare(strict_types=1);
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// 2. Richiamo il tuo modulo Response e il Modello
|
|
6
|
-
require_once CORE_PATH . '/modules/Response.php';
|
|
7
|
-
require_once __DIR__ . '/../../database/models/User.php';
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
// Your protected endpoint logic here. You can access route parameters in $requestParams array
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
$user = new User();
|
|
14
|
-
$id = isset($requestParams[0]) ? (int)$requestParams[0] : null;
|
|
15
|
-
$input = json_decode(file_get_contents('php://input'), true) ?? [];
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
switch ($method) {
|
|
19
|
-
case 'GET':
|
|
20
|
-
$data = $id ? $user->getById($id) : $user->getAll();
|
|
21
|
-
if ($id && !$data) {
|
|
22
|
-
Response::error('User not found', 404);
|
|
23
|
-
}
|
|
24
|
-
// Sostituito con Response::success()
|
|
25
|
-
Response::success($data);
|
|
26
|
-
break;
|
|
27
|
-
|
|
28
|
-
case 'POST':
|
|
29
|
-
if (empty($input['nickname']) || empty($input['email'])) {
|
|
30
|
-
Response::error('Missing fields', 400);
|
|
31
|
-
}
|
|
32
|
-
if (!filter_var($input['email'], FILTER_VALIDATE_EMAIL)) {
|
|
33
|
-
Response::error('Invalid email', 400);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
$newId = $user->create($input['nickname'], $input['email']);
|
|
37
|
-
http_response_code(201);
|
|
38
|
-
Response::success(['message' => 'Created', 'id' => $newId]);
|
|
39
|
-
break;
|
|
40
|
-
|
|
41
|
-
case 'PUT':
|
|
42
|
-
case 'PATCH':
|
|
43
|
-
if (!$id) Response::error('ID required', 400);
|
|
44
|
-
if (!$user->update($id, $input)) {
|
|
45
|
-
Response::error('Not found or no changes', 404);
|
|
46
|
-
}
|
|
47
|
-
Response::success(['message' => 'Updated']);
|
|
48
|
-
break;
|
|
49
|
-
|
|
50
|
-
case 'DELETE':
|
|
51
|
-
if (!$id) Response::error('ID required', 400);
|
|
52
|
-
if (!$user->delete($id)) {
|
|
53
|
-
Response::error('Not found', 404);
|
|
54
|
-
}
|
|
55
|
-
Response::success(['message' => 'Deleted']);
|
|
56
|
-
break;
|
|
57
|
-
|
|
58
|
-
default:
|
|
59
|
-
Response::error('Method not allowed', 405);
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
} catch (PDOException $e) {
|
|
63
|
-
if ($e->getCode() === '23000') {
|
|
64
|
-
Response::error('Nickname or email already exists', 409);
|
|
65
|
-
}
|
|
66
|
-
Response::error('Database error', 500);
|
|
67
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
declare(strict_types=1);
|
|
3
|
-
|
|
4
|
-
require_once CORE_PATH . '/modules/Response.php';
|
|
5
|
-
require_once __DIR__ . '/../../../database/models/User.php';
|
|
6
|
-
|
|
7
|
-
if ($method !== 'POST') {
|
|
8
|
-
Response::error('Method not allowed', 405);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
// Your protected endpoint logic here. You can access route parameters in $requestParams array
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
$input = json_decode(file_get_contents('php://input'), true) ?? [];
|
|
16
|
-
|
|
17
|
-
$email = trim(filter_var($input['email'] ?? '', FILTER_SANITIZE_EMAIL));
|
|
18
|
-
$password = trim($input['password'] ?? '');
|
|
19
|
-
|
|
20
|
-
if (empty($email) || empty($password)) {
|
|
21
|
-
Response::error('Missing fields', 400);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
25
|
-
Response::error('Invalid email', 400);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
$user = new User();
|
|
29
|
-
$found = $user->findByEmail($email);
|
|
30
|
-
|
|
31
|
-
if (!$found || !password_verify($password, $found['password'])) {
|
|
32
|
-
Response::error('Invalid credentials', 401);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
unset($found['password']);
|
|
36
|
-
Response::success([
|
|
37
|
-
'user' => $found,
|
|
38
|
-
]);
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
declare(strict_types=1);
|
|
3
|
-
|
|
4
|
-
require_once CORE_PATH . '/modules/Response.php';
|
|
5
|
-
require_once __DIR__ . '/../../../database/models/User.php';
|
|
6
|
-
|
|
7
|
-
if ($method !== 'POST') {
|
|
8
|
-
Response::error('Method not allowed', 405);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
// Your protected endpoint logic here. You can access route parameters in $requestParams array
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
$input = json_decode(file_get_contents('php://input'), true) ?? [];
|
|
17
|
-
|
|
18
|
-
$nickname = htmlspecialchars(strip_tags(trim($input['nickname'] ?? '')));
|
|
19
|
-
$email = trim(filter_var($input['email'] ?? '', FILTER_SANITIZE_EMAIL));
|
|
20
|
-
$password = trim($input['password'] ?? '');
|
|
21
|
-
|
|
22
|
-
if (empty($nickname) || empty($email) || empty($password)) {
|
|
23
|
-
Response::error('Missing fields', 400);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
27
|
-
Response::error('Invalid email', 400);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (strlen($password) < 8) {
|
|
31
|
-
Response::error('Password must be at least 8 characters', 400);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
$user = new User();
|
|
36
|
-
$newId = $user->create($nickname, $email, $password);
|
|
37
|
-
http_response_code(201);
|
|
38
|
-
Response::success(['id' => $newId]);
|
|
39
|
-
} catch (PDOException $e) {
|
|
40
|
-
if ($e->getCode() === '23000') {
|
|
41
|
-
Response::error('Nickname or email already exists', 409);
|
|
42
|
-
}
|
|
43
|
-
Response::error('Database error', 500);
|
|
44
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
USE example_db;
|
|
2
|
-
|
|
3
|
-
CREATE TABLE IF NOT EXISTS users (
|
|
4
|
-
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
5
|
-
nickname VARCHAR(50) NOT NULL UNIQUE,
|
|
6
|
-
email VARCHAR(255) NOT NULL UNIQUE,
|
|
7
|
-
password VARCHAR(255) NOT NULL,
|
|
8
|
-
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
9
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
declare(strict_types=1);
|
|
3
|
-
|
|
4
|
-
require_once __DIR__ . '/../Database.php';
|
|
5
|
-
|
|
6
|
-
class User {
|
|
7
|
-
private PDO $db;
|
|
8
|
-
|
|
9
|
-
public function __construct() {
|
|
10
|
-
$this->db = Database::getInstance();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public function getAll(): array {
|
|
14
|
-
return $this->db->query("SELECT id, nickname, email, created_at FROM users")->fetchAll();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public function getById(int $id): ?array {
|
|
18
|
-
$stmt = $this->db->prepare("SELECT id, nickname, email, created_at FROM users WHERE id = :id");
|
|
19
|
-
$stmt->execute(['id' => $id]);
|
|
20
|
-
return $stmt->fetch() ?: null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public function findByEmail(string $email): ?array {
|
|
24
|
-
$stmt = $this->db->prepare("SELECT id, nickname, email, password, created_at FROM users WHERE email = :email");
|
|
25
|
-
$stmt->execute(['email' => filter_var(trim($email), FILTER_SANITIZE_EMAIL)]);
|
|
26
|
-
return $stmt->fetch() ?: null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public function create(string $nickname, string $email, string $password = ''): int {
|
|
30
|
-
$stmt = $this->db->prepare("INSERT INTO users (nickname, email, password) VALUES (:nickname, :email, :password)");
|
|
31
|
-
$stmt->execute([
|
|
32
|
-
'nickname' => htmlspecialchars(strip_tags(trim($nickname))),
|
|
33
|
-
'email' => filter_var(trim($email), FILTER_SANITIZE_EMAIL),
|
|
34
|
-
'password' => $password !== '' ? password_hash($password, PASSWORD_BCRYPT) : '',
|
|
35
|
-
]);
|
|
36
|
-
return (int)$this->db->lastInsertId();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public function update(int $id, array $data): bool {
|
|
40
|
-
$fields = [];
|
|
41
|
-
$params = ['id' => $id];
|
|
42
|
-
|
|
43
|
-
if (isset($data['nickname'])) {
|
|
44
|
-
$fields[] = 'nickname = :nickname';
|
|
45
|
-
$params['nickname'] = htmlspecialchars(strip_tags($data['nickname']));
|
|
46
|
-
}
|
|
47
|
-
if (isset($data['email'])) {
|
|
48
|
-
$fields[] = 'email = :email';
|
|
49
|
-
$params['email'] = filter_var($data['email'], FILTER_SANITIZE_EMAIL);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (empty($fields)) return false;
|
|
53
|
-
|
|
54
|
-
$sql = "UPDATE users SET " . implode(', ', $fields) . " WHERE id = :id";
|
|
55
|
-
return $this->db->prepare($sql)->execute($params);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public function delete(int $id): bool {
|
|
59
|
-
return $this->db->prepare("DELETE FROM users WHERE id = :id")->execute(['id' => $id]);
|
|
60
|
-
}
|
|
61
|
-
}
|
/package/src/backend/api/protected/{subfolder/example-protected.php → example-protected.php}
RENAMED
|
File without changes
|