Source

Target

Commits (5)
Showing with 384 additions and 248 deletions
+384 -248
......@@ -18,7 +18,7 @@
],
"require": {
"kaa/kaa": "0.0.2"
"kaa/kaa": "0.0.4"
},
"require-dev": {
"symplify/easy-coding-standard": "^12.0",
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "0c7a4662da421eb5b2fcca1adee226b0",
"content-hash": "26e27756d0ca58efbf1da65e9865b77c",
"packages": [
{
"name": "haydenpierce/class-finder",
......@@ -50,11 +50,11 @@
},
{
"name": "kaa/kaa",
"version": "0.0.2",
"version": "0.0.4",
"source": {
"type": "git",
"url": "https://git.miem.hse.ru/kaa-framework/kaa",
"reference": "03b8dacc043a0eb962348fd8280f6c89036e0d0e"
"reference": "f66fa572e7a1f42ad39f61d1ee0384e36047e458"
},
"require": {
"haydenpierce/class-finder": "0.5.3",
......@@ -92,7 +92,7 @@
"MIT"
],
"description": "Kaa - KPHP compatible Web Framework",
"time": "2024-01-23T22:08:25+00:00"
"time": "2024-02-01T09:54:22+00:00"
},
{
"name": "nette/php-generator",
......@@ -312,16 +312,16 @@
},
{
"name": "symfony/config",
"version": "v6.4.0",
"version": "v6.4.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/config.git",
"reference": "5d33e0fb707d603330e0edfd4691803a1253572e"
"reference": "206482ff3ed450495b1d5b7bad1bc3a852def96f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/config/zipball/5d33e0fb707d603330e0edfd4691803a1253572e",
"reference": "5d33e0fb707d603330e0edfd4691803a1253572e",
"url": "https://api.github.com/repos/symfony/config/zipball/206482ff3ed450495b1d5b7bad1bc3a852def96f",
"reference": "206482ff3ed450495b1d5b7bad1bc3a852def96f",
"shasum": ""
},
"require": {
......@@ -367,7 +367,7 @@
"description": "Helps you find, load, combine, autofill and validate configuration values of any kind",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/config/tree/v6.4.0"
"source": "https://github.com/symfony/config/tree/v6.4.3"
},
"funding": [
{
......@@ -383,7 +383,7 @@
"type": "tidelift"
}
],
"time": "2023-11-09T08:28:32+00:00"
"time": "2024-01-29T13:26:27+00:00"
},
{
"name": "symfony/deprecation-contracts",
......@@ -454,16 +454,16 @@
},
{
"name": "symfony/filesystem",
"version": "v7.0.0",
"version": "v7.0.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/filesystem.git",
"reference": "7da8ea2362a283771478c5f7729cfcb43a76b8b7"
"reference": "2890e3a825bc0c0558526c04499c13f83e1b6b12"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/7da8ea2362a283771478c5f7729cfcb43a76b8b7",
"reference": "7da8ea2362a283771478c5f7729cfcb43a76b8b7",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/2890e3a825bc0c0558526c04499c13f83e1b6b12",
"reference": "2890e3a825bc0c0558526c04499c13f83e1b6b12",
"shasum": ""
},
"require": {
......@@ -497,7 +497,7 @@
"description": "Provides basic utilities for the filesystem",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/filesystem/tree/v7.0.0"
"source": "https://github.com/symfony/filesystem/tree/v7.0.3"
},
"funding": [
{
......@@ -513,7 +513,7 @@
"type": "tidelift"
}
],
"time": "2023-07-27T06:33:22+00:00"
"time": "2024-01-23T15:02:46+00:00"
},
{
"name": "symfony/finder",
......@@ -829,16 +829,16 @@
},
{
"name": "symfony/yaml",
"version": "v7.0.0",
"version": "v7.0.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "0055b230c408428b9b5cde7c55659555be5c0278"
"reference": "2d4fca631c00700597e9442a0b2451ce234513d3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/0055b230c408428b9b5cde7c55659555be5c0278",
"reference": "0055b230c408428b9b5cde7c55659555be5c0278",
"url": "https://api.github.com/repos/symfony/yaml/zipball/2d4fca631c00700597e9442a0b2451ce234513d3",
"reference": "2d4fca631c00700597e9442a0b2451ce234513d3",
"shasum": ""
},
"require": {
......@@ -880,7 +880,7 @@
"description": "Loads and dumps YAML files",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/yaml/tree/v7.0.0"
"source": "https://github.com/symfony/yaml/tree/v7.0.3"
},
"funding": [
{
......@@ -896,7 +896,7 @@
"type": "tidelift"
}
],
"time": "2023-11-07T10:26:03+00:00"
"time": "2024-01-23T15:02:46+00:00"
},
{
"name": "twig/twig",
......@@ -1586,16 +1586,16 @@
},
{
"name": "symfony/console",
"version": "v7.0.2",
"version": "v7.0.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "f8587c4cdc5acad67af71c37db34ef03af91e59c"
"reference": "c5010d50f1ee4b25cfa0201d9915cf1b14071456"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/f8587c4cdc5acad67af71c37db34ef03af91e59c",
"reference": "f8587c4cdc5acad67af71c37db34ef03af91e59c",
"url": "https://api.github.com/repos/symfony/console/zipball/c5010d50f1ee4b25cfa0201d9915cf1b14071456",
"reference": "c5010d50f1ee4b25cfa0201d9915cf1b14071456",
"shasum": ""
},
"require": {
......@@ -1659,7 +1659,7 @@
"terminal"
],
"support": {
"source": "https://github.com/symfony/console/tree/v7.0.2"
"source": "https://github.com/symfony/console/tree/v7.0.3"
},
"funding": [
{
......@@ -1675,20 +1675,20 @@
"type": "tidelift"
}
],
"time": "2023-12-10T16:54:46+00:00"
"time": "2024-01-23T15:02:46+00:00"
},
{
"name": "symfony/event-dispatcher",
"version": "v7.0.2",
"version": "v7.0.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
"reference": "098b62ae81fdd6cbf941f355059f617db28f4f9a"
"reference": "834c28d533dd0636f910909d01b9ff45cc094b5e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/098b62ae81fdd6cbf941f355059f617db28f4f9a",
"reference": "098b62ae81fdd6cbf941f355059f617db28f4f9a",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/834c28d533dd0636f910909d01b9ff45cc094b5e",
"reference": "834c28d533dd0636f910909d01b9ff45cc094b5e",
"shasum": ""
},
"require": {
......@@ -1739,7 +1739,7 @@
"description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/event-dispatcher/tree/v7.0.2"
"source": "https://github.com/symfony/event-dispatcher/tree/v7.0.3"
},
"funding": [
{
......@@ -1755,7 +1755,7 @@
"type": "tidelift"
}
],
"time": "2023-12-27T22:24:19+00:00"
"time": "2024-01-23T15:02:46+00:00"
},
{
"name": "symfony/event-dispatcher-contracts",
......@@ -2146,16 +2146,16 @@
},
{
"name": "symfony/process",
"version": "v7.0.2",
"version": "v7.0.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
"reference": "acd3eb5cb02382c1cb0287ba29b2908cc6ffa83a"
"reference": "937a195147e0c27b2759ade834169ed006d0bc74"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/process/zipball/acd3eb5cb02382c1cb0287ba29b2908cc6ffa83a",
"reference": "acd3eb5cb02382c1cb0287ba29b2908cc6ffa83a",
"url": "https://api.github.com/repos/symfony/process/zipball/937a195147e0c27b2759ade834169ed006d0bc74",
"reference": "937a195147e0c27b2759ade834169ed006d0bc74",
"shasum": ""
},
"require": {
......@@ -2187,7 +2187,7 @@
"description": "Executes commands in sub-processes",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/process/tree/v7.0.2"
"source": "https://github.com/symfony/process/tree/v7.0.3"
},
"funding": [
{
......@@ -2203,7 +2203,7 @@
"type": "tidelift"
}
],
"time": "2023-12-24T09:15:37+00:00"
"time": "2024-01-23T15:02:46+00:00"
},
{
"name": "symfony/service-contracts",
......@@ -2289,16 +2289,16 @@
},
{
"name": "symfony/stopwatch",
"version": "v7.0.0",
"version": "v7.0.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/stopwatch.git",
"reference": "7bbfa3dd564a0ce12eb4acaaa46823c740f9cb7a"
"reference": "983900d6fddf2b0cbaacacbbad07610854bd8112"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/stopwatch/zipball/7bbfa3dd564a0ce12eb4acaaa46823c740f9cb7a",
"reference": "7bbfa3dd564a0ce12eb4acaaa46823c740f9cb7a",
"url": "https://api.github.com/repos/symfony/stopwatch/zipball/983900d6fddf2b0cbaacacbbad07610854bd8112",
"reference": "983900d6fddf2b0cbaacacbbad07610854bd8112",
"shasum": ""
},
"require": {
......@@ -2331,7 +2331,7 @@
"description": "Provides a way to profile code",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/stopwatch/tree/v7.0.0"
"source": "https://github.com/symfony/stopwatch/tree/v7.0.3"
},
"funding": [
{
......@@ -2347,20 +2347,20 @@
"type": "tidelift"
}
],
"time": "2023-07-05T13:06:06+00:00"
"time": "2024-01-23T15:02:46+00:00"
},
{
"name": "symfony/string",
"version": "v7.0.2",
"version": "v7.0.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/string.git",
"reference": "cc78f14f91f5e53b42044d0620961c48028ff9f5"
"reference": "524aac4a280b90a4420d8d6a040718d0586505ac"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/string/zipball/cc78f14f91f5e53b42044d0620961c48028ff9f5",
"reference": "cc78f14f91f5e53b42044d0620961c48028ff9f5",
"url": "https://api.github.com/repos/symfony/string/zipball/524aac4a280b90a4420d8d6a040718d0586505ac",
"reference": "524aac4a280b90a4420d8d6a040718d0586505ac",
"shasum": ""
},
"require": {
......@@ -2417,7 +2417,7 @@
"utf8"
],
"support": {
"source": "https://github.com/symfony/string/tree/v7.0.2"
"source": "https://github.com/symfony/string/tree/v7.0.3"
},
"funding": [
{
......@@ -2433,7 +2433,7 @@
"type": "tidelift"
}
],
"time": "2023-12-10T16:54:46+00:00"
"time": "2024-01-29T15:41:16+00:00"
},
{
"name": "symplify/easy-coding-standard",
......
......@@ -5,6 +5,10 @@ security:
user_provider: '@App\Service\UserProvider'
firewalls:
register:
path: '^/register'
authenticators:
- { service: App\Authenticator\RegisterAuthenticator }
login:
path: '^/login'
authenticators:
......
CREATE TABLE IF NOT EXISTS tag(
id INTEGER PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(60) NOT NULL UNIQUE
);
id INTEGER PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(60) NOT NULL UNIQUE
);
CREATE TABLE IF NOT EXISTS user(
id INTEGER PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(120) NOT NULL UNIQUE ,
id INTEGER PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(120) NOT NULL UNIQUE ,
email VARCHAR(120) NOT NULL UNIQUE ,
password VARCHAR(60) NOT NULL ,
role VARCHAR(10),
password VARCHAR(120) NOT NULL ,
roles VARCHAR(10),
created DATETIME,
changed DATETIME,
CONSTRAINT role_enum CHECK ( role IN ('USER', 'MODERATOR', 'ADMIN') )
);
CONSTRAINT role_enum CHECK ( roles IN ('USER', 'MODERATOR', 'ADMIN') )
);
CREATE TABLE IF NOT EXISTS topic(
id INTEGER PRIMARY KEY AUTO_INCREMENT,
author_id INTEGER,
title VARCHAR(365) NOT NULL ,
id INTEGER PRIMARY KEY AUTO_INCREMENT,
author_id INTEGER,
title VARCHAR(365) NOT NULL ,
type VARCHAR(8) NOT NULL ,
created DATETIME,
CONSTRAINT FOREIGN KEY (author_id)
REFERENCES user(id)
ON DELETE no action
);
REFERENCES user(id)
ON DELETE no action,
CONSTRAINT type_check CHECK ( type IN ('PUBLIC', 'PRIVATE') )
);
CREATE TABLE IF NOT EXISTS article(
id INTEGER PRIMARY KEY AUTO_INCREMENT,
author_id INTEGER ,
topic_id INTEGER ,
title VARCHAR(480) NOT NULL ,
id INTEGER PRIMARY KEY AUTO_INCREMENT,
author_id INTEGER ,
topic_id INTEGER ,
title VARCHAR(480) NOT NULL ,
body VARCHAR(10000) ,
created DATETIME ,
changed DATETIME ,
CONSTRAINT FOREIGN KEY (author_id)
REFERENCES user(id)
ON DELETE no action ,
REFERENCES user(id)
ON DELETE no action ,
CONSTRAINT FOREIGN KEY (topic_id)
REFERENCES topic(id)
ON DELETE set null
);
REFERENCES topic(id)
ON DELETE set null
);
CREATE TABLE IF NOT EXISTS comment(
id INTEGER PRIMARY KEY AUTO_INCREMENT,
author_id INTEGER,
article_id INTEGER,
body VARCHAR(1000),
id INTEGER PRIMARY KEY AUTO_INCREMENT,
author_id INTEGER,
article_id INTEGER,
body VARCHAR(1000),
created DATETIME,
changed DATETIME,
CONSTRAINT FOREIGN KEY (author_id)
REFERENCES user(id)
ON DELETE no action ,
REFERENCES user(id)
ON DELETE no action ,
CONSTRAINT FOREIGN KEY (article_id)
REFERENCES article(id)
ON DELETE CASCADE
);
REFERENCES article(id)
ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS article_tag(
id INTEGER PRIMARY KEY AUTO_INCREMENT,
article_id INTEGER,
tag_id INTEGER,
CONSTRAINT FOREIGN KEY (article_id)
REFERENCES article(id)
ON DELETE CASCADE ,
id INTEGER PRIMARY KEY AUTO_INCREMENT,
article_id INTEGER,
tag_id INTEGER,
CONSTRAINT FOREIGN KEY (article_id)
REFERENCES article(id)
ON DELETE CASCADE ,
CONSTRAINT FOREIGN KEY (tag_id)
REFERENCES tag(id)
ON DELETE CASCADE
);
REFERENCES tag(id)
ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS admission(
id INTEGER PRIMARY KEY AUTO_INCREMENT,
topic_id INTEGER,
user_id INTEGER,
CONSTRAINT FOREIGN KEY (topic_id)
REFERENCES topic(id)
ON DELETE CASCADE ,
CONSTRAINT FOREIGN KEY (user_id)
REFERENCES user(id)
ON DELETE CASCADE
);
INSERT INTO user(username, email, password, role, created, changed)
VALUES ('test', 'test@gmail.com', '12345', 'USER', '2022-12-27 08:26:49.219717', '2022-12-27 08:26:49.219717');
INSERT INTO user(username, email, password, roles, created, changed)
VALUES ('test', 'test@gmail.com', '5994471ABB01112AFCC18159F6CC74B4F511B99806DA59B3CAF5A9C173CACFC5', 'USER', '2022-12-27 08:26:49.219717', '2022-12-27 08:26:49.219717');
INSERT INTO user(username, email, password, role, created, changed)
VALUES ('Admin', 'admin@gmail.com', '12345', 'ADMIN', '2022-12-27 08:26:49.219717', '2022-12-27 08:26:49.219717');
INSERT INTO user(username, email, password, roles, created, changed)
VALUES ('Admin', 'admin@gmail.com', '5994471ABB01112AFCC18159F6CC74B4F511B99806DA59B3CAF5A9C173CACFC5', 'ADMIN', '2022-12-27 08:26:49.219717', '2022-12-27 08:26:49.219717');
......@@ -3,19 +3,17 @@ POST http://localhost:8800/tag
Content-Type: application/json
{
"id": 0,
"title": "KPHP"
"title": "KPHP2"
}
### GET TAG
GET http://localhost:8800/tag/1
### PUT TAG
PUT http://localhost:8800/tag/0
POST http://localhost:8800/tag/put/1
Content-Type: application/json
{
"id": 0,
"title": "Test"
}
......@@ -28,12 +26,20 @@ Content-Type: application/json
"password": "12345"
}
### LOGIN
POST http://localhost:8800/login
Content-Type: application/json
{
"username": "test",
"password": "12345"
}
### REGISTER
POST http://localhost:8800/register
Content-Type: application/json
{
"id": 5,
"username": "kphp",
"email": "kphp@mail.com",
"password": "12355"
......@@ -68,36 +74,40 @@ Content-Type: application/json
]
}
### LOGIN MODER
POST http://localhost:8800/login
Content-Type: application/json
{
"username": "Moder",
"password": "qwerty"
}
### GET USER
GET http://localhost:8800/admin/user/3
### PUT USER
PUT http://localhost:8800/admin/user/3
POST http://localhost:8800/put/admin/user/3
Content-Type: application/json
{
"id": 3,
"username": "Moderator",
"email": "moder@mail.com",
"password": "qwerty",
"created": "2024-01-22 21:30:00",
"changed": "2024-01-22 21:30:00",
"roles": [
"MODERATOR"
]
}
### PUT CURRENT USER
PUT http://localhost:8800/user/me
PUT http://localhost:8800/put/user/me
Content-Type: application/json
{
"id": 1,
"username": "test",
"email": "test@mail.com",
"username": "Admin90",
"email": "testhhaodmin@mail.com",
"password": "qwerty",
"created": "2024-01-22 21:30:00",
"changed": "2024-01-22 21:30:00",
"roles": [
"USER"
]
......@@ -108,24 +118,29 @@ POST http://localhost:8800/moderator/topic
Content-Type: application/json
{
"id": 0,
"authorId": 2,
"title": "KPHP - not cool!",
"type": "PRIVATE",
"acceptedUsers": [
1
],
"created": "2024-01-22 21:30:00"
}
### GET TOPIC
GET http://localhost:8800/topic/1
GET http://localhost:8800/topic/2
### PUT TUPIC
PUT http://localhost:8800/moderator/topic/2
POST http://localhost:8800/put/moderator/topic/2
Content-Type: application/json
{
"id": 1,
"authorId": 2,
"title": "KPHP is very cool!",
"created": "2024-01-22 21:30:00"
"type": "PRIVATE",
"acceptedUsers": [
1
]
}
......@@ -134,38 +149,30 @@ POST http://localhost:8800/article
Content-Type: application/json
{
"id": 2,
"authorId": 2,
"topicId": 1,
"topicId": 2,
"title": "KPHP",
"body": "dfdjgkjdfgdfhgopudfhgokvbjncv[qeio[eruoergoierj",
"tags": [
1
],
"created": "2024-01-22 21:30:00",
"changed": "2024-01-22 21:30:00"
]
}
### GET ARTICLE
GET http://localhost:8800/article/1
### CHANGE ARTICLE
PUT http://localhost:8800/article/3
POST http://localhost:8800/article/put/1
Content-Type: application/json
{
"id": 1,
"authorId": 2,
"topicId": 2,
"title": "KPHP",
"body": "I very like this framework and KPHP!!!",
"tags": [
1
],
"created": "2024-01-22 21:30:00",
"changed": "2024-01-22 21:30:00"
]
}
### ADD COMMENT
......@@ -173,28 +180,22 @@ POST http://localhost:8800/comment
Content-Type: application/json
{
"id": 0,
"authorId": 2,
"articleId": 1,
"body": "Boring...",
"created": "2024-01-22 21:30:00",
"changed": "2024-01-22 21:30:00"
"body": "Boring..."
}
### GET COMMENT
GET http://localhost:8800/comment/1
### UPDATE COMMENT
PUT http://localhost:8800/comment/1
POST http://localhost:8800/comment/put/1
Content-Type: application/json
{
"id": 1,
"authorId": 2,
"articleId": 1,
"body": "Very interesting!",
"created": "2024-01-22 21:30:00",
"changed": "2024-01-22 21:30:00"
"body": "Very interesting!"
}
......
......@@ -3,6 +3,8 @@
declare(strict_types=1);
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
use PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer;
use PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer;
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
......@@ -15,6 +17,10 @@ return ECSConfig::configure()
// add a single rule
->withRules([
ArraySyntaxFixer::class,
NoUnusedImportsFixer::class
NoUnusedImportsFixer::class,
NoTrailingCommaInSinglelineFixer::class
])
->withPreparedSets(psr12: true);
->withPreparedSets(psr12: true)
->withSkip([
TrailingCommaInMultilineFixer::class
]);
......@@ -15,7 +15,7 @@ use Kaa\Component\Security\AuthenticatorInterface;
use Kaa\Component\Security\Exception\SessionException;
use Kaa\Component\Security\Session\SessionService;
use Random\RandomException;
use Symfony\Component\Filesystem\Exception\RuntimeException;
use RuntimeException;
use Throwable;
class LoginAuthenticator implements AuthenticatorInterface
......@@ -43,9 +43,9 @@ class LoginAuthenticator implements AuthenticatorInterface
public function supports(Request $request): bool
{
$content = json_decode($request->getContent(), true);
return $request->getMethod() === 'POST' &&
array_key_exists('username', $content) &&
array_key_exists('password', $content);
return $request->getMethod() === 'POST'
&& array_key_exists('username', $content)
&& array_key_exists('password', $content);
}
/**
......@@ -55,7 +55,10 @@ class LoginAuthenticator implements AuthenticatorInterface
{
$data = json_decode($request->getContent(), true);
$user = $this->entityManager->findOneBy(User::class, ['username' => $data['username']]);
if (($data['username'] === $user->getUsername()) && ($data['password'] === $user->getPassword())) {
if (
($data['username'] === $user->getUsername())
&& (strtoupper(hash('sha256', $data['password'])) === $user->getPassword())
) {
return fn () => $this->userProvider->getUser($user->getIdentifier());
}
throw new RuntimeException('Incorrect username or password');
......@@ -77,6 +80,6 @@ class LoginAuthenticator implements AuthenticatorInterface
public function onAuthenticationFailure(Request $request, Throwable $throwable): ?Response
{
return new JsonResponse('Incorrect login or password', 401);
return new JsonResponse('Incorrect username or password', 401);
}
}
<?php
namespace App\Authenticator;
use App\Model\UserModel;
use App\Service\UserProvider;
use App\Service\UserService;
use Exception;
use Kaa\Component\Database\EntityManager\EntityManagerInterface;
use Kaa\Component\HttpMessage\Exception\BadRequestException;
use Kaa\Component\HttpMessage\Exception\NoContentException;
use Kaa\Component\HttpMessage\Exception\SuspiciousOperationException;
use Kaa\Component\HttpMessage\Request;
use Kaa\Component\HttpMessage\Response\JsonResponse;
use Kaa\Component\HttpMessage\Response\Response;
use Kaa\Component\Security\AuthenticatorInterface;
use Kaa\Component\Security\Exception\SessionException;
use Kaa\Component\Security\Session\SessionService;
use Random\RandomException;
use Throwable;
class RegisterAuthenticator implements AuthenticatorInterface
{
private SessionService $sessionService;
private EntityManagerInterface $entityManager;
private UserProvider $userProvider;
private UserService $userService;
public function __construct(
SessionService $sessionService,
EntityManagerInterface $entityManager,
UserProvider $userProvider,
UserService $userService
) {
$this->sessionService = $sessionService;
$this->entityManager = $entityManager;
$this->userProvider = $userProvider;
$this->userService = $userService;
}
/**
* @throws BadRequestException
* @throws SuspiciousOperationException
* @throws NoContentException
*/
public function supports(Request $request): bool
{
$content = json_decode($request->getContent(), true);
return $request->getMethod() === 'POST'
&& array_key_exists('username', $content)
&& array_key_exists('password', $content)
&& array_key_exists('email', $content);
}
/**
* @throws NoContentException
* @throws Exception
*/
public function authenticate(Request $request): callable
{
$data = json_decode($request->getContent(), true);
$id = $this->userService->createUser(new UserModel(
(string)$data['username'],
(string)$data['email'],
(string)$data['password'],
['USER']
));
return fn () => $this->userProvider->getUser((string)$id);
}
/**
* @throws SessionException
* @throws RandomException
*/
public function onAuthenticationSuccess(Request $request, callable $getUser): ?Response
{
$cookie = $this->sessionService->writeSession($getUser());
$response = new Response('Success', 200);
$response->addCookie($cookie);
return $response;
}
public function onAuthenticationFailure(Request $request, Throwable $throwable): ?Response
{
return new JsonResponse('Something went wrong...', 400);
}
}
......@@ -15,7 +15,6 @@ use Kaa\Component\RequestMapperDecorator\MapJsonPayload;
use Kaa\Component\RequestMapperDecorator\MapRouteParameter;
use Kaa\Component\Router\Attribute\Get;
use Kaa\Component\Router\Attribute\Post;
use Kaa\Component\Router\Attribute\Put;
use Kaa\Component\Router\Attribute\Route;
use Kaa\Component\SecurityDecorator\CurrentUser;
......@@ -46,7 +45,7 @@ class ArticleController
return $articleService->getArticle($id);
}
#[Put('/{id}')]
#[POST('/put/{id}')]
public function changeArticle(
#[MapRouteParameter]
int $id,
......@@ -58,7 +57,7 @@ class ArticleController
User $user
): Response {
$articleService->updateArticle($id, $articleModel, $user);
return new JsonResponse('Successful changed', status: 200);
return new JsonResponse('Successful changed', 200);
}
#[Get('/my')]
......@@ -69,7 +68,7 @@ class ArticleController
#[Inject]
ArticleService $articleService
): MultipleArticlesModel {
return $articleService->getUserArticles((string) $user->getId());
return $articleService->getUserArticles($user->getId());
}
#[Get('/user/{id}')]
......@@ -80,6 +79,6 @@ class ArticleController
#[Inject]
ArticleService $articleService
): MultipleArticlesModel {
return $articleService->getUserArticles((string) $id);
return $articleService->getUserArticles($id);
}
}
......@@ -4,6 +4,7 @@ namespace App\Controller;
use App\Entity\User;
use App\Model\CommentModel;
use App\Model\CommentResponseModel;
use App\Model\MultipleCommentModel;
use App\Service\CommentService;
use Exception;
......@@ -15,7 +16,6 @@ use Kaa\Component\RequestMapperDecorator\MapJsonPayload;
use Kaa\Component\RequestMapperDecorator\MapRouteParameter;
use Kaa\Component\Router\Attribute\Get;
use Kaa\Component\Router\Attribute\Post;
use Kaa\Component\Router\Attribute\Put;
use Kaa\Component\Router\Attribute\Route;
use Kaa\Component\SecurityDecorator\CurrentUser;
......@@ -45,11 +45,11 @@ class CommentController
int $id,
#[Inject]
CommentService $commentService
): CommentModel {
): CommentResponseModel {
return $commentService->getComment($id);
}
#[Put('/{id}')]
#[Post('/put/{id}')]
public function changeComment(
#[MapRouteParameter]
int $id,
......@@ -61,7 +61,7 @@ class CommentController
User $user
): Response {
$commentService->updateComment($id, $commentModel, $user);
return new JsonResponse('Successful changed', status: 200);
return new JsonResponse();
}
#[Get('/my')]
......@@ -72,7 +72,7 @@ class CommentController
#[Inject]
CommentService $commentService
): MultipleCommentModel {
return $commentService->getUserComments((string) $user->getId());
return $commentService->getUserComments($user->getId());
}
#[Get('/user/{id}')]
......@@ -83,6 +83,6 @@ class CommentController
#[Inject]
CommentService $commentService
): MultipleCommentModel {
return $commentService->getUserComments((string) $id);
return $commentService->getUserComments($id);
}
}
......@@ -11,7 +11,7 @@ class ExampleController
#[Get('/test')]
public function test(): JsonResponse
{
return new JsonResponse('{"hame": "kolaya"}', 200, []);
return new JsonResponse('{"hame": "kolaya"}', 200);
} # warning for incorrect json for parsing?
#[Get('/test/{id}')]
......@@ -19,6 +19,6 @@ class ExampleController
#[MapRouteParameter]
int $id
): JsonResponse {
return new JsonResponse("{'id': {$id}}", 200, []);
return new JsonResponse("{'id': {$id}}", 200);
}
}
<?php
namespace App\Controller;
use App\Model\RegisterModel;
use App\Service\UserProvider;
use Kaa\Component\DependencyInjectionDecorator\Inject;
use Kaa\Component\RequestMapperDecorator\AsJsonResponse;
use Kaa\Component\RequestMapperDecorator\MapJsonPayload;
use Kaa\Component\Router\Attribute\Post;
class RegisterController
{
#[Post('/register')]
#[AsJsonResponse]
public function register(
#[MapJsonPayload]
RegisterModel $registerModel,
#[Inject]
UserProvider $userProvider
): int {
return $userProvider->registerUser($registerModel);
}
}
......@@ -3,6 +3,7 @@
namespace App\Controller;
use App\Model\TagModel;
use App\Model\TagResponseModel;
use App\Service\TagService;
use Kaa\Component\DependencyInjectionDecorator\Inject;
use Kaa\Component\HttpMessage\Response\JsonResponse;
......@@ -11,7 +12,6 @@ use Kaa\Component\RequestMapperDecorator\MapJsonPayload;
use Kaa\Component\RequestMapperDecorator\MapRouteParameter;
use Kaa\Component\Router\Attribute\Get;
use Kaa\Component\Router\Attribute\Post;
use Kaa\Component\Router\Attribute\Put;
use Kaa\Component\Router\Attribute\Route;
#[Route('/tag')]
......@@ -35,11 +35,11 @@ class TagController
TagService $tagService,
#[MapRouteParameter]
int $id
): TagModel {
): TagResponseModel {
return $tagService->getTag($id);
}
#[Put('/{id}')]
#[Post('/put/{id}')]
public function changeTag(
#[Inject]
TagService $tagService,
......@@ -49,6 +49,6 @@ class TagController
TagModel $tagModel
): JsonResponse {
$tagService->updateTag($id, $tagModel);
return new JsonResponse('Successful changed', status: 200);
return new JsonResponse();
}
}
......@@ -5,6 +5,7 @@ namespace App\Controller;
use App\Entity\User;
use App\Model\MultipleTopicsModel;
use App\Model\TopicModel;
use App\Model\TopicResponseModel;
use App\Service\TopicService;
use Kaa\Component\DependencyInjectionDecorator\Inject;
use Kaa\Component\HttpMessage\Response\JsonResponse;
......@@ -13,7 +14,6 @@ use Kaa\Component\RequestMapperDecorator\MapJsonPayload;
use Kaa\Component\RequestMapperDecorator\MapRouteParameter;
use Kaa\Component\Router\Attribute\Get;
use Kaa\Component\Router\Attribute\Post;
use Kaa\Component\Router\Attribute\Put;
use Kaa\Component\SecurityDecorator\CurrentUser;
class TopicController
......@@ -36,11 +36,11 @@ class TopicController
TopicService $topicService,
#[MapRouteParameter]
int $id
): TopicModel {
): TopicResponseModel {
return $topicService->getTopic($id);
}
#[Put('moderator/topic/{id}')]
#[Post('/put/moderator/topic/{id}')]
public function changeTopic(
#[MapRouteParameter]
int $id,
......@@ -50,7 +50,7 @@ class TopicController
TopicService $topicService
): JsonResponse {
$topicService->updateTopic($id, $topicModel);
return new JsonResponse('Successful changed', status: 200);
return new JsonResponse('Successful changed', 200);
}
#[Get('/topic/my')]
......@@ -61,7 +61,7 @@ class TopicController
#[Inject]
TopicService $topicService
): MultipleTopicsModel {
return $topicService->getUserTopics((string) $user->getId());
return $topicService->getUserTopics($user->getId());
}
#[Get('/topic/user/{id}')]
......@@ -72,6 +72,6 @@ class TopicController
#[Inject]
TopicService $topicService
): MultipleTopicsModel {
return $topicService->getUserTopics((string) $id);
return $topicService->getUserTopics($id);
}
}
......@@ -4,9 +4,8 @@ namespace App\Controller;
use App\Entity\User;
use App\Model\UserModel;
use App\Service\UserProvider;
use DateTimeImmutable;
use Exception;
use App\Model\UserResponseModel;
use App\Service\UserService;
use Kaa\Component\DependencyInjectionDecorator\Inject;
use Kaa\Component\HttpMessage\Response\JsonResponse;
use Kaa\Component\HttpMessage\Response\Response;
......@@ -15,7 +14,6 @@ use Kaa\Component\RequestMapperDecorator\MapJsonPayload;
use Kaa\Component\RequestMapperDecorator\MapRouteParameter;
use Kaa\Component\Router\Attribute\Get;
use Kaa\Component\Router\Attribute\Post;
use Kaa\Component\Router\Attribute\Put;
use Kaa\Component\SecurityDecorator\CurrentUser;
class UserController
......@@ -26,9 +24,9 @@ class UserController
#[MapJsonPayload]
UserModel $model,
#[Inject]
UserProvider $userProvider
UserService $userService
): int {
return $userProvider->createUser($model);
return $userService->createUser($model);
}
#[Get('/user/me')]
......@@ -37,54 +35,46 @@ class UserController
#[CurrentUser]
User $user,
#[Inject]
UserProvider $userProvider,
): UserModel {
return $userProvider->getCurrentUser($user);
UserService $userService
): UserResponseModel {
return $userService->getUserByEntity($user);
}
#[Get('/admin/user/{id}')]
#[AsJsonResponse]
public function getUser(
#[Inject]
UserProvider $userProvider,
UserService $userService,
#[MapRouteParameter]
int $id
): UserModel {
return $userProvider->getUserById($id);
): UserResponseModel {
return $userService->getUserById($id);
}
#[Put('/admin/user/{id}')]
#[Post('/put/admin/user/{id}')]
public function changeUser(
#[Inject]
UserProvider $userProvider,
UserService $userService,
#[MapRouteParameter]
int $id,
#[MapJsonPayload]
UserModel $userModel
): JsonResponse {
$userModel->setChangingDate(new DateTimeImmutable());
try {
$userProvider->updateUser($userModel, $id);
} catch (Exception $exception) {
return new JsonResponse('Nothing changed', status: 200);
}
return new JsonResponse('Successfully changed', status: 200);
$userService->updateUser($userModel, $id);
return new JsonResponse();
}
#[Put('/user/me')]
#[Post('/put/user/me')]
public function changeCurrentUser(
#[Inject]
UserProvider $userProvider,
UserService $userService,
#[CurrentUser]
User $user,
#[MapJsonPayload]
UserModel $userModel
): Response {
$userModel
->setRoles($user->getRoles())
->setCreationDate($user->getCreationTime())
->setChangingDate(new DateTimeImmutable());
$userProvider->updateUser($userModel, $user->getId());
return new JsonResponse('Successfully changed', status: 200);
$userModel->setRoles($user->getRoles());
$userService->updateUser($userModel, $user->getId());
return new JsonResponse('Successfully changed', 200);
}
}
<?php
namespace App\Entity;
use Kaa\Component\Database\Attribute as Db;
use Kaa\Component\Database\EntityInterface;
#[Db\Entity]
abstract class Admission implements EntityInterface
{
#[Db\Id]
#[Db\Column]
protected ?int $id = null;
#[Db\ManyToOne(Topic::class)]
protected Topic $topic;
#[Db\ManyToOne(User::class)]
protected User $user;
public function getId(): int
{
return $this->id ?? -1;
}
public function setId(int $id): Admission
{
$this->id = $id;
return $this;
}
public function getTopic(): Topic
{
return $this->topic;
}
public function setTopic(Topic $topic): Admission
{
$this->topic = $topic;
return $this;
}
public function getUser(): User
{
return $this->user;
}
public function setUser(User $user): Admission
{
$this->user = $user;
return $this;
}
}
......@@ -34,9 +34,13 @@ abstract class Article implements EntityInterface
#[Db\OneToMany(ArticleTag::class, mappedBy: 'article')]
protected array $tags = [];
/** @var Comment[] */
#[Db\OneToMany(Comment::class, mappedBy: 'article')]
protected array$comments = [];
public function getId(): int
{
return $this->id;
return $this->id ?? -1;
}
public function setId(int $id): Article
......@@ -45,11 +49,6 @@ abstract class Article implements EntityInterface
return $this;
}
public function getAuthorId(): int
{
return $this->author->getId();
}
public function getTopicId(): int
{
return $this->topic->getId();
......@@ -135,4 +134,18 @@ abstract class Article implements EntityInterface
$this->tags[] = $tag;
return $this;
}
/**
* @return Comment[]
*/
public function getComments(): array
{
return $this->comments;
}
public function addComment(Comment $comment): Article
{
$this->comments[] = $comment;
return $this;
}
}
......@@ -20,7 +20,7 @@ abstract class ArticleTag implements EntityInterface
public function getId(): int
{
return $this->id;
return $this->id ?? -1;
}
public function setId(int $id): ArticleTag
......@@ -29,15 +29,6 @@ abstract class ArticleTag implements EntityInterface
return $this;
}
public function getArticleId(): int
{
return $this->article->getId();
}
public function getTagId(): int
{
return $this->tag->getId();
}
public function getArticle(): Article
{
......
......@@ -30,7 +30,7 @@ abstract class Comment implements EntityInterface
public function getId(): int
{
return $this->id;
return $this->id ?? -1;
}
public function setId(int $id): Comment
......@@ -39,11 +39,6 @@ abstract class Comment implements EntityInterface
return $this;
}
public function getAuthorId(): int
{
return $this->author->getId();
}
public function getArticleId(): int
{
return $this->article->getId();
......
......@@ -15,13 +15,13 @@ abstract class Tag implements EntityInterface
#[Db\Column]
protected string $title;
/** @var Article[] */
/** @var ArticleTag[] */
#[Db\OneToMany(ArticleTag::class, mappedBy: 'tag')]
protected array $articles = [];
public function getId(): int
{
return $this->id;
return $this->id ?? -1;
}
public function setId(int $id): Tag
......