Compare commits
75
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9fd8453f63
|
||
|
|
a7d3942d1f
|
||
|
|
41933ec510
|
||
|
|
e98bb28faf
|
||
|
|
34eeb10c27
|
||
|
|
70e13f70c0
|
||
|
|
a89182b64f
|
||
|
|
45a22c2dd4
|
||
|
|
c6d33753c8
|
||
|
|
b32092f1cd
|
||
|
|
b5cb59d3ee
|
||
|
|
0b8d7b9cda
|
||
|
|
4f4cc43e90
|
||
|
|
b066ef22b4
|
||
|
|
08767d1d59
|
||
|
|
46404a9d7b
|
||
|
|
8a4c5403cb
|
||
|
|
15a58e8ace
|
||
|
|
d763c4344c
|
||
|
|
4dc08dffc9
|
||
|
|
87b811f716
|
||
|
|
eb4ebb9582
|
||
|
|
6af7813e3d
|
||
|
|
31ff9b287d
|
||
|
|
c9a06e5ada
|
||
|
|
4f007765f4
|
||
|
|
97780eb079
|
||
|
|
e487a59816
|
||
|
|
a7790319eb
|
||
|
|
e143d05801
|
||
|
|
7c0ebe6668
|
||
|
|
6eb54a6f11
|
||
|
|
ed137b38de
|
||
|
|
db757de71c
|
||
|
|
71aed9dcec
|
||
|
|
b809542083
|
||
|
|
749b93e3af
|
||
|
|
df3bf89079
|
||
|
|
de346c0c6e
|
||
|
|
6df63373ab
|
||
|
|
a0fe77fe66
|
||
|
|
151112bd2a
|
||
|
|
366abf61b3
|
||
|
|
367e78cbf8
|
||
|
|
c056e0bdfc
|
||
|
|
12890293e0
|
||
|
|
845f1fe262
|
||
|
|
bc9f1a1d1f
|
||
|
|
84df948012
|
||
|
|
1200489186
|
||
|
|
74d0b24f5f
|
||
|
|
cbe6d79ab5
|
||
|
|
72618c6c66
|
||
|
|
b6018a0715
|
||
|
|
35b7db81b2
|
||
|
|
89c7d3b0ea
|
||
|
|
13b62c8c02
|
||
|
|
364d55a4b2
|
||
|
|
e4dc8ace04
|
||
|
|
af8ecc748f
|
||
|
|
6d11be728e
|
||
|
|
453940a5ef
|
||
|
|
d45b790122
|
||
|
|
862daea29c
|
||
|
|
006ffea7c5
|
||
|
|
03d71727e8
|
||
|
|
b2584dca31
|
||
|
|
545e5b39ac
|
||
|
|
67619926ca
|
||
|
|
e13281af5f
|
||
|
|
36d5635812
|
||
|
|
ef6561ac19
|
||
|
|
f2aa55bc3e
|
||
|
|
48017bf46f
|
||
|
|
8edb7ff37f
|
No files matched your search
@@ -19,3 +19,5 @@ GOOGLE_OAUTH_CLIENT_SECRET=your_google_oauth_client_secret
|
||||
GOOGLE_ANALITICS_ID=your_google_analytics_id
|
||||
RECAPTCHA_SITEKEY=your_recaptcha_sitekey
|
||||
RECAPTCHA_SECRET=your_recaptcha_secret
|
||||
JWT_RSA_PRIVATE_KEY=jwt-rsa256-private.pem
|
||||
JWT_RSA_PUBLIC_KEY=jwt-rsa256-public.pem
|
||||
@@ -2,3 +2,4 @@
|
||||
installed
|
||||
vendor
|
||||
node_modules
|
||||
*.pem
|
||||
+2
-1
@@ -10,7 +10,8 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"esoko/soko-web": "0.1"
|
||||
"esoko/soko-web": "0.4",
|
||||
"firebase/php-jwt": "^6.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.6",
|
||||
|
||||
Generated
+67
-4
@@ -4,15 +4,15 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "3479948070678fa4e980114fbe8b71b5",
|
||||
"content-hash": "f7786e07bcb0373560ae67549fa28f0b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "esoko/soko-web",
|
||||
"version": "v0.1",
|
||||
"version": "v0.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://git.esoko.eu/esoko/soko-web.git",
|
||||
"reference": "a17a88e9d44e42cef3d996fc66b4dd1134b85def"
|
||||
"reference": "948b36c80d324e07339a543d97b9e629487f3a45"
|
||||
},
|
||||
"require": {
|
||||
"phpmailer/phpmailer": "^6.8",
|
||||
@@ -33,7 +33,70 @@
|
||||
"GNU GPL 3.0"
|
||||
],
|
||||
"description": "Lightweight web framework",
|
||||
"time": "2023-04-07T17:32:15+00:00"
|
||||
"time": "2023-04-16T18:52:06+00:00"
|
||||
},
|
||||
{
|
||||
"name": "firebase/php-jwt",
|
||||
"version": "v6.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/firebase/php-jwt.git",
|
||||
"reference": "4dd1e007f22a927ac77da5a3fbb067b42d3bc224"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/firebase/php-jwt/zipball/4dd1e007f22a927ac77da5a3fbb067b42d3bc224",
|
||||
"reference": "4dd1e007f22a927ac77da5a3fbb067b42d3bc224",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.1||^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"guzzlehttp/guzzle": "^6.5||^7.4",
|
||||
"phpspec/prophecy-phpunit": "^1.1",
|
||||
"phpunit/phpunit": "^7.5||^9.5",
|
||||
"psr/cache": "^1.0||^2.0",
|
||||
"psr/http-client": "^1.0",
|
||||
"psr/http-factory": "^1.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-sodium": "Support EdDSA (Ed25519) signatures",
|
||||
"paragonie/sodium_compat": "Support EdDSA (Ed25519) signatures when libsodium is not present"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Firebase\\JWT\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Neuman Vong",
|
||||
"email": "neuman+pear@twilio.com",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"name": "Anant Narayanan",
|
||||
"email": "anant@php.net",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.",
|
||||
"homepage": "https://github.com/firebase/php-jwt",
|
||||
"keywords": [
|
||||
"jwt",
|
||||
"php"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/firebase/php-jwt/issues",
|
||||
"source": "https://github.com/firebase/php-jwt/tree/v6.4.0"
|
||||
},
|
||||
"time": "2023-02-09T21:01:23+00:00"
|
||||
},
|
||||
{
|
||||
"name": "graham-campbell/result-type",
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
CREATE TABLE `oauth_tokens` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`nonce` varchar(255) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
||||
`user_id` int(10) unsigned DEFAULT NULL,
|
||||
`code` varchar(255) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
||||
`created` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
`expires` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `code` (`code`)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
||||
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE `users`
|
||||
ADD `username` varchar(100) DEFAULT NULL,
|
||||
ADD UNIQUE `username` (`username`);
|
||||
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE `users`
|
||||
ADD `full_name` varchar(255) NOT NULL DEFAULT '',
|
||||
ADD `nickname` varchar(255) NOT NULL DEFAULT '',
|
||||
ADD `phone` varchar(255) NOT NULL DEFAULT '',
|
||||
ADD `id_number` varchar(255) NOT NULL DEFAULT '';
|
||||
@@ -0,0 +1,4 @@
|
||||
ALTER TABLE `oauth_tokens`
|
||||
ADD `scope` varchar(255) NOT NULL DEFAULT '',
|
||||
ADD `access_token` varchar(255) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
||||
ADD UNIQUE `access_token` (`access_token`);
|
||||
@@ -0,0 +1,10 @@
|
||||
CREATE TABLE `oauth_clients` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`client_id` varchar(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
||||
`client_secret` varchar(40) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
||||
`redirect_uris` text NOT NULL,
|
||||
`preapproved` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`created` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `client_id` (`client_id`)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE `oauth_tokens`
|
||||
ADD `audience` varchar(255) NOT NULL DEFAULT '';
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE `oauth_tokens`
|
||||
DROP `audience`;
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE `oauth_clients`
|
||||
MODIFY `client_id` varchar(255) CHARACTER SET ascii COLLATE ascii_bin NOT NULL;
|
||||
@@ -0,0 +1,20 @@
|
||||
CREATE TABLE `communities` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`currency` varchar(3) NOT NULL,
|
||||
`created` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
||||
|
||||
CREATE TABLE `community_members` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`community_id` int(10) unsigned NOT NULL,
|
||||
`user_id` int(10) unsigned DEFAULT NULL,
|
||||
`owner` tinyint(1) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_user_for_community` (`community_id`, `user_id`),
|
||||
KEY `community_id` (`community_id`),
|
||||
KEY `user_id` (`user_id`),
|
||||
CONSTRAINT `community_members_community_id` FOREIGN KEY (`community_id`) REFERENCES `communities` (`id`),
|
||||
CONSTRAINT `community_members_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
||||
@@ -19,6 +19,12 @@ services:
|
||||
MYSQL_DATABASE: 'rvr'
|
||||
MYSQL_USER: 'rvr'
|
||||
MYSQL_PASSWORD: 'rvr'
|
||||
adminer:
|
||||
image: adminer:4.8.1-standalone
|
||||
ports:
|
||||
- 9090:8080
|
||||
environment:
|
||||
- ADMINER_DEFAULT_SERVER=mariadb
|
||||
mail:
|
||||
image: marcopas/docker-mailslurper:latest
|
||||
ports:
|
||||
|
||||
@@ -1,58 +1,3 @@
|
||||
<?php
|
||||
|
||||
use SokoWeb\Interfaces\Response\IRedirect;
|
||||
use SokoWeb\Response\Redirect;
|
||||
|
||||
require '../web.php';
|
||||
|
||||
$method = strtolower($_SERVER['REQUEST_METHOD']);
|
||||
$url = substr($_SERVER['REQUEST_URI'], strlen('/'));
|
||||
if (($pos = strpos($url, '?')) !== false) {
|
||||
$url = substr($url, 0, $pos);
|
||||
}
|
||||
$url = rawurldecode($url);
|
||||
|
||||
$match = Container::$routeCollection->match($method, $url == '' ? [] : explode('/', $url));
|
||||
|
||||
if ($match !== null) {
|
||||
list($route, $params) = $match;
|
||||
|
||||
Container::$request->setParsedRouteParams($params);
|
||||
|
||||
$handler = $route->getHandler();
|
||||
$controller = new $handler[0](Container::$request);
|
||||
|
||||
if ($controller instanceof SokoWeb\Interfaces\Authorization\ISecured) {
|
||||
$authorized = $controller->authorize();
|
||||
} else {
|
||||
$authorized = true;
|
||||
}
|
||||
|
||||
if (!$authorized) {
|
||||
Container::$request->session()->set('redirect_after_login', $url);
|
||||
$response = new Redirect(Container::$routeCollection->getRoute('login')->generateLink(), IRedirect::TEMPORARY);
|
||||
header('Location: ' . $response->getUrl(), true, $response->getHttpCode());
|
||||
return;
|
||||
}
|
||||
|
||||
if ($method === 'post' && Container::$request->post('anti_csrf_token') !== Container::$request->session()->get('anti_csrf_token')) {
|
||||
$content = new SokoWeb\Response\JsonContent(['error' => 'no_valid_anti_csrf_token']);
|
||||
header('Content-Type: text/html; charset=UTF-8', true, 403);
|
||||
$content->render();
|
||||
return;
|
||||
}
|
||||
|
||||
$response = call_user_func([$controller, $handler[1]]);
|
||||
if ($response instanceof SokoWeb\Interfaces\Response\IContent) {
|
||||
header('Content-Type: ' . $response->getContentType() . '; charset=UTF-8');
|
||||
$response->render();
|
||||
return;
|
||||
} elseif ($response instanceof SokoWeb\Interfaces\Response\IRedirect) {
|
||||
header('Location: ' . $response->getUrl(), true, $response->getHttpCode());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$content = new SokoWeb\Response\HtmlContent('error/404');
|
||||
header('Content-Type: text/html; charset=UTF-8', true, 404);
|
||||
$content->render();
|
||||
+33
-61
@@ -88,10 +88,14 @@ sub {
|
||||
}
|
||||
|
||||
hr {
|
||||
border: solid #bbbbbb 1px;
|
||||
border: solid #bbbbcc 1px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.normal {
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.bold {
|
||||
font-weight: 700;
|
||||
}
|
||||
@@ -385,13 +389,6 @@ main {
|
||||
padding: 6px 12px;
|
||||
}
|
||||
|
||||
main.full {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: calc(100% - 40px);
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
footer {
|
||||
background-color: #869ab9;
|
||||
padding: 3px 6px;
|
||||
@@ -411,20 +408,6 @@ div.buttonContainer>button {
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
#cookiesNotice {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
margin: 20px;
|
||||
background-color: #eeeeee;
|
||||
border: solid #888888 1px;
|
||||
border-radius: 3px;
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
#loading {
|
||||
position: fixed;
|
||||
width: 64px;
|
||||
@@ -439,50 +422,51 @@ div.buttonContainer>button {
|
||||
|
||||
div.box {
|
||||
width: 576px;
|
||||
background-color: #eeeeee;
|
||||
background-color: #eeeef4;
|
||||
border-radius: 3px;
|
||||
margin: 10px auto;
|
||||
padding: 10px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.circleControl {
|
||||
position: absolute;
|
||||
width: 60px;
|
||||
bottom: 20px;
|
||||
right: 10px;
|
||||
div.gridContainer {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
|
||||
grid-gap: 10px;
|
||||
}
|
||||
|
||||
.circleControl .controlItem {
|
||||
position: relative;
|
||||
height: 60px;
|
||||
margin-top: 10px;
|
||||
opacity: 70%;
|
||||
cursor: pointer;
|
||||
div.gridContainer > div {
|
||||
background-color: #eeeef4;
|
||||
border-radius: 3px;
|
||||
padding: 5px 10px;
|
||||
}
|
||||
|
||||
.circleControl .controlItem:hover {
|
||||
opacity: 100%;
|
||||
table {
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
}
|
||||
|
||||
.circleControl .controlItem div {
|
||||
position: absolute;
|
||||
table.fullWidth {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.circleControl .controlBackground {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
opacity: 50%;
|
||||
table th {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.circleControl .controlIcon {
|
||||
width: 75%;
|
||||
height: 75%;
|
||||
margin: auto;
|
||||
margin-top: 50%;
|
||||
transform: translateY(-50%);
|
||||
table th, table td {
|
||||
padding: 2px 0;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.choices__inner {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 424px) {
|
||||
div.gridContainer {
|
||||
grid-template-columns: auto;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 599px) {
|
||||
@@ -511,12 +495,6 @@ div.box {
|
||||
div.box {
|
||||
width: initial;
|
||||
}
|
||||
.circleControl {
|
||||
width: 45px;
|
||||
}
|
||||
.circleControl .controlItem {
|
||||
height: 45px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 600px) {
|
||||
@@ -546,12 +524,6 @@ div.box {
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.circleControl {
|
||||
width: 45px;
|
||||
}
|
||||
.circleControl .controlItem {
|
||||
height: 45px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-height: 400px) and (max-height: 499px) {
|
||||
|
||||
@@ -3,7 +3,7 @@ var Account = {
|
||||
countdown: null,
|
||||
|
||||
openGoogleAuthenticate: function () {
|
||||
window.open('/account/googleAuthenticate', 'googleAuthenticate', 'height=600,width=600')
|
||||
window.open(googleAuthenticateUrl, 'googleAuthenticate', 'height=600,width=600')
|
||||
},
|
||||
|
||||
authenticatedWithGoogleCallback: function (authenticatedWithGoogleUntil) {
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
(function () {
|
||||
const element = document.getElementById('new_member_user_id');
|
||||
const choices = new Choices(element, {
|
||||
noResultsText: 'No users found',
|
||||
noChoicesText: 'Start typing to search users'
|
||||
});
|
||||
|
||||
element.addEventListener('search', RVR.debounce(async function (e) {
|
||||
RVR.httpRequest('GET', searchUserUrl.replace('QUERY', encodeURIComponent(e.detail.value)), function () {
|
||||
choices.setChoices(this.response.results, 'value', 'label', true);
|
||||
});
|
||||
}));
|
||||
|
||||
element.addEventListener('choice', function () {
|
||||
choices.setChoices([], 'value', 'label', true);
|
||||
document.getElementById('new_member_button').disabled = false;
|
||||
});
|
||||
|
||||
document.getElementById('new_member_button').addEventListener('click', function () {
|
||||
document.getElementById('loading').style.visibility = 'visible';
|
||||
|
||||
let data = new FormData();
|
||||
data.append('user_id', document.getElementById('new_member_user_id').value);
|
||||
|
||||
RVR.httpRequest('POST', newMemberUrl, function () {
|
||||
window.location.reload();
|
||||
}, data);
|
||||
});
|
||||
|
||||
const ownerCheckboxesButtons = document.getElementsByClassName('member_owner');
|
||||
for (const ownerCheckboxesButton of ownerCheckboxesButtons) {
|
||||
ownerCheckboxesButton.addEventListener('change', function () {
|
||||
document.getElementById('loading').style.visibility = 'visible';
|
||||
|
||||
let data = new FormData();
|
||||
data.append('community_member_id', this.dataset.id);
|
||||
data.append('owner', this.checked ? 1 : 0);
|
||||
|
||||
RVR.httpRequest('POST', editMemberUrl, function () {
|
||||
document.getElementById('loading').style.visibility = 'hidden';
|
||||
|
||||
if (!this.response.success) {
|
||||
ownerCheckboxesButton.checked = !ownerCheckboxesButton.checked;
|
||||
}
|
||||
}, data);
|
||||
});
|
||||
};
|
||||
|
||||
const deleteButtons = document.getElementsByClassName('delete_member');
|
||||
for (const deleteButton of deleteButtons) {
|
||||
deleteButton.addEventListener('click', function () {
|
||||
document.getElementById('loading').style.visibility = 'visible';
|
||||
|
||||
let data = new FormData();
|
||||
data.append('community_member_id', this.dataset.id);
|
||||
|
||||
RVR.httpRequest('POST', deleteMemberUrl, function () {
|
||||
window.location.reload();
|
||||
}, data);
|
||||
});
|
||||
};
|
||||
})();
|
||||
+19
-7
@@ -1,6 +1,5 @@
|
||||
var RVR = {
|
||||
isSecure: window.location.protocol === 'https:',
|
||||
cookiesAgreed: false,
|
||||
sessionAvailableHooks: {},
|
||||
|
||||
initGoogleAnalitics: function () {
|
||||
@@ -159,12 +158,17 @@ var RVR = {
|
||||
document.getElementById('cover').style.visibility = 'hidden';
|
||||
},
|
||||
|
||||
observeInput: function (input, buttonToToggle) {
|
||||
observeInput: function (form, observedInputs) {
|
||||
var anyChanged = false;
|
||||
|
||||
for (var i = 0; i < observedInputs.length; i++) {
|
||||
var input = form.elements[observedInputs[i]];
|
||||
if (input.defaultValue !== input.value) {
|
||||
buttonToToggle.disabled = false;
|
||||
} else {
|
||||
buttonToToggle.disabled = true;
|
||||
anyChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
form.elements.submit.disabled = !anyChanged;
|
||||
},
|
||||
|
||||
observeInputsInForm: function (form, observedInputs) {
|
||||
@@ -175,12 +179,12 @@ var RVR = {
|
||||
case 'INPUT':
|
||||
case 'TEXTAREA':
|
||||
input.oninput = function () {
|
||||
RVR.observeInput(this, form.elements.submit);
|
||||
RVR.observeInput(form, observedInputs);
|
||||
};
|
||||
break;
|
||||
case 'SELECT':
|
||||
input.onchange = function () {
|
||||
RVR.observeInput(this, form.elements.submit);
|
||||
RVR.observeInput(form, observedInputs);
|
||||
};
|
||||
break;
|
||||
}
|
||||
@@ -189,6 +193,14 @@ var RVR = {
|
||||
form.onreset = function () {
|
||||
form.elements.submit.disabled = true;
|
||||
}
|
||||
},
|
||||
|
||||
debounce: function(func, timeout = 300) {
|
||||
let timer;
|
||||
return (...args) => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => { func.apply(this, args); }, timeout);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Generated
+57
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"requires": true,
|
||||
"lockfileVersion": 1,
|
||||
"dependencies": {
|
||||
"@babel/runtime": {
|
||||
"version": "7.21.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.21.0.tgz",
|
||||
"integrity": "sha512-xwII0//EObnq89Ji5AKYQaRYiW/nZ3llSv29d49IuxPhKbtJoLP+9QUUZ4nVragQVtaVGeZrpB+ZtG/Pdy/POw==",
|
||||
"requires": {
|
||||
"regenerator-runtime": "^0.13.11"
|
||||
}
|
||||
},
|
||||
"choices.js": {
|
||||
"version": "10.2.0",
|
||||
"resolved": "https://registry.npmjs.org/choices.js/-/choices.js-10.2.0.tgz",
|
||||
"integrity": "sha512-8PKy6wq7BMjNwDTZwr3+Zry6G2+opJaAJDDA/j3yxvqSCnvkKe7ZIFfIyOhoc7htIWFhsfzF9tJpGUATcpUtPg==",
|
||||
"requires": {
|
||||
"deepmerge": "^4.2.2",
|
||||
"fuse.js": "^6.6.2",
|
||||
"redux": "^4.2.0"
|
||||
}
|
||||
},
|
||||
"deepmerge": {
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz",
|
||||
"integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A=="
|
||||
},
|
||||
"fuse.js": {
|
||||
"version": "6.6.2",
|
||||
"resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-6.6.2.tgz",
|
||||
"integrity": "sha512-cJaJkxCCxC8qIIcPBF9yGxY0W/tVZS3uEISDxhYIdtk8OL93pe+6Zj7LjCqVV4dzbqcriOZ+kQ/NE4RXZHsIGA=="
|
||||
},
|
||||
"leaflet": {
|
||||
"version": "1.9.3",
|
||||
"resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.9.3.tgz",
|
||||
"integrity": "sha512-iB2cR9vAkDOu5l3HAay2obcUHZ7xwUBBjph8+PGtmW/2lYhbLizWtG7nTeYht36WfOslixQF9D/uSIzhZgGMfQ=="
|
||||
},
|
||||
"leaflet.markercluster": {
|
||||
"version": "1.5.3",
|
||||
"resolved": "https://registry.npmjs.org/leaflet.markercluster/-/leaflet.markercluster-1.5.3.tgz",
|
||||
"integrity": "sha512-vPTw/Bndq7eQHjLBVlWpnGeLa3t+3zGiuM7fJwCkiMFq+nmRuG3RI3f7f4N4TDX7T4NpbAXpR2+NTRSEGfCSeA=="
|
||||
},
|
||||
"redux": {
|
||||
"version": "4.2.1",
|
||||
"resolved": "https://registry.npmjs.org/redux/-/redux-4.2.1.tgz",
|
||||
"integrity": "sha512-LAUYz4lc+Do8/g7aeRa8JkyDErK6ekstQaqWQrNRW//MY1TvCEpMtpTWvlQ+FPbWCx+Xixu/6SHt5N0HR+SB4w==",
|
||||
"requires": {
|
||||
"@babel/runtime": "^7.9.2"
|
||||
}
|
||||
},
|
||||
"regenerator-runtime": {
|
||||
"version": "0.13.11",
|
||||
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz",
|
||||
"integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg=="
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"leaflet": "^1.6.0",
|
||||
"leaflet.markercluster": "^1.4.1"
|
||||
"leaflet.markercluster": "^1.4.1",
|
||||
"choices.js": "^10.2.0"
|
||||
}
|
||||
}
|
||||
@@ -9,5 +9,8 @@ $app->add(new RVR\Cli\MigrateDatabaseCommand());
|
||||
$app->add(new RVR\Cli\AddUserCommand());
|
||||
$app->add(new RVR\Cli\LinkViewCommand());
|
||||
$app->add(new RVR\Cli\MaintainDatabaseCommand());
|
||||
$app->add(new RVR\Cli\AddOAuthClientCommand());
|
||||
$app->add(new RVR\Cli\AddOAuthRedirectUriCommand());
|
||||
$app->add(new RVR\Cli\RemoveOAuthRedirectUriCommand());
|
||||
|
||||
$app->run();
|
||||
@@ -9,9 +9,6 @@ if [ -f ${ROOT_DIR}/installed ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Installing NPM packages..."
|
||||
(cd ${ROOT_DIR}/multi && npm install)
|
||||
|
||||
echo "Installing Yarn packages..."
|
||||
(cd ${ROOT_DIR}/public/static && yarn install)
|
||||
|
||||
|
||||
@@ -12,6 +12,6 @@ VERSION=$(git describe --tags --always --match "Release_*" HEAD)
|
||||
REVISION=$(git rev-parse --short HEAD)
|
||||
REVISION_DATE=$(git show -s --format=%aI HEAD)
|
||||
|
||||
sed -i -E "s/const VERSION = '(.*)';/const VERSION = '${VERSION}';/" main.php
|
||||
sed -i -E "s/const REVISION = '(.*)';/const REVISION = '${REVISION}';/" main.php
|
||||
sed -i -E "s/const REVISION_DATE = '(.*)';/const REVISION_DATE = '${REVISION_DATE}';/" main.php
|
||||
sed -i -E "s/const VERSION = '(.*)';/const VERSION = '${VERSION}';/" app.php
|
||||
sed -i -E "s/const REVISION = '(.*)';/const REVISION = '${REVISION}';/" app.php
|
||||
sed -i -E "s/const REVISION_DATE = '(.*)';/const REVISION_DATE = '${REVISION_DATE}';/" app.php
|
||||
@@ -11,9 +11,6 @@ else
|
||||
(cd ${ROOT_DIR} && composer install --dev)
|
||||
fi
|
||||
|
||||
echo "Installing NPM packages..."
|
||||
(cd ${ROOT_DIR}/multi && npm install)
|
||||
|
||||
echo "Installing Yarn packages..."
|
||||
(cd ${ROOT_DIR}/public/static && yarn install)
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php namespace RVR\Cli;
|
||||
|
||||
use DateTime;
|
||||
use SokoWeb\PersistentData\PersistentDataManager;
|
||||
use RVR\PersistentData\Model\OAuthClient;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class AddOAuthClientCommand extends Command
|
||||
{
|
||||
public function configure(): void
|
||||
{
|
||||
$this->setName('oauth:add-client')
|
||||
->setDescription('Adding of OAuth client.')
|
||||
->addArgument('client-id', InputArgument::OPTIONAL, 'Client ID')
|
||||
->addArgument('preapproved', InputArgument::OPTIONAL, 'Preapproved');
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$clientId = $input->getArgument('client-id') ? $input->getArgument('client-id') : bin2hex(random_bytes(8));
|
||||
$clientSecret = bin2hex(random_bytes(20));
|
||||
|
||||
$oAuthClient = new OAuthClient();
|
||||
$oAuthClient->setClientId($clientId);
|
||||
$oAuthClient->setClientSecret($clientSecret);
|
||||
$oAuthClient->setCreatedDate(new DateTime());
|
||||
|
||||
if ($input->getArgument('preapproved')) {
|
||||
$oAuthClient->setPreapproved($input->getArgument('preapproved'));
|
||||
}
|
||||
|
||||
try {
|
||||
$pdm = new PersistentDataManager();
|
||||
$pdm->saveToDb($oAuthClient);
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln('<error>Adding OAuth client failed!</error>');
|
||||
$output->writeln('');
|
||||
|
||||
$output->writeln((string) $e);
|
||||
$output->writeln('');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln('<info>OAuth client was successfully added!</info>');
|
||||
$output->writeln('<info>Client ID: ' . $clientId . '</info>');
|
||||
$output->writeln('<info>Client secret: ' . $clientSecret . '</info>');
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php namespace RVR\Cli;
|
||||
|
||||
use SokoWeb\PersistentData\PersistentDataManager;
|
||||
use RVR\Repository\OAuthClientRepository;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class AddOAuthRedirectUriCommand extends Command
|
||||
{
|
||||
public function configure(): void
|
||||
{
|
||||
$this->setName('oauth:add-redirect-uri')
|
||||
->setDescription('Adding of redirect URI for OAuth client.')
|
||||
->addArgument('client_id', InputArgument::REQUIRED, 'The OAuth client ID')
|
||||
->addArgument('redirect_uris', InputArgument::IS_ARRAY, 'Redirect URIs to add');
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$oAuthClientRepository = new OAuthClientRepository();
|
||||
$oAuthClient = $oAuthClientRepository->getByClientId($input->getArgument('client_id'));
|
||||
|
||||
if ($oAuthClient === null) {
|
||||
$output->writeln('<error>OAuth client does not exist!</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$redirectUris = array_unique(array_merge($oAuthClient->getRedirectUrisArray(), $input->getArgument('redirect_uris')));
|
||||
|
||||
$oAuthClient->setRedirectUrisArray($redirectUris);
|
||||
|
||||
try {
|
||||
$pdm = new PersistentDataManager();
|
||||
$pdm->saveToDb($oAuthClient);
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln('<error>Adding redirect URI failed!</error>');
|
||||
$output->writeln('');
|
||||
|
||||
$output->writeln((string) $e);
|
||||
$output->writeln('');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$redirectUrisToPrint = [];
|
||||
foreach ($redirectUris as $redirectUri) $redirectUrisToPrint[] = '* ' . $redirectUri;
|
||||
|
||||
$output->writeln('<info>Redirect URIS were successfully added! Current URIs:' . "\n" . implode("\n", $redirectUrisToPrint) . '</info>');
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,11 @@ class AddUserCommand extends Command
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
if (!filter_var($input->getArgument('email'), FILTER_VALIDATE_EMAIL)) {
|
||||
$output->writeln('<error>Please provide a valid email address.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
$user->setEmail($input->getArgument('email'));
|
||||
$user->setPlainPassword($input->getArgument('password'));
|
||||
|
||||
@@ -96,7 +96,7 @@ class MigrateDatabaseCommand extends Command
|
||||
while ($file = readdir($dir)) {
|
||||
$filePath = $path . '/' . $file;
|
||||
|
||||
if (!is_file($filePath) || in_array(pathinfo($file, PATHINFO_FILENAME), $done)) {
|
||||
if (!is_file($filePath) || $file == '.gitkeep' || in_array(pathinfo($file, PATHINFO_FILENAME), $done)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php namespace RVR\Cli;
|
||||
|
||||
use SokoWeb\PersistentData\PersistentDataManager;
|
||||
use RVR\Repository\OAuthClientRepository;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class RemoveOAuthRedirectUriCommand extends Command
|
||||
{
|
||||
public function configure(): void
|
||||
{
|
||||
$this->setName('oauth:remove-redirect-uri')
|
||||
->setDescription('Removing of redirect URI for OAuth client.')
|
||||
->addArgument('client_id', InputArgument::REQUIRED, 'The OAuth client ID')
|
||||
->addArgument('redirect_uris', InputArgument::IS_ARRAY, 'Redirect URIs to remove');
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$oAuthClientRepository = new OAuthClientRepository();
|
||||
$oAuthClient = $oAuthClientRepository->getByClientId($input->getArgument('client_id'));
|
||||
|
||||
if ($oAuthClient === null) {
|
||||
$output->writeln('<error>OAuth client does not exist!</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$redirectUris = array_diff($oAuthClient->getRedirectUrisArray(), $input->getArgument('redirect_uris'));
|
||||
|
||||
$oAuthClient->setRedirectUrisArray($redirectUris);
|
||||
|
||||
try {
|
||||
$pdm = new PersistentDataManager();
|
||||
$pdm->saveToDb($oAuthClient);
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln('<error>Removing redirect URI failed!</error>');
|
||||
$output->writeln('');
|
||||
|
||||
$output->writeln((string) $e);
|
||||
$output->writeln('');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$redirectUrisToPrint = [];
|
||||
foreach ($redirectUris as $redirectUri) $redirectUrisToPrint[] = '* ' . $redirectUri;
|
||||
|
||||
$output->writeln('<info>Redirect URIS were successfully removed! Current URIs:' . "\n" . implode("\n", $redirectUrisToPrint) . '</info>');
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
<?php namespace RVR\Controller;
|
||||
|
||||
use DateTime;
|
||||
use RVR\PersistentData\Model\Community;
|
||||
use RVR\PersistentData\Model\CommunityMember;
|
||||
use RVR\PersistentData\Model\User;
|
||||
use RVR\Repository\CommunityRepository;
|
||||
use RVR\Repository\CommunityMemberRepository;
|
||||
use RVR\Repository\UserRepository;
|
||||
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
||||
use SokoWeb\Interfaces\Request\IRequest;
|
||||
use SokoWeb\Interfaces\Response\IContent;
|
||||
use SokoWeb\PersistentData\PersistentDataManager;
|
||||
use SokoWeb\Response\HtmlContent;
|
||||
use SokoWeb\Response\JsonContent;
|
||||
|
||||
class CommunityController implements IAuthenticationRequired
|
||||
{
|
||||
private IRequest $request;
|
||||
|
||||
private PersistentDataManager $pdm;
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
private CommunityRepository $communityRepository;
|
||||
|
||||
private CommunityMemberRepository $communityMemberRepository;
|
||||
|
||||
public function __construct(IRequest $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->pdm = new PersistentDataManager();
|
||||
$this->userRepository = new UserRepository();
|
||||
$this->communityRepository = new CommunityRepository();
|
||||
$this->communityMemberRepository = new CommunityMemberRepository();
|
||||
}
|
||||
|
||||
public function isAuthenticationRequired(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getCommunityHome(): ?IContent
|
||||
{
|
||||
if (!$this->checkPermission($this->request->query('communityId'), false, $community, $ownCommunityMember)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new HtmlContent('communities/community', [
|
||||
'community' => $community,
|
||||
'members' => $this->getMembers($community),
|
||||
'currencyNames' => [],
|
||||
'upcomingEvents' => [],
|
||||
'editPermission' => $ownCommunityMember->getOwner()
|
||||
]);
|
||||
}
|
||||
|
||||
public function getCommunityNew(): IContent
|
||||
{
|
||||
return new HtmlContent('communities/community_edit');
|
||||
}
|
||||
|
||||
public function getCommunityEdit(): ?IContent
|
||||
{
|
||||
if (!$this->checkPermission($this->request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new HtmlContent('communities/community_edit', [
|
||||
'community' => $community
|
||||
]);
|
||||
}
|
||||
|
||||
public function getMembersEdit(): ?IContent
|
||||
{
|
||||
if (!$this->checkPermission($this->request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new HtmlContent('communities/community_members', [
|
||||
'community' => $community,
|
||||
'members' => $this->getMembers($community)
|
||||
]);
|
||||
}
|
||||
|
||||
private function getMembers(Community $community): array
|
||||
{
|
||||
$members = iterator_to_array($this->communityMemberRepository->getAllByCommunity($community, true));
|
||||
usort($members, function($a, $b) {
|
||||
return strnatcmp($a->getUser()->getDisplayName(), $b->getUser()->getDisplayName());
|
||||
});
|
||||
return $members;
|
||||
}
|
||||
|
||||
|
||||
public function newMember(): ?IContent
|
||||
{
|
||||
if (!$this->checkPermission($this->request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$user = $this->userRepository->getById($this->request->post('user_id'));
|
||||
|
||||
$communityMember = new CommunityMember();
|
||||
$communityMember->setCommunity($community);
|
||||
$communityMember->setUser($user);
|
||||
$this->pdm->saveToDb($communityMember);
|
||||
|
||||
return new JsonContent(['success' => true]);
|
||||
}
|
||||
|
||||
public function editMember(): ?IContent
|
||||
{
|
||||
if (!$this->checkPermission($this->request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$communityMember = $this->communityMemberRepository->getById($this->request->post('community_member_id'));
|
||||
if ($communityMember->getUserId() === $this->request->user()->getUniqueId()) {
|
||||
return new JsonContent([
|
||||
'error' => ['errorText' => 'Own user cannot be edited.']
|
||||
]);
|
||||
}
|
||||
|
||||
$communityMember->setOwner($this->request->post('owner'));
|
||||
$this->pdm->saveToDb($communityMember);
|
||||
|
||||
return new JsonContent(['success' => true]);
|
||||
}
|
||||
|
||||
public function deleteMember(): ?IContent
|
||||
{
|
||||
if (!$this->checkPermission($this->request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$communityMember = $this->communityMemberRepository->getById($this->request->post('community_member_id'));
|
||||
if ($communityMember->getUserId() === $this->request->user()->getUniqueId()) {
|
||||
return new JsonContent([
|
||||
'error' => ['errorText' => 'Own user cannot be deleted.']
|
||||
]);
|
||||
}
|
||||
|
||||
$this->pdm->deleteFromDb($communityMember);
|
||||
|
||||
return new JsonContent(['success' => true]);
|
||||
}
|
||||
|
||||
public function saveCommunity(): ?IContent
|
||||
{
|
||||
$communityId = $this->request->query('communityId');
|
||||
if ($communityId){
|
||||
if (!$this->checkPermission($communityId, true, $community, $ownCommunityMember)) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
$community = new Community();
|
||||
}
|
||||
|
||||
$name = $this->request->post('name');
|
||||
$currency = $this->request->post('currency');
|
||||
if (strlen($name) === 0 || strlen($currency) === 0 || strlen($currency) > 3) {
|
||||
return new JsonContent([
|
||||
'error' => ['errorText' => 'Please fill all required fields!']
|
||||
]);
|
||||
}
|
||||
|
||||
$community->setName($name);
|
||||
$community->setCurrency($currency);
|
||||
if (!$communityId) {
|
||||
$community->setCreatedDate(new DateTime());
|
||||
}
|
||||
$this->pdm->saveToDb($community);
|
||||
|
||||
if (!$communityId) {
|
||||
/**
|
||||
* @var User $user
|
||||
*/
|
||||
$user = $this->request->user();
|
||||
|
||||
$communityMember = new CommunityMember();
|
||||
$communityMember->setCommunity($community);
|
||||
$communityMember->setUser($user);
|
||||
$communityMember->setOwner(true);
|
||||
$this->pdm->saveToDb($communityMember);
|
||||
}
|
||||
|
||||
return new JsonContent([
|
||||
'redirect' => ['target' => \Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()])]
|
||||
]);
|
||||
}
|
||||
|
||||
private function checkPermission(
|
||||
int $communityId,
|
||||
bool $needToBeOwner,
|
||||
?Community &$community,
|
||||
?CommunityMember &$ownCommunityMember): bool
|
||||
{
|
||||
$community = $this->communityRepository->getById($communityId);
|
||||
if ($community === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var User $user
|
||||
*/
|
||||
$user = $this->request->user();
|
||||
|
||||
$ownCommunityMember = $this->communityMemberRepository->getByCommunityAndUser($community, $user);
|
||||
if ($ownCommunityMember === null || ($needToBeOwner && !$ownCommunityMember->getOwner())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,48 @@
|
||||
<?php namespace RVR\Controller;
|
||||
|
||||
use SokoWeb\Interfaces\Authorization\ISecured;
|
||||
use RVR\PersistentData\Model\User;
|
||||
use RVR\Repository\CommunityMemberRepository;
|
||||
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
||||
use SokoWeb\Interfaces\Request\IRequest;
|
||||
use SokoWeb\Interfaces\Response\IContent;
|
||||
use SokoWeb\Response\HtmlContent;
|
||||
use SokoWeb\Response\JsonContent;
|
||||
|
||||
class HomeController implements ISecured
|
||||
class HomeController implements IAuthenticationRequired
|
||||
{
|
||||
private IRequest $request;
|
||||
|
||||
private CommunityMemberRepository $communityMemberRepository;
|
||||
|
||||
public function __construct(IRequest $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->communityMemberRepository = new CommunityMemberRepository();
|
||||
}
|
||||
|
||||
public function authorize(): bool
|
||||
public function isAuthenticationRequired(): bool
|
||||
{
|
||||
return $this->request->user() !== null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getIndex(): IContent
|
||||
public function getHome(): IContent
|
||||
{
|
||||
return new HtmlContent('index');
|
||||
/**
|
||||
* @var User $user
|
||||
*/
|
||||
$user = $this->request->user();
|
||||
|
||||
$ownCommunityMembers = $this->communityMemberRepository->getAllByUser($user, true);
|
||||
$communities = [];
|
||||
foreach ($ownCommunityMembers as $ownCommunityMember) {
|
||||
$communities[] = $ownCommunityMember->getCommunity();
|
||||
}
|
||||
usort($communities, function($a, $b) {
|
||||
return strnatcmp($a->getName(), $b->getName());
|
||||
});
|
||||
|
||||
return new HtmlContent('home', [
|
||||
'communities' => $communities,
|
||||
'upcomingEvents' => []
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -27,21 +27,27 @@ class LoginController
|
||||
|
||||
private UserPasswordResetterRepository $userPasswordResetterRepository;
|
||||
|
||||
private string $redirectUrl;
|
||||
|
||||
public function __construct(IRequest $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->pdm = new PersistentDataManager();
|
||||
$this->userRepository = new UserRepository();
|
||||
$this->userPasswordResetterRepository = new UserPasswordResetterRepository();
|
||||
$this->redirectUrl = $this->request->session()->has('redirect_after_login') ?
|
||||
$this->request->session()->get('redirect_after_login') :
|
||||
\Container::$routeCollection->getRoute('home')->generateLink();
|
||||
}
|
||||
|
||||
public function getLoginForm()
|
||||
{
|
||||
if ($this->request->user() !== null) {
|
||||
return new Redirect(\Container::$routeCollection->getRoute('index')->generateLink(), IRedirect::TEMPORARY);
|
||||
$this->deleteRedirectUrl();
|
||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||
}
|
||||
|
||||
return new HtmlContent('login/login');
|
||||
return new HtmlContent('login/login', ['redirectUrl' => $this->redirectUrl]);
|
||||
}
|
||||
|
||||
public function getGoogleLoginRedirect(): IRedirect
|
||||
@@ -55,7 +61,7 @@ class LoginController
|
||||
$oAuth = new GoogleOAuth(new Request());
|
||||
$url = $oAuth->getDialogUrl(
|
||||
$state,
|
||||
$this->request->getBase() . '/' . \Container::$routeCollection->getRoute('login-google-action')->generateLink(),
|
||||
$this->request->getBase() . \Container::$routeCollection->getRoute('login-google-action')->generateLink(),
|
||||
$nonce
|
||||
);
|
||||
|
||||
@@ -65,7 +71,8 @@ class LoginController
|
||||
public function getRequestPasswordResetForm()
|
||||
{
|
||||
if ($this->request->user() !== null) {
|
||||
return new Redirect(\Container::$routeCollection->getRoute('index')->generateLink(), IRedirect::TEMPORARY);
|
||||
$this->deleteRedirectUrl();
|
||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||
}
|
||||
|
||||
return new HtmlContent('login/password_reset_request', ['email' => $this->request->query('email')]);
|
||||
@@ -79,7 +86,8 @@ class LoginController
|
||||
public function getResetPasswordForm()
|
||||
{
|
||||
if ($this->request->user() !== null) {
|
||||
return new Redirect(\Container::$routeCollection->getRoute('index')->generateLink(), IRedirect::TEMPORARY);
|
||||
$this->deleteRedirectUrl();
|
||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||
}
|
||||
|
||||
$token = $this->request->query('token');
|
||||
@@ -91,95 +99,91 @@ class LoginController
|
||||
|
||||
$user = $this->userRepository->getById($resetter->getUserId());
|
||||
|
||||
return new HtmlContent('login/reset_password', ['success' => true, 'token' => $token, 'email' => $user->getEmail()]);
|
||||
return new HtmlContent('login/reset_password', ['success' => true, 'token' => $token, 'email' => $user->getEmail(), 'redirectUrl' => $this->redirectUrl]);
|
||||
}
|
||||
|
||||
public function login(): IContent
|
||||
{
|
||||
if ($this->request->user() !== null) {
|
||||
$this->deleteRedirectUrl();
|
||||
return new JsonContent(['success' => true]);
|
||||
}
|
||||
|
||||
$user = $this->userRepository->getByEmail($this->request->post('email'));
|
||||
$user = $this->userRepository->getByEmailOrUsername($this->request->post('email'));
|
||||
if ($user === null || !$user->checkPassword($this->request->post('password'))) {
|
||||
return new JsonContent([
|
||||
'error' => [
|
||||
'errorText' => 'No user found with the given email address or the given password is wrong. You can <a href="/password/requestReset?email=' .
|
||||
urlencode($this->request->post('email')) . '" title="Request password reset">request password reset</a>!'
|
||||
'errorText' => 'No user found with the given email address / username or the given password is wrong. You can <a href="' .
|
||||
\Container::$routeCollection->getRoute('password-requestReset')->generateLink(['email' => $this->request->post('email')]) . '" title="Request password reset">request password reset</a>!'
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
$this->request->setUser($user);
|
||||
|
||||
$this->deleteRedirectUrl();
|
||||
return new JsonContent(['success' => true]);
|
||||
}
|
||||
|
||||
public function loginWithGoogle()
|
||||
{
|
||||
$redirectUrl = $this->request->session()->get('redirect_after_login');
|
||||
if ($redirectUrl === null) {
|
||||
$redirectUrl = \Container::$routeCollection->getRoute('index')->generateLink();
|
||||
}
|
||||
$defaultError = 'Authentication with Google failed. Please <a href="' . \Container::$routeCollection->getRoute('login-google')->generateLink() . '" title="Login with Google">try again</a>!';
|
||||
|
||||
if ($this->request->user() !== null) {
|
||||
$this->request->session()->delete('redirect_after_login');
|
||||
return new Redirect($redirectUrl, IRedirect::TEMPORARY);
|
||||
$this->deleteRedirectUrl();
|
||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||
}
|
||||
|
||||
if ($this->request->query('state') !== $this->request->session()->get('oauth_state')) {
|
||||
return new HtmlContent('login/google_login');
|
||||
return new HtmlContent('login/google_login_error', ['error' => $defaultError]);
|
||||
}
|
||||
|
||||
$oAuth = new GoogleOAuth(new Request());
|
||||
$tokenData = $oAuth->getToken(
|
||||
$this->request->query('code'),
|
||||
$this->request->getBase() . '/' . \Container::$routeCollection->getRoute('login-google-action')->generateLink()
|
||||
$this->request->getBase() . \Container::$routeCollection->getRoute('login-google-action')->generateLink()
|
||||
);
|
||||
|
||||
if (!isset($tokenData['id_token'])) {
|
||||
return new HtmlContent('login/google_login');
|
||||
return new HtmlContent('login/google_login_error', ['error' => $defaultError]);
|
||||
}
|
||||
|
||||
$jwtParser = new JwtParser($tokenData['id_token']);
|
||||
$idToken = $jwtParser->getPayload();
|
||||
|
||||
if ($idToken['nonce'] !== $this->request->session()->get('oauth_nonce')) {
|
||||
return new HtmlContent('login/google_login');
|
||||
return new HtmlContent('login/google_login_error', ['error' => $defaultError]);
|
||||
}
|
||||
|
||||
if (!$idToken['email_verified']) {
|
||||
return new HtmlContent('login/google_login');
|
||||
return new HtmlContent('login/google_login_error', ['error' => $defaultError]);
|
||||
}
|
||||
|
||||
$user = $this->userRepository->getByGoogleSub($idToken['sub']);
|
||||
if ($user === null) {
|
||||
return new JsonContent([
|
||||
'error' => [
|
||||
'errorText' => 'No user found for this Google account.'
|
||||
]
|
||||
]);
|
||||
return new HtmlContent('login/google_login_error', ['error' => 'No user found for this Google account.']);
|
||||
}
|
||||
|
||||
$this->request->setUser($user);
|
||||
|
||||
$this->request->session()->delete('redirect_after_login');
|
||||
return new Redirect($redirectUrl, IRedirect::TEMPORARY);
|
||||
$this->deleteRedirectUrl();
|
||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||
}
|
||||
|
||||
public function logout(): IRedirect
|
||||
{
|
||||
$this->request->setUser(null);
|
||||
|
||||
return new Redirect(\Container::$routeCollection->getRoute('index')->generateLink(), IRedirect::TEMPORARY);
|
||||
return new Redirect(\Container::$routeCollection->getRoute('home')->generateLink(), IRedirect::TEMPORARY);
|
||||
}
|
||||
|
||||
public function requestPasswordReset(): IContent
|
||||
{
|
||||
if ($this->request->user() !== null) {
|
||||
$this->deleteRedirectUrl();
|
||||
return new JsonContent([
|
||||
'redirect' => [
|
||||
'target' => '/' . \Container::$routeCollection->getRoute('home')->generateLink()
|
||||
'target' => $this->redirectUrl
|
||||
]
|
||||
]);
|
||||
}
|
||||
@@ -196,11 +200,11 @@ class LoginController
|
||||
}
|
||||
}
|
||||
|
||||
$user = $this->userRepository->getByEmail($this->request->post('email'));
|
||||
$user = $this->userRepository->getByEmailOrUsername($this->request->post('email'));
|
||||
if ($user === null) {
|
||||
return new JsonContent([
|
||||
'error' => [
|
||||
'errorText' => 'No user found with the given email address.'
|
||||
'errorText' => 'No user found with the given email address / username.'
|
||||
]
|
||||
]);
|
||||
}
|
||||
@@ -240,9 +244,10 @@ class LoginController
|
||||
public function resetPassword(): IContent
|
||||
{
|
||||
if ($this->request->user() !== null) {
|
||||
$this->deleteRedirectUrl();
|
||||
return new JsonContent([
|
||||
'redirect' => [
|
||||
'target' => '/' . \Container::$routeCollection->getRoute('home')->generateLink()
|
||||
'target' => $this->redirectUrl
|
||||
]
|
||||
]);
|
||||
}
|
||||
@@ -253,7 +258,7 @@ class LoginController
|
||||
if ($resetter === null || $resetter->getExpiresDate() < new DateTime()) {
|
||||
return new JsonContent([
|
||||
'redirect' => [
|
||||
'target' => '/' . \Container::$routeCollection->getRoute('password-reset')->generateLink(['token' => $token])
|
||||
'target' => \Container::$routeCollection->getRoute('password-reset')->generateLink(['token' => $token])
|
||||
]
|
||||
]);
|
||||
}
|
||||
@@ -283,6 +288,7 @@ class LoginController
|
||||
|
||||
$this->request->setUser($user);
|
||||
|
||||
$this->deleteRedirectUrl();
|
||||
return new JsonContent(['success' => true]);
|
||||
}
|
||||
|
||||
@@ -293,10 +299,15 @@ class LoginController
|
||||
$mail->setSubject($_ENV['APP_NAME'] . ' - Password reset');
|
||||
$mail->setBodyFromTemplate('password-reset', [
|
||||
'EMAIL' => $email,
|
||||
'RESET_LINK' => $this->request->getBase() . '/' .
|
||||
'RESET_LINK' => $this->request->getBase() .
|
||||
\Container::$routeCollection->getRoute('password-reset')->generateLink(['token' => $token]),
|
||||
'EXPIRES' => $expires->format('Y-m-d H:i T')
|
||||
]);
|
||||
$mail->send();
|
||||
}
|
||||
|
||||
private function deleteRedirectUrl(): void
|
||||
{
|
||||
$this->request->session()->delete('redirect_after_login');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php namespace RVR\Controller;
|
||||
|
||||
use DateTime;
|
||||
use RVR\PersistentData\Model\OAuthToken;
|
||||
use RVR\PersistentData\Model\User;
|
||||
use RVR\Repository\OAuthClientRepository;
|
||||
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
||||
use SokoWeb\Interfaces\Request\IRequest;
|
||||
use SokoWeb\Interfaces\Response\IRedirect;
|
||||
use SokoWeb\Response\Redirect;
|
||||
use SokoWeb\PersistentData\PersistentDataManager;
|
||||
use SokoWeb\Response\HtmlContent;
|
||||
|
||||
class OAuthAuthController implements IAuthenticationRequired
|
||||
{
|
||||
private IRequest $request;
|
||||
|
||||
private PersistentDataManager $pdm;
|
||||
|
||||
private OAuthClientRepository $oAuthClientRepository;
|
||||
|
||||
public function __construct(IRequest $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->pdm = new PersistentDataManager();
|
||||
$this->oAuthClientRepository = new OAuthClientRepository();
|
||||
}
|
||||
|
||||
public function isAuthenticationRequired(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function auth()
|
||||
{
|
||||
$redirectUri = $this->request->query('redirect_uri');
|
||||
$clientId = $this->request->query('client_id');
|
||||
$scope = $this->request->query('scope') ? $this->request->query('scope'): '';
|
||||
$state = $this->request->query('state');
|
||||
$nonce = $this->request->query('nonce') ? $this->request->query('nonce'): '';
|
||||
|
||||
if (!$clientId || !$redirectUri || !$state) {
|
||||
return new HtmlContent('oauth/oauth_error', ['error' => 'An invalid request was made. Please start authentication again.']);
|
||||
}
|
||||
|
||||
$client = $this->oAuthClientRepository->getByClientId($clientId);
|
||||
if ($client === null) {
|
||||
return new HtmlContent('oauth/oauth_error', ['error' => 'Client is not authorized.']);
|
||||
}
|
||||
|
||||
$redirectUriParsed = parse_url($redirectUri);
|
||||
$redirectUriBase = $redirectUriParsed['scheme'] . '://' . $redirectUriParsed['host'] . $redirectUriParsed['path'];
|
||||
$redirectUriQuery = [];
|
||||
if (isset($redirectUriParsed['query'])) {
|
||||
parse_str($redirectUriParsed['query'], $redirectUriQuery);
|
||||
}
|
||||
|
||||
if (!in_array($redirectUriBase, $client->getRedirectUrisArray())) {
|
||||
return new HtmlContent('oauth/oauth_error', ['error' => 'Redirect URI \'' . $redirectUriBase .'\' is not allowed for this client.']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var ?User $user
|
||||
*/
|
||||
$user = $this->request->user();
|
||||
$code = bin2hex(random_bytes(16));
|
||||
$accessToken = bin2hex(random_bytes(16));
|
||||
|
||||
$token = new OAuthToken();
|
||||
$token->setNonce($nonce);
|
||||
$token->setScope($scope);
|
||||
$token->setUser($user);
|
||||
$token->setCode($code);
|
||||
$token->setAccessToken($accessToken);
|
||||
$token->setCreatedDate(new DateTime());
|
||||
$token->setExpiresDate(new DateTime('+5 minutes'));
|
||||
$this->pdm->saveToDb($token);
|
||||
|
||||
$redirectUriQuery = array_merge($redirectUriQuery, [
|
||||
'state' => $state,
|
||||
'code' => $code
|
||||
]);
|
||||
$finalRedirectUri = $redirectUriBase . '?' . http_build_query($redirectUriQuery);
|
||||
|
||||
return new Redirect($finalRedirectUri, IRedirect::TEMPORARY);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
<?php namespace RVR\Controller;
|
||||
|
||||
use DateTime;
|
||||
use Firebase\JWT\JWT;
|
||||
use RVR\Repository\OAuthTokenRepository;
|
||||
use RVR\Repository\UserRepository;
|
||||
use RVR\PersistentData\Model\User;
|
||||
use RVR\Repository\OAuthClientRepository;
|
||||
use SokoWeb\Interfaces\Request\IRequest;
|
||||
use SokoWeb\Interfaces\Response\IContent;
|
||||
use SokoWeb\Response\JsonContent;
|
||||
|
||||
class OAuthController
|
||||
{
|
||||
private IRequest $request;
|
||||
|
||||
private OAuthClientRepository $oAuthClientRepository;
|
||||
|
||||
private OAuthTokenRepository $oAuthTokenRepository;
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
public function __construct(IRequest $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->oAuthClientRepository = new OAuthClientRepository();
|
||||
$this->oAuthTokenRepository = new OAuthTokenRepository();
|
||||
$this->userRepository = new UserRepository();
|
||||
}
|
||||
|
||||
public function getToken(): ?IContent
|
||||
{
|
||||
$clientId = $this->request->post('client_id');
|
||||
$clientSecret = $this->request->post('client_secret');
|
||||
$code = $this->request->post('code');
|
||||
|
||||
if (!$clientId || !$clientSecret || !$code) {
|
||||
return new JsonContent([
|
||||
'error' => 'An invalid request was made.'
|
||||
]);
|
||||
}
|
||||
|
||||
$client = $this->oAuthClientRepository->getByClientId($clientId);
|
||||
if ($client === null || $client->getClientSecret() !== $clientSecret) {
|
||||
return new JsonContent([
|
||||
'error' => 'Client is not authorized.'
|
||||
]);
|
||||
}
|
||||
|
||||
$token = $this->oAuthTokenRepository->getByCode($code);
|
||||
if ($token === null || $token->getExpiresDate() < new DateTime()) {
|
||||
return new JsonContent([
|
||||
'error' => 'The provided code is invalid.'
|
||||
]);
|
||||
}
|
||||
|
||||
$payload = array_merge([
|
||||
'iss' => $_ENV['APP_URL'],
|
||||
'iat' => (int)$token->getCreatedDate()->getTimestamp(),
|
||||
'nbf' => (int)$token->getCreatedDate()->getTimestamp(),
|
||||
'exp' => (int)$token->getExpiresDate()->getTimestamp(),
|
||||
'aud' => $clientId,
|
||||
'nonce' => $token->getNonce()
|
||||
], $this->getUserInfoInternal(
|
||||
$this->userRepository->getById($token->getUserId()),
|
||||
$token->getScopeArray())
|
||||
);
|
||||
|
||||
$privateKey = file_get_contents(ROOT . '/' . $_ENV['JWT_RSA_PRIVATE_KEY']);
|
||||
$jwt = JWT::encode($payload, $privateKey, 'RS256');
|
||||
|
||||
return new JsonContent([
|
||||
'access_token' => $token->getAccessToken(),
|
||||
'expires_in' => $token->getExpiresDate()->getTimestamp() - (new DateTime())->getTimestamp(),
|
||||
'scope' => $token->getScope(),
|
||||
'id_token' => $jwt,
|
||||
'token_type' => 'Bearer'
|
||||
]);
|
||||
}
|
||||
|
||||
public function getUserInfo() : IContent
|
||||
{
|
||||
$authorization = $this->request->header('Authorization');
|
||||
if ($authorization === null) {
|
||||
return new JsonContent([
|
||||
'error' => 'No Authorization header was sent.'
|
||||
]);
|
||||
}
|
||||
|
||||
$accessToken = substr($authorization, strlen('Bearer '));
|
||||
$token = $this->oAuthTokenRepository->getByAccessToken($accessToken);
|
||||
|
||||
if ($token === null || $token->getExpiresDate() < new DateTime()) {
|
||||
return new JsonContent([
|
||||
'error' => 'The provided access token is invalid.'
|
||||
]);
|
||||
}
|
||||
|
||||
return new JsonContent(
|
||||
$this->getUserInfoInternal(
|
||||
$this->userRepository->getById($token->getUserId()),
|
||||
$token->getScopeArray()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getConfig(): IContent
|
||||
{
|
||||
return new JsonContent([
|
||||
'issuer' => $_ENV['APP_URL'],
|
||||
'authorization_endpoint' => $this->request->getBase() . \Container::$routeCollection->getRoute('oauth-auth')->generateLink(),
|
||||
'token_endpoint' => $this->request->getBase() . \Container::$routeCollection->getRoute('oauth-token')->generateLink(),
|
||||
'userinfo_endpoint' => $this->request->getBase() . \Container::$routeCollection->getRoute('oauth-userinfo')->generateLink(),
|
||||
'jwks_uri' => $this->request->getBase() . \Container::$routeCollection->getRoute('oauth-certs')->generateLink(),
|
||||
'response_types_supported' =>
|
||||
[
|
||||
'code',
|
||||
],
|
||||
'subject_types_supported' =>
|
||||
[
|
||||
'public',
|
||||
],
|
||||
'id_token_signing_alg_values_supported' =>
|
||||
[
|
||||
'RS256',
|
||||
],
|
||||
'scopes_supported' =>
|
||||
[
|
||||
'openid',
|
||||
'email',
|
||||
'profile',
|
||||
],
|
||||
'token_endpoint_auth_methods_supported' =>
|
||||
[
|
||||
'client_secret_post',
|
||||
],
|
||||
'claims_supported' =>
|
||||
[
|
||||
'aud',
|
||||
'email',
|
||||
'exp',
|
||||
'full_name',
|
||||
'iat',
|
||||
'id_number',
|
||||
'iss',
|
||||
'nickname',
|
||||
'phone',
|
||||
'picture',
|
||||
'sub',
|
||||
'username',
|
||||
],
|
||||
'code_challenge_methods_supported' =>
|
||||
[
|
||||
'plain',
|
||||
'S256',
|
||||
],
|
||||
'grant_types_supported' =>
|
||||
[
|
||||
'authorization_code',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function getCerts(): IContent
|
||||
{
|
||||
$publicKey = file_get_contents(ROOT . '/' . $_ENV['JWT_RSA_PUBLIC_KEY']);
|
||||
$keyInfo = openssl_pkey_get_details(openssl_pkey_get_public($publicKey));
|
||||
|
||||
return new JsonContent(['keys' => [
|
||||
[
|
||||
'kty' => 'RSA',
|
||||
'alg' => 'RS256',
|
||||
'use' => 'sig',
|
||||
'kid' => '1',
|
||||
'n' => str_replace(['+', '/'], ['-', '_'], base64_encode($keyInfo['rsa']['n'])),
|
||||
'e' => str_replace(['+', '/'], ['-', '_'], base64_encode($keyInfo['rsa']['e'])),
|
||||
]
|
||||
]]);
|
||||
}
|
||||
|
||||
private function getUserInfoInternal(User $user, array $scope): array
|
||||
{
|
||||
$userInfo = [];
|
||||
if (in_array('openid', $scope)) {
|
||||
$userInfo['sub'] = (string)$user->getId();
|
||||
}
|
||||
if (in_array('email', $scope)) {
|
||||
$userInfo['email'] = $user->getEmail();
|
||||
}
|
||||
if (in_array('profile', $scope)) {
|
||||
if ($user->getUsername() !== null) {
|
||||
$userInfo['preferred_username'] = $user->getUsername();
|
||||
}
|
||||
$userInfo['name'] = $user->getFullName();
|
||||
$userInfo['nickname'] = $user->getNickname();
|
||||
$userInfo['phone_number'] = $user->getPhone();
|
||||
$userInfo['id_number'] = $user->getIdNumber();
|
||||
}
|
||||
return $userInfo;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use DateTime;
|
||||
use SokoWeb\Http\Request;
|
||||
use SokoWeb\Interfaces\Authorization\ISecured;
|
||||
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
||||
use SokoWeb\Interfaces\Request\IRequest;
|
||||
use SokoWeb\Interfaces\Response\IContent;
|
||||
use SokoWeb\Interfaces\Response\IRedirect;
|
||||
@@ -13,22 +13,26 @@ use SokoWeb\Response\HtmlContent;
|
||||
use SokoWeb\Response\JsonContent;
|
||||
use SokoWeb\Response\Redirect;
|
||||
use SokoWeb\Util\JwtParser;
|
||||
use RVR\Repository\UserRepository;
|
||||
|
||||
class UserController implements ISecured
|
||||
class UserController implements IAuthenticationRequired
|
||||
{
|
||||
private IRequest $request;
|
||||
|
||||
private PersistentDataManager $pdm;
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
public function __construct(IRequest $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->pdm = new PersistentDataManager();
|
||||
$this->userRepository = new UserRepository();
|
||||
}
|
||||
|
||||
public function authorize(): bool
|
||||
public function isAuthenticationRequired(): bool
|
||||
{
|
||||
return $this->request->user() !== null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getAccount(): IContent
|
||||
@@ -58,7 +62,7 @@ class UserController implements ISecured
|
||||
|
||||
$url = $oAuth->getDialogUrl(
|
||||
$state,
|
||||
$this->request->getBase() . '/' . \Container::$routeCollection->getRoute('account.googleAuthenticate-action')->generateLink(),
|
||||
$this->request->getBase() . \Container::$routeCollection->getRoute('account.googleAuthenticate-action')->generateLink(),
|
||||
$nonce,
|
||||
$user->getEmail()
|
||||
);
|
||||
@@ -80,7 +84,7 @@ class UserController implements ISecured
|
||||
$oAuth = new GoogleOAuth(new Request());
|
||||
$tokenData = $oAuth->getToken(
|
||||
$this->request->query('code'),
|
||||
$this->request->getBase() . '/' . \Container::$routeCollection->getRoute('account.googleAuthenticate-action')->generateLink()
|
||||
$this->request->getBase() . \Container::$routeCollection->getRoute('account.googleAuthenticate-action')->generateLink()
|
||||
);
|
||||
|
||||
if (!isset($tokenData['id_token'])) {
|
||||
@@ -126,8 +130,39 @@ class UserController implements ISecured
|
||||
return new JsonContent(['error' => ['errorText' => $error]]);
|
||||
}
|
||||
|
||||
if (strlen($this->request->post('password_new')) > 0) {
|
||||
if (strlen($this->request->post('password_new')) < 6) {
|
||||
$newEmail = $this->request->post('email');
|
||||
if ($newEmail !== $user->getEmail()) {
|
||||
if (!filter_var($newEmail, FILTER_VALIDATE_EMAIL)) {
|
||||
return new JsonContent(['error' => ['errorText' => 'Please provide a valid email address.']]);
|
||||
}
|
||||
|
||||
if ($this->userRepository->getByEmail($newEmail) !== null) {
|
||||
return new JsonContent(['error' => ['errorText' => 'The given email address belongs to another account.']]);
|
||||
}
|
||||
|
||||
$user->setEmail($newEmail);
|
||||
}
|
||||
|
||||
$newUsername = $this->request->post('username');
|
||||
if ($newUsername !== $user->getUsername()) {
|
||||
if (strlen($newUsername) > 0) {
|
||||
if (filter_var($newUsername, FILTER_VALIDATE_EMAIL)) {
|
||||
return new JsonContent(['error' => ['errorText' => 'Please select a username that is not a valid email address.']]);
|
||||
}
|
||||
|
||||
if ($this->userRepository->getByUsername($newUsername) !== null) {
|
||||
return new JsonContent(['error' => ['errorText' => 'The given username is already taken.']]);
|
||||
}
|
||||
|
||||
$user->setUsername($newUsername);
|
||||
} else {
|
||||
$user->setUsername(null);
|
||||
}
|
||||
}
|
||||
|
||||
$newPassword = $this->request->post('password_new');
|
||||
if (strlen($newPassword) > 0) {
|
||||
if (strlen($newPassword) < 6) {
|
||||
return new JsonContent([
|
||||
'error' => [
|
||||
'errorText' => 'The given new password is too short. Please choose a password that is at least 6 characters long!'
|
||||
@@ -135,7 +170,7 @@ class UserController implements ISecured
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->request->post('password_new') !== $this->request->post('password_new_confirm')) {
|
||||
if ($newPassword !== $this->request->post('password_new_confirm')) {
|
||||
return new JsonContent([
|
||||
'error' => [
|
||||
'errorText' => 'The given new passwords do not match.'
|
||||
@@ -143,9 +178,13 @@ class UserController implements ISecured
|
||||
]);
|
||||
}
|
||||
|
||||
$user->setPlainPassword($this->request->post('password_new'));
|
||||
$user->setPlainPassword($newPassword);
|
||||
}
|
||||
|
||||
$user->setNickname($this->request->post('nickname'));
|
||||
$user->setPhone($this->request->post('phone'));
|
||||
$user->setIdNumber($this->request->post('id_number'));
|
||||
|
||||
$this->pdm->saveToDb($user);
|
||||
|
||||
$this->request->session()->delete('authenticated_with_google_until');
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php namespace RVR\Controller;
|
||||
|
||||
use RVR\Repository\UserRepository;
|
||||
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
||||
use SokoWeb\Interfaces\Request\IRequest;
|
||||
use SokoWeb\Interfaces\Response\IContent;
|
||||
use SokoWeb\Response\JsonContent;
|
||||
|
||||
class UserSearchController implements IAuthenticationRequired
|
||||
{
|
||||
private IRequest $request;
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
public function __construct(IRequest $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->userRepository = new UserRepository();
|
||||
}
|
||||
|
||||
public function isAuthenticationRequired(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function searchUser(): IContent
|
||||
{
|
||||
$users = iterator_to_array($this->userRepository->searchByName($this->request->query('q')));
|
||||
usort($users, function($a, $b) {
|
||||
return strnatcmp($a->getDisplayName(), $b->getDisplayName());
|
||||
});
|
||||
|
||||
$results = [];
|
||||
foreach ($users as $user) {
|
||||
$results[] = ['value' => $user->getId(), 'label' => $user->getFullDisplayName()];
|
||||
}
|
||||
|
||||
return new JsonContent([
|
||||
'results' => $results
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php namespace RVR\PersistentData\Model;
|
||||
|
||||
use DateTime;
|
||||
use SokoWeb\PersistentData\Model\Model;
|
||||
|
||||
class Community extends Model
|
||||
{
|
||||
protected static string $table = 'communities';
|
||||
|
||||
protected static array $fields = ['name', 'currency', 'created'];
|
||||
|
||||
private string $name = '';
|
||||
|
||||
private string $currency = '';
|
||||
|
||||
private DateTime $created;
|
||||
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function setCurrency(string $currency): void
|
||||
{
|
||||
$this->currency = $currency;
|
||||
}
|
||||
|
||||
public function setCreatedDate(DateTime $created): void
|
||||
{
|
||||
$this->created = $created;
|
||||
}
|
||||
|
||||
public function setCreated(string $created): void
|
||||
{
|
||||
$this->created = new DateTime($created);
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getCurrency(): string
|
||||
{
|
||||
return $this->currency;
|
||||
}
|
||||
|
||||
public function getCreatedDate(): DateTime
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
public function getCreated(): string
|
||||
{
|
||||
return $this->created->format('Y-m-d H:i:s');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php namespace RVR\PersistentData\Model;
|
||||
|
||||
use SokoWeb\PersistentData\Model\Model;
|
||||
|
||||
class CommunityMember extends Model
|
||||
{
|
||||
protected static string $table = 'community_members';
|
||||
|
||||
protected static array $fields = ['community_id', 'user_id', 'owner'];
|
||||
|
||||
protected static array $relations = ['community' => Community::class, 'user' => User::class];
|
||||
|
||||
private ?Community $community = null;
|
||||
|
||||
private ?int $communityId = null;
|
||||
|
||||
private ?User $user = null;
|
||||
|
||||
private ?int $userId = null;
|
||||
|
||||
private bool $owner = false;
|
||||
|
||||
public function setCommunity(Community $community): void
|
||||
{
|
||||
$this->community = $community;
|
||||
}
|
||||
|
||||
public function setCommunityId(int $communityId): void
|
||||
{
|
||||
$this->communityId = $communityId;
|
||||
}
|
||||
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function setUserId(int $userId): void
|
||||
{
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
public function setOwner(bool $owner): void
|
||||
{
|
||||
$this->owner = $owner;
|
||||
}
|
||||
|
||||
public function getCommunity(): ?Community
|
||||
{
|
||||
return $this->community;
|
||||
}
|
||||
|
||||
public function getCommunityId(): ?int
|
||||
{
|
||||
return $this->communityId;
|
||||
}
|
||||
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function getUserId(): ?int
|
||||
{
|
||||
return $this->userId;
|
||||
}
|
||||
|
||||
public function getOwner(): bool
|
||||
{
|
||||
return $this->owner;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php namespace RVR\PersistentData\Model;
|
||||
|
||||
use DateTime;
|
||||
use SokoWeb\PersistentData\Model\Model;
|
||||
|
||||
class OAuthClient extends Model
|
||||
{
|
||||
protected static string $table = 'oauth_clients';
|
||||
|
||||
protected static array $fields = ['client_id', 'client_secret', 'redirect_uris', 'preapproved', 'created'];
|
||||
|
||||
private string $clientId = '';
|
||||
|
||||
private string $clientSecret = '';
|
||||
|
||||
private array $redirectUris = [];
|
||||
|
||||
private bool $preapproved = false;
|
||||
|
||||
private DateTime $created;
|
||||
|
||||
public function setClientId(string $clientId): void
|
||||
{
|
||||
$this->clientId = $clientId;
|
||||
}
|
||||
|
||||
public function setClientSecret(string $clientSecret): void
|
||||
{
|
||||
$this->clientSecret = $clientSecret;
|
||||
}
|
||||
|
||||
public function setRedirectUrisArray(array $redirectUris): void
|
||||
{
|
||||
$this->redirectUris = $redirectUris;
|
||||
}
|
||||
|
||||
public function setRedirectUris(string $redirectUris): void
|
||||
{
|
||||
$this->redirectUris = json_decode($redirectUris, true);
|
||||
}
|
||||
|
||||
public function setPreapproved(bool $preapproved): void
|
||||
{
|
||||
$this->preapproved = $preapproved;
|
||||
}
|
||||
|
||||
public function setCreatedDate(DateTime $created): void
|
||||
{
|
||||
$this->created = $created;
|
||||
}
|
||||
|
||||
public function setCreated(string $created): void
|
||||
{
|
||||
$this->created = new DateTime($created);
|
||||
}
|
||||
|
||||
public function getClientId(): string
|
||||
{
|
||||
return $this->clientId;
|
||||
}
|
||||
|
||||
public function getClientSecret(): string
|
||||
{
|
||||
return $this->clientSecret;
|
||||
}
|
||||
|
||||
public function getRedirectUrisArray(): array
|
||||
{
|
||||
return $this->redirectUris;
|
||||
}
|
||||
|
||||
public function getRedirectUris(): string
|
||||
{
|
||||
return json_encode($this->redirectUris);
|
||||
}
|
||||
|
||||
public function getPreapproved(): bool
|
||||
{
|
||||
return $this->preapproved;
|
||||
}
|
||||
|
||||
public function getCreatedDate(): DateTime
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
public function getCreated(): string
|
||||
{
|
||||
return $this->created->format('Y-m-d H:i:s');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php namespace RVR\PersistentData\Model;
|
||||
|
||||
use DateTime;
|
||||
use SokoWeb\PersistentData\Model\Model;
|
||||
|
||||
class OAuthToken extends Model
|
||||
{
|
||||
protected static string $table = 'oauth_tokens';
|
||||
|
||||
protected static array $fields = ['scope', 'nonce', 'user_id', 'code', 'access_token', 'created', 'expires'];
|
||||
|
||||
protected static array $relations = ['user' => User::class];
|
||||
|
||||
private static array $possibleScopeValues = ['openid', 'email', 'profile'];
|
||||
|
||||
private array $scope = [];
|
||||
|
||||
private string $nonce = '';
|
||||
|
||||
private ?User $user = null;
|
||||
|
||||
private ?int $userId = null;
|
||||
|
||||
private string $code = '';
|
||||
|
||||
private string $accessToken = '';
|
||||
|
||||
private DateTime $created;
|
||||
|
||||
private DateTime $expires;
|
||||
|
||||
public function setScopeArray(array $scope): void
|
||||
{
|
||||
$this->scope = array_intersect($scope, self::$possibleScopeValues);
|
||||
}
|
||||
|
||||
public function setScope(string $scope): void
|
||||
{
|
||||
$this->setScopeArray(explode(' ', $scope));
|
||||
}
|
||||
|
||||
public function setNonce(string $nonce): void
|
||||
{
|
||||
$this->nonce = $nonce;
|
||||
}
|
||||
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function setUserId(int $userId): void
|
||||
{
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
public function setCode(string $code): void
|
||||
{
|
||||
$this->code = $code;
|
||||
}
|
||||
|
||||
public function setAccessToken(string $accessToken): void
|
||||
{
|
||||
$this->accessToken = $accessToken;
|
||||
}
|
||||
|
||||
public function setCreatedDate(DateTime $created): void
|
||||
{
|
||||
$this->created = $created;
|
||||
}
|
||||
|
||||
public function setExpiresDate(DateTime $expires): void
|
||||
{
|
||||
$this->expires = $expires;
|
||||
}
|
||||
|
||||
public function setCreated(string $created): void
|
||||
{
|
||||
$this->created = new DateTime($created);
|
||||
}
|
||||
|
||||
public function setExpires(string $expires): void
|
||||
{
|
||||
$this->expires = new DateTime($expires);
|
||||
}
|
||||
|
||||
public function getScope(): string
|
||||
{
|
||||
return implode(' ', $this->scope);
|
||||
}
|
||||
|
||||
public function getScopeArray(): array
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
public function getNonce(): string
|
||||
{
|
||||
return $this->nonce;
|
||||
}
|
||||
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function getUserId(): ?int
|
||||
{
|
||||
return $this->userId;
|
||||
}
|
||||
|
||||
public function getCode(): string
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function getAccessToken(): string
|
||||
{
|
||||
return $this->accessToken;
|
||||
}
|
||||
|
||||
public function getCreatedDate(): DateTime
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
public function getCreated(): string
|
||||
{
|
||||
return $this->created->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
public function getExpiresDate(): DateTime
|
||||
{
|
||||
return $this->expires;
|
||||
}
|
||||
|
||||
public function getExpires(): string
|
||||
{
|
||||
return $this->expires->format('Y-m-d H:i:s');
|
||||
}
|
||||
}
|
||||
@@ -8,12 +8,14 @@ class User extends Model implements IUser
|
||||
{
|
||||
protected static string $table = 'users';
|
||||
|
||||
protected static array $fields = ['email', 'password', 'type', 'google_sub', 'created'];
|
||||
protected static array $fields = ['email', 'username', 'password', 'type', 'google_sub', 'created', 'full_name', 'nickname', 'phone', 'id_number'];
|
||||
|
||||
private static array $types = ['user', 'admin'];
|
||||
|
||||
private string $email = '';
|
||||
|
||||
private ?string $username = null;
|
||||
|
||||
private ?string $password = null;
|
||||
|
||||
private string $type = 'user';
|
||||
@@ -22,11 +24,24 @@ class User extends Model implements IUser
|
||||
|
||||
private DateTime $created;
|
||||
|
||||
private string $fullName = '';
|
||||
|
||||
private string $nickname = '';
|
||||
|
||||
private string $phone = '';
|
||||
|
||||
private string $idNumber = '';
|
||||
|
||||
public function setEmail(string $email): void
|
||||
{
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
public function setUsername(?string $username): void
|
||||
{
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
public function setPassword(?string $hashedPassword): void
|
||||
{
|
||||
$this->password = $hashedPassword;
|
||||
@@ -59,11 +74,36 @@ class User extends Model implements IUser
|
||||
$this->created = new DateTime($created);
|
||||
}
|
||||
|
||||
public function setFullName(string $fullName): void
|
||||
{
|
||||
$this->fullName = $fullName;
|
||||
}
|
||||
|
||||
public function setNickname(string $nickname): void
|
||||
{
|
||||
$this->nickname = $nickname;
|
||||
}
|
||||
|
||||
public function setPhone(string $phone): void
|
||||
{
|
||||
$this->phone = $phone;
|
||||
}
|
||||
|
||||
public function setIdNumber(string $idNumber): void
|
||||
{
|
||||
$this->idNumber = $idNumber;
|
||||
}
|
||||
|
||||
public function getEmail(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function getUsername(): ?string
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function getPassword(): ?string
|
||||
{
|
||||
return $this->password;
|
||||
@@ -89,6 +129,26 @@ class User extends Model implements IUser
|
||||
return $this->created->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
public function getFullName(): string
|
||||
{
|
||||
return $this->fullName;
|
||||
}
|
||||
|
||||
public function getNickname(): string
|
||||
{
|
||||
return $this->nickname;
|
||||
}
|
||||
|
||||
public function getPhone(): string
|
||||
{
|
||||
return $this->phone;
|
||||
}
|
||||
|
||||
public function getIdNumber(): string
|
||||
{
|
||||
return $this->idNumber;
|
||||
}
|
||||
|
||||
public function hasPermission(int $permission): bool
|
||||
{
|
||||
switch ($permission) {
|
||||
@@ -108,7 +168,12 @@ class User extends Model implements IUser
|
||||
|
||||
public function getDisplayName(): string
|
||||
{
|
||||
return $this->email;
|
||||
return $this->nickname ?: $this->fullName;
|
||||
}
|
||||
|
||||
public function getFullDisplayName(): string
|
||||
{
|
||||
return $this->nickname ? $this->nickname . ' (' . $this->fullName . ')' : $this->fullName;
|
||||
}
|
||||
|
||||
public function checkPassword(string $password): bool
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php namespace RVR\Repository;
|
||||
|
||||
use Generator;
|
||||
use RVR\PersistentData\Model\Community;
|
||||
use RVR\PersistentData\Model\CommunityMember;
|
||||
use RVR\PersistentData\Model\User;
|
||||
use SokoWeb\Database\Query\Select;
|
||||
use SokoWeb\PersistentData\PersistentDataManager;
|
||||
|
||||
class CommunityMemberRepository
|
||||
{
|
||||
private PersistentDataManager $pdm;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->pdm = new PersistentDataManager();
|
||||
}
|
||||
|
||||
public function getById(int $id): ?CommunityMember
|
||||
{
|
||||
return $this->pdm->selectFromDbById($id, CommunityMember::class);
|
||||
}
|
||||
|
||||
public function getAllByCommunity(Community $community, bool $useRelations = false): Generator
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('community_id', '=', $community->getId());
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, CommunityMember::class, $useRelations);
|
||||
}
|
||||
|
||||
public function getAllByUser(User $user, bool $useRelations = false): Generator
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('user_id', '=', $user->getId());
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, CommunityMember::class, $useRelations);
|
||||
}
|
||||
|
||||
public function getByCommunityAndUser(Community $community, User $user) : ?CommunityMember
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('community_id', '=', $community->getId());
|
||||
$select->where('user_id', '=', $user->getId());
|
||||
|
||||
return $this->pdm->selectFromDb($select, CommunityMember::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php namespace RVR\Repository;
|
||||
|
||||
use RVR\PersistentData\Model\Community;
|
||||
use SokoWeb\PersistentData\PersistentDataManager;
|
||||
|
||||
class CommunityRepository
|
||||
{
|
||||
private PersistentDataManager $pdm;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->pdm = new PersistentDataManager();
|
||||
}
|
||||
|
||||
public function getById(int $id): ?Community
|
||||
{
|
||||
return $this->pdm->selectFromDbById($id, Community::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php namespace RVR\Repository;
|
||||
|
||||
use SokoWeb\Database\Query\Select;
|
||||
use RVR\PersistentData\Model\OAuthClient;
|
||||
use SokoWeb\PersistentData\PersistentDataManager;
|
||||
|
||||
class OAuthClientRepository
|
||||
{
|
||||
private PersistentDataManager $pdm;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->pdm = new PersistentDataManager();
|
||||
}
|
||||
|
||||
public function getById(int $id): ?OAuthClient
|
||||
{
|
||||
return $this->pdm->selectFromDbById($id, OAuthClient::class);
|
||||
}
|
||||
|
||||
public function getByClientId(string $clientId): ?OAuthClient
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('client_id', '=', $clientId);
|
||||
|
||||
return $this->pdm->selectFromDb($select, OAuthClient::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php namespace RVR\Repository;
|
||||
|
||||
use DateTime;
|
||||
use Generator;
|
||||
use SokoWeb\Database\Query\Select;
|
||||
use RVR\PersistentData\Model\OAuthToken;
|
||||
use SokoWeb\PersistentData\PersistentDataManager;
|
||||
|
||||
class OAuthTokenRepository
|
||||
{
|
||||
private PersistentDataManager $pdm;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->pdm = new PersistentDataManager();
|
||||
}
|
||||
|
||||
public function getById(int $id): ?OAuthToken
|
||||
{
|
||||
return $this->pdm->selectFromDbById($id, OAuthToken::class);
|
||||
}
|
||||
|
||||
public function getByCode(string $code): ?OAuthToken
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('code', '=', $code);
|
||||
|
||||
return $this->pdm->selectFromDb($select, OAuthToken::class);
|
||||
}
|
||||
|
||||
public function getByAccessToken(string $accessToken): ?OAuthToken
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('access_token', '=', $accessToken);
|
||||
|
||||
return $this->pdm->selectFromDb($select, OAuthToken::class);
|
||||
}
|
||||
|
||||
public function getAllExpired(): Generator
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('expires', '<', (new DateTime())->format('Y-m-d H:i:s'));
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, OAuthToken::class);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php namespace RVR\Repository;
|
||||
|
||||
use Generator;
|
||||
use SokoWeb\Interfaces\Repository\IUserRepository;
|
||||
use SokoWeb\Database\Query\Select;
|
||||
use RVR\PersistentData\Model\User;
|
||||
@@ -27,6 +28,23 @@ class UserRepository implements IUserRepository
|
||||
return $this->pdm->selectFromDb($select, User::class);
|
||||
}
|
||||
|
||||
public function getByUsername(string $username): ?User
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('username', '=', $username);
|
||||
|
||||
return $this->pdm->selectFromDb($select, User::class);
|
||||
}
|
||||
|
||||
public function getByEmailOrUsername(string $emailOrUsername): ?User
|
||||
{
|
||||
if (filter_var($emailOrUsername, FILTER_VALIDATE_EMAIL)) {
|
||||
return $this->getByEmail($emailOrUsername);
|
||||
}
|
||||
|
||||
return $this->getByUsername($emailOrUsername);
|
||||
}
|
||||
|
||||
public function getByGoogleSub(string $sub): ?User
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
@@ -34,4 +52,14 @@ class UserRepository implements IUserRepository
|
||||
|
||||
return $this->pdm->selectFromDb($select, User::class);
|
||||
}
|
||||
|
||||
public function searchByName(string $name): Generator
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('full_name', 'LIKE', '%' . $name . '%');
|
||||
$select->orWhere('nickname', 'LIKE', '%' . $name . '%');
|
||||
$select->limit(10);
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, User::class);
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -5,11 +5,11 @@
|
||||
@section(main)
|
||||
<h2>Account</h2>
|
||||
<div class="box">
|
||||
<form id="accountForm" action="/account" method="post" data-observe-inputs="password_new,password_new_confirm">
|
||||
<form id="accountForm" action="<?= Container::$routeCollection->getRoute('account-action')->generateLink() ?>" method="post" data-reload-on-success="true" data-observe-inputs="email,username,password_new,password_new_confirm,nickname,phone,id_number">
|
||||
<?php if ($user['password'] !== null && $user['google_sub'] !== null): ?>
|
||||
<p class="justify small">Please confirm your identity with your password or with Google to modify your account.</p>
|
||||
<div class="inputWithButton">
|
||||
<input type="password" class="text name="password" placeholder="Current password" required minlength="6" autofocus><!--
|
||||
<input type="password" class="text" name="password" placeholder="Current password" required minlength="6" autofocus><!--
|
||||
--><button id="authenticateWithGoogleButton" class="yellow" type="button">Google</button>
|
||||
</div>
|
||||
<?php elseif ($user['password'] !== null): ?>
|
||||
@@ -23,10 +23,15 @@
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<hr>
|
||||
<?php /* TODO: disabled for the time being, email modification should be implemented */ ?>
|
||||
<input type="email" class="text big fullWidth" name="email" placeholder="Email address" value="<?= $user['email'] ?>" disabled>
|
||||
<input type="email" class="text big fullWidth" name="email" placeholder="Email address" value="<?= $user['email'] ?>">
|
||||
<input type="text" class="text big fullWidth marginTop" name="username" placeholder="Username" value="<?= $user['username'] ?>">
|
||||
<input type="password" class="text big fullWidth marginTop" name="password_new" placeholder="New password" minlength="6">
|
||||
<input type="password" class="text big fullWidth marginTop" name="password_new_confirm" placeholder="New password confirmation" minlength="6">
|
||||
<hr>
|
||||
<input type="text" class="text big fullWidth marginTop" name="full_name" placeholder="Full name" value="<?= $user['full_name'] ?>" disabled>
|
||||
<input type="text" class="text big fullWidth marginTop" name="nickname" placeholder="Nickname" value="<?= $user['nickname'] ?>">
|
||||
<input type="text" class="text big fullWidth marginTop" name="phone" placeholder="Phone" value="<?= $user['phone'] ?>">
|
||||
<input type="text" class="text big fullWidth marginTop" name="id_number" placeholder="ID number" value="<?= $user['id_number'] ?>">
|
||||
<p id="accountFormError" class="formError justify marginTop"></p>
|
||||
<div class="right marginTop">
|
||||
<button type="submit" name="submit" disabled>Save</button>
|
||||
@@ -34,3 +39,9 @@
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section(pageScript)
|
||||
<script>
|
||||
var googleAuthenticateUrl = '<?= Container::$routeCollection->getRoute('account.googleAuthenticate')->generateLink() ?>';
|
||||
</script>
|
||||
@endsection
|
||||
@@ -0,0 +1,50 @@
|
||||
@extends(templates/layout_normal)
|
||||
|
||||
@section(main)
|
||||
<h2><?= $community->getName() ?> <span class="small">[<a href="<?= Container::$routeCollection->getRoute('community-edit')->generateLink(['communityId' => $community->getId()]) ?>">edit</a>]</span></h2>
|
||||
|
||||
<div class="gridContainer marginTop">
|
||||
<div>
|
||||
<h3 class="marginBottom">Members</h3>
|
||||
<?php foreach ($members as $member): ?>
|
||||
<p><?= $member->getUser()->getDisplayName() ?></p>
|
||||
<?php endforeach; ?>
|
||||
<?php if ($editPermission): ?>
|
||||
<hr>
|
||||
<p><a href="<?= Container::$routeCollection->getRoute('community-members')->generateLink(['communityId' => $community->getId()]) ?>">Edit members</a></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="marginBottom">Currencies</h3>
|
||||
<p>Main currency: <b><?= $community->getCurrency() ?></b></p>
|
||||
<p>Further currencies: <b><?= implode(', ', $currencyNames) ?></b></p>
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="marginBottom">Upcoming events</h3>
|
||||
<?php if (count($upcomingEvents) > 0): ?>
|
||||
<?php foreach ($upcomingEvents as $event): ?>
|
||||
<!-- todo -->
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<p>There is no upcoming event.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="marginBottom">Finances</h3>
|
||||
<table class="fullWidth">
|
||||
<tr>
|
||||
<td>You owe</td>
|
||||
<td style="text-align: right; color: red;">0 <?= $community->getCurrency() ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>You're owed</td>
|
||||
<td style="text-align: right; color: green;">0 <?= $community->getCurrency() ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Your balance</td>
|
||||
<td style="text-align: right;">0 <?= $community->getCurrency() ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -0,0 +1,20 @@
|
||||
@extends(templates/layout_normal)
|
||||
|
||||
@section(main)
|
||||
<h2><?= isset($community) ? $community->getName() . ' - Edit' : 'New community' ?></h2>
|
||||
<div class="box">
|
||||
<?php
|
||||
$formAction = isset($community) ?
|
||||
Container::$routeCollection->getRoute('community-edit-action')->generateLink(['communityId' => $community->getId()]) :
|
||||
Container::$routeCollection->getRoute('community-new-action')->generateLink();
|
||||
?>
|
||||
<form id="communityForm" action="<?= $formAction ?>" method="post" data-redirect-on-success="true">
|
||||
<input type="text" class="text big fullWidth" name="name" placeholder="Name" value="<?= isset($community) ? $community->getName() : '' ?>" required>
|
||||
<input type="text" class="text big fullWidth marginTop" name="currency" value="<?= isset($community) ? $community->getCurrency() : '' ?>" placeholder="Default currency" maxlength="3" required>
|
||||
<p id="accountFormError" class="formError justify marginTop"></p>
|
||||
<div class="right marginTop">
|
||||
<button type="submit" name="submit"><?= isset($community) ? 'Save' : 'Create' ?></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -0,0 +1,42 @@
|
||||
@css(node_modules/choices.js/public/assets/styles/choices.min.css)
|
||||
@js(node_modules/choices.js/public/assets/scripts/choices.js)
|
||||
@js(js/communities/community_members.js)
|
||||
|
||||
@extends(templates/layout_normal)
|
||||
|
||||
@section(main)
|
||||
<h2><?= $community->getName() ?> - Edit members</h2>
|
||||
<div class="box">
|
||||
<table class="fullWidth">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 50%;"></th>
|
||||
<th style="width: 25%; text-align: center;">Owner</th>
|
||||
<th style="width: 25%;"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php foreach ($members as $member): ?>
|
||||
<?php $editable = $member->getUserId() !== Container::$request->user()->getUniqueId(); ?>
|
||||
<tr>
|
||||
<td><?= $member->getUser()->getDisplayName() ?></td>
|
||||
<td style="text-align: center;"><input type="checkbox" class="member_owner" data-id="<?= $member->getId() ?>" <?= $member->getOwner() ? 'checked' : '' ?> <?= !$editable ? 'disabled' : '' ?> /></td>
|
||||
<td style="text-align: right;"><button type="button" class="small red delete_member" data-id="<?= $member->getId() ?>" <?= !$editable ? 'disabled' : '' ?>>Delete</button></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<tr>
|
||||
<td><select type="text" id="new_member_user_id"></td>
|
||||
<td></td>
|
||||
<td style="text-align: right;"><button type="button" class="small" id="new_member_button" disabled>Add</button></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section(pageScript)
|
||||
<script>
|
||||
var searchUserUrl = '<?= Container::$routeCollection->getRoute('searchUser')->generateLink(['q' => 'QUERY']) ?>';
|
||||
var newMemberUrl = '<?= Container::$routeCollection->getRoute('community-members-new')->generateLink(['communityId' => $community->getId()]) ?>';
|
||||
var editMemberUrl = '<?= Container::$routeCollection->getRoute('community-members-edit')->generateLink(['communityId' => $community->getId()]) ?>';
|
||||
var deleteMemberUrl = '<?= Container::$routeCollection->getRoute('community-members-delete')->generateLink(['communityId' => $community->getId()]) ?>';
|
||||
</script>
|
||||
@endsection
|
||||
+1
-1
@@ -2,5 +2,5 @@
|
||||
|
||||
@section(main)
|
||||
<h2>404 | Page not found</h2>
|
||||
<p>The requested URL was not found on this server. <a href="/" title="<?= $_ENV['APP_NAME'] ?>">Back to start.</a></p>
|
||||
<p>The requested URL was not found on this server. <a href="<?= Container::$routeCollection->getRoute('home')->generateLink() ?>" title="<?= $_ENV['APP_NAME'] ?>">Back to start.</a></p>
|
||||
@endsection
|
||||
@@ -0,0 +1,28 @@
|
||||
@extends(templates/layout_normal)
|
||||
|
||||
@section(main)
|
||||
<div class="gridContainer">
|
||||
<div>
|
||||
<h3 class="marginBottom">Communities</h3>
|
||||
<?php if (count($communities) > 0): ?>
|
||||
<?php foreach ($communities as $community): ?>
|
||||
<p><a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a></p>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<p>You have no community.</p>
|
||||
<?php endif; ?>
|
||||
<hr>
|
||||
<p><a href="<?= Container::$routeCollection->getRoute('community-new')->generateLink() ?>">New community</a></p>
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="marginBottom">Upcoming events</h3>
|
||||
<?php if (count($upcomingEvents) > 0): ?>
|
||||
<?php foreach ($upcomingEvents as $event): ?>
|
||||
<!-- todo -->
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<p>There is no upcoming event.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -1,8 +0,0 @@
|
||||
@extends(templates/layout_normal)
|
||||
|
||||
@section(main)
|
||||
<h2>Login up with Google</h2>
|
||||
<div class="box">
|
||||
<p class="error justify">Authentication with Google failed. Please <a href="/login/google" title="Login with Google">try again</a>!</p>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -1,8 +1,8 @@
|
||||
@extends(templates/layout_normal)
|
||||
|
||||
@section(main)
|
||||
<h2><?= $_ENV['APP_NAME'] ?></h2>
|
||||
<h2>Login up with Google</h2>
|
||||
<div class="box">
|
||||
<p>This is the new <?= $_ENV['APP_NAME'] ?>.</p>
|
||||
<p class="error justify"><?= $error ?></p>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -3,17 +3,17 @@
|
||||
@section(main)
|
||||
<h2>Login</h2>
|
||||
<div class="box">
|
||||
<form id="loginForm" action="/login" method="post" data-redirect-on-success="/">
|
||||
<input type="email" class="text big fullWidth" name="email" placeholder="Email address" required autofocus>
|
||||
<form id="loginForm" action="<?= Container::$routeCollection->getRoute('login-action')->generateLink() ?>" method="post" data-redirect-on-success="<?= $redirectUrl ?>">
|
||||
<input type="text" class="text big fullWidth" name="email" placeholder="Email address / Username" required autofocus>
|
||||
<input type="password" class="text big fullWidth marginTop" name="password" placeholder="Password" required minlength="6">
|
||||
<p id="loginFormError" class="formError justify marginTop"></p>
|
||||
<div class="right marginTop">
|
||||
<button type="submit">Login</button>
|
||||
</div>
|
||||
<p class="center marginTop"><a href="/password/requestReset" title="Request password reset">Forgot your password?</a></p>
|
||||
<p class="center marginTop"><a href="<?= Container::$routeCollection->getRoute('password-requestReset')->generateLink() ?>" title="Request password reset">Forgot your password?</a></p>
|
||||
<hr>
|
||||
<div class="center">
|
||||
<a class="button yellow" href="/login/google" title="Login with Google">Login with Google</a>
|
||||
<a class="button yellow" href="<?= Container::$routeCollection->getRoute('login-google')->generateLink() ?>" title="Login with Google">Login with Google</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
@section(main)
|
||||
<h2>Request password reset</h2>
|
||||
<div class="box">
|
||||
<form id="passwordResetForm" action="/password/requestReset" method="post" data-redirect-on-success="/password/requestReset/success">
|
||||
<form id="passwordResetForm" action="<?= Container::$routeCollection->getRoute('password-requestReset-action')->generateLink() ?>" method="post" data-redirect-on-success="<?= Container::$routeCollection->getRoute('password-requestReset.success')->generateLink() ?>">
|
||||
<input type="email" class="text big fullWidth" name="email" placeholder="Email address" value="<?= isset($email) ? $email : '' ?>" required autofocus>
|
||||
<?php if (!empty($_ENV['RECAPTCHA_SITEKEY'])): ?>
|
||||
<div class="marginTop">
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<h2>Reset password</h2>
|
||||
<div class="box">
|
||||
<?php if ($success) : ?>
|
||||
<form id="resetPasswordForm" action="/password/reset/<?= $token ?>" method="post" data-redirect-on-success="/">
|
||||
<form id="resetPasswordForm" action="<?= Container::$routeCollection->getRoute('password-reset.action')->generateLink(['token' => $token]) ?>"" method="post" data-redirect-on-success="<?= $redirectUrl ?>">
|
||||
<input type="email" class="text big fullWidth" name="email" placeholder="Email address" value="<?= $email ?>" disabled>
|
||||
<input type="password" class="text big fullWidth marginTop" name="password" placeholder="Password" required minlength="6" autofocus>
|
||||
<input type="password" class="text big fullWidth marginTop" name="password_confirm" placeholder="Password confirmation" required minlength="6">
|
||||
@@ -14,7 +14,7 @@
|
||||
</div>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<p class="error justify">Confirming your identity failed. Please check the link you entered, or retry <a href="/password/requestReset" title="Request password reset">requesting password reset</a>!</p>
|
||||
<p class="error justify">Confirming your identity failed. Please check the link you entered, or retry <a href="<?= Container::$routeCollection->getRoute('password-requestReset')->generateLink() ?>" title="Request password reset">requesting password reset</a>!</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -0,0 +1,8 @@
|
||||
@extends(templates/layout_normal)
|
||||
|
||||
@section(main)
|
||||
<h2>OAuth error</h2>
|
||||
<div class="box">
|
||||
<p class="error justify"><?= $error ?></p>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -3,21 +3,21 @@
|
||||
@section(content)
|
||||
<header>
|
||||
<h1>
|
||||
<a href="/" title="<?= $_ENV['APP_NAME'] ?>">
|
||||
<a href="<?= Container::$routeCollection->getRoute('home')->generateLink() ?>" title="<?= $_ENV['APP_NAME'] ?>">
|
||||
<img class="inline" width="1em" height="1em" src="<?= $_ENV['STATIC_ROOT'] ?>/img/icon.svg?rev=<?= REVISION ?>" alt="<?= $_ENV['APP_NAME'] ?>"><!--
|
||||
--><span><?= $_ENV['APP_NAME'] ?></span>
|
||||
</a>
|
||||
</h1>
|
||||
<p>
|
||||
<?php if (Container::$request->user()) : ?>
|
||||
<span><a href="/account" title="Account">
|
||||
<span><a href="<?= Container::$routeCollection->getRoute('account')->generateLink() ?>" title="Account">
|
||||
<?php /* Copyright (c) 2019 The Bootstrap Authors. License can be found in 'USED_SOFTWARE' in section 'Bootstrap Icons'. */ ?>
|
||||
<svg class="inline" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" d="M3 14s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1H3zm5-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"/>
|
||||
</svg><!--
|
||||
--><?= Container::$request->user()->getDisplayName() ?><!--
|
||||
--></a></span><!--
|
||||
--><span><a href="/logout" title="Logout">Logout</a></span>
|
||||
--><span><a href="<?= Container::$routeCollection->getRoute('logout')->generateLink() ?>" title="Logout">Logout</a></span>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
</header>
|
||||
@@ -25,8 +25,8 @@
|
||||
@yields('main')
|
||||
</main>
|
||||
<footer>
|
||||
<p><?= round($__debug_runtime, 0) ?> ms</p>
|
||||
<p><span class="bold"><?= $_ENV['APP_NAME'] ?></span> <?= str_replace('Release_', '', VERSION) ?></p><!--
|
||||
<p><?= round($__debug_runtime, 0) ?> ms</p><!--
|
||||
--><p><span class="bold"><?= $_ENV['APP_NAME'] ?></span> <?= str_replace('Release_', '', VERSION) ?></p><!--
|
||||
--><p>© The RVR Contributors <?= (new DateTime(REVISION_DATE))->format('Y') ?></p>
|
||||
</footer>
|
||||
@endsection
|
||||
@@ -1,22 +0,0 @@
|
||||
@css(test1.css)
|
||||
@js(test1.js)
|
||||
@js(test2_<?= $some['expression'] ?>)
|
||||
|
||||
@extra
|
||||
<?php phpinfo() ?>
|
||||
@endextra
|
||||
|
||||
@extends(parent)
|
||||
|
||||
@section(section1)
|
||||
<div>Test HTML with @extends - section 1</div>
|
||||
@endsection
|
||||
|
||||
@section(section2)
|
||||
<div>Test HTML with @extends - section 2</div>
|
||||
@endsection
|
||||
|
||||
@extra
|
||||
<?php $a = 'test_string' ?>
|
||||
EXTRA
|
||||
@endextra
|
||||
@@ -1,5 +0,0 @@
|
||||
@extends(parent1)
|
||||
|
||||
@extends(parent2)
|
||||
|
||||
<div>Test HTML with multiple @extends</div>
|
||||
@@ -1,6 +0,0 @@
|
||||
@extends(parent)
|
||||
|
||||
@section(section1)
|
||||
@section(section2)
|
||||
|
||||
<div>Test HTML with opening @section before previous closed</div>
|
||||
@@ -1,4 +0,0 @@
|
||||
@extends(parent)
|
||||
|
||||
<div>Test HTML with @endsection when no section is open</div>
|
||||
@endsection
|
||||
@@ -1,3 +0,0 @@
|
||||
@section(section1)
|
||||
|
||||
<div>Test HTML with @section but without @extends</div>
|
||||
@@ -1,4 +0,0 @@
|
||||
@css(test.css)
|
||||
@js(test.js)
|
||||
@js(test_<?= $some['expression'] ?>)
|
||||
<div>Test HTML with @css and @js</div>
|
||||
@@ -1,5 +0,0 @@
|
||||
@extends(parent)
|
||||
|
||||
@section(section1)
|
||||
<div>Test HTML with @extends</div>
|
||||
@endsection
|
||||
@@ -1 +0,0 @@
|
||||
<div>Test HTML without @extends</div>
|
||||
@@ -1,5 +1,19 @@
|
||||
<?php
|
||||
|
||||
use Container;
|
||||
use SokoWeb\Response\HttpResponse;
|
||||
use SokoWeb\Routing\RouteCollection;
|
||||
use SokoWeb\Session\DatabaseSessionHandler;
|
||||
use SokoWeb\Request\Request;
|
||||
use RVR\Controller\HomeController;
|
||||
use RVR\Controller\LoginController;
|
||||
use RVR\Controller\OAuthAuthController;
|
||||
use RVR\Controller\OAuthController;
|
||||
use RVR\Controller\UserController;
|
||||
use RVR\Controller\UserSearchController;
|
||||
use RVR\Controller\CommunityController;
|
||||
use RVR\Repository\UserRepository;
|
||||
|
||||
require 'app.php';
|
||||
|
||||
if (!empty($_ENV['DEV'])) {
|
||||
@@ -10,32 +24,53 @@ if (!empty($_ENV['DEV'])) {
|
||||
ini_set('display_errors', '0');
|
||||
}
|
||||
|
||||
Container::$routeCollection = new SokoWeb\Routing\RouteCollection();
|
||||
Container::$routeCollection = new RouteCollection();
|
||||
|
||||
Container::$routeCollection->get('index', '', [RVR\Controller\HomeController::class, 'getIndex']);
|
||||
Container::$routeCollection->get('startSession', 'startSession.json', [RVR\Controller\HomeController::class, 'startSession']);
|
||||
Container::$routeCollection->group('login', function (SokoWeb\Routing\RouteCollection $routeCollection) {
|
||||
$routeCollection->get('login', '', [RVR\Controller\LoginController::class, 'getLoginForm']);
|
||||
$routeCollection->post('login-action', '', [RVR\Controller\LoginController::class, 'login']);
|
||||
$routeCollection->get('login-google', 'google', [RVR\Controller\LoginController::class, 'getGoogleLoginRedirect']);
|
||||
$routeCollection->get('login-google-action', 'google/code', [RVR\Controller\LoginController::class, 'loginWithGoogle']);
|
||||
Container::$routeCollection->get('home', '', [HomeController::class, 'getHome']);
|
||||
Container::$routeCollection->get('startSession', 'startSession.json', [HomeController::class, 'startSession']);
|
||||
Container::$routeCollection->group('login', function (RouteCollection $routeCollection) {
|
||||
$routeCollection->get('login', '', [LoginController::class, 'getLoginForm']);
|
||||
$routeCollection->post('login-action', '', [LoginController::class, 'login']);
|
||||
$routeCollection->get('login-google', 'google', [LoginController::class, 'getGoogleLoginRedirect']);
|
||||
$routeCollection->get('login-google-action', 'google/code', [LoginController::class, 'loginWithGoogle']);
|
||||
});
|
||||
Container::$routeCollection->group('password', function (SokoWeb\Routing\RouteCollection $routeCollection) {
|
||||
$routeCollection->get('password-requestReset', 'requestReset', [RVR\Controller\LoginController::class, 'getRequestPasswordResetForm']);
|
||||
$routeCollection->post('password-requestReset-action', 'requestReset', [RVR\Controller\LoginController::class, 'requestPasswordReset']);
|
||||
$routeCollection->get('password-requestReset.success', 'requestReset/success', [RVR\Controller\LoginController::class, 'getRequestPasswordResetSuccess']);
|
||||
$routeCollection->get('password-reset', 'reset/{token}', [RVR\Controller\LoginController::class, 'getResetPasswordForm']);
|
||||
$routeCollection->post('password-reset.action', 'reset/{token}', [RVR\Controller\LoginController::class, 'resetPassword']);
|
||||
Container::$routeCollection->group('oauth', function (RouteCollection $routeCollection) {
|
||||
$routeCollection->get('oauth-auth', 'auth', [OAuthAuthController::class, 'auth']);
|
||||
$routeCollection->post('oauth-token', 'token', [OAuthController::class, 'getToken']);
|
||||
$routeCollection->get('oauth-userinfo', 'userinfo', [OAuthController::class, 'getUserInfo']);
|
||||
$routeCollection->get('oauth-config', '.well-known/openid-configuration', [OAuthController::class, 'getConfig']);
|
||||
$routeCollection->get('oauth-certs', 'certs', [OAuthController::class, 'getCerts']);
|
||||
});
|
||||
Container::$routeCollection->group('password', function (RouteCollection $routeCollection) {
|
||||
$routeCollection->get('password-requestReset', 'requestReset', [LoginController::class, 'getRequestPasswordResetForm']);
|
||||
$routeCollection->post('password-requestReset-action', 'requestReset', [LoginController::class, 'requestPasswordReset']);
|
||||
$routeCollection->get('password-requestReset.success', 'requestReset/success', [LoginController::class, 'getRequestPasswordResetSuccess']);
|
||||
$routeCollection->get('password-reset', 'reset/{token}', [LoginController::class, 'getResetPasswordForm']);
|
||||
$routeCollection->post('password-reset.action', 'reset/{token}', [LoginController::class, 'resetPassword']);
|
||||
});
|
||||
Container::$routeCollection->get('logout', 'logout', [LoginController::class, 'logout']);
|
||||
Container::$routeCollection->group('account', function (RouteCollection $routeCollection) {
|
||||
$routeCollection->get('account', '', [UserController::class, 'getAccount']);
|
||||
$routeCollection->post('account-action', '', [UserController::class, 'saveAccount']);
|
||||
$routeCollection->get('account.googleAuthenticate', 'googleAuthenticate', [UserController::class, 'getGoogleAuthenticateRedirect']);
|
||||
$routeCollection->get('account.googleAuthenticate-action', 'googleAuthenticate/code', [UserController::class, 'authenticateWithGoogle']);
|
||||
});
|
||||
Container::$routeCollection->get('searchUser', 'searchUser', [UserSearchController::class, 'searchUser']);
|
||||
Container::$routeCollection->group('communities', function (RouteCollection $routeCollection) {
|
||||
$routeCollection->get('community-new', 'new', [CommunityController::class, 'getCommunityNew']);
|
||||
$routeCollection->post('community-new-action', 'new', [CommunityController::class, 'saveCommunity']);
|
||||
$routeCollection->group('{communityId}', function (RouteCollection $routeCollection) {
|
||||
$routeCollection->get('community', '', [CommunityController::class, 'getCommunityHome']);
|
||||
$routeCollection->get('community-edit', 'edit', [CommunityController::class, 'getCommunityEdit']);
|
||||
$routeCollection->post('community-edit-action', 'edit', [CommunityController::class, 'saveCommunity']);
|
||||
$routeCollection->get('community-members', 'members', [CommunityController::class, 'getMembersEdit']);
|
||||
$routeCollection->post('community-members-new', 'newMember', [CommunityController::class, 'newMember']);
|
||||
$routeCollection->post('community-members-edit', 'editMember', [CommunityController::class, 'editMember']);
|
||||
$routeCollection->post('community-members-delete', 'deleteMember', [CommunityController::class, 'deleteMember']);
|
||||
});
|
||||
Container::$routeCollection->get('logout', 'logout', [RVR\Controller\LoginController::class, 'logout']);
|
||||
Container::$routeCollection->group('account', function (SokoWeb\Routing\RouteCollection $routeCollection) {
|
||||
$routeCollection->get('account', '', [RVR\Controller\UserController::class, 'getAccount']);
|
||||
$routeCollection->post('account-action', '', [RVR\Controller\UserController::class, 'saveAccount']);
|
||||
$routeCollection->get('account.googleAuthenticate', 'googleAuthenticate', [RVR\Controller\UserController::class, 'getGoogleAuthenticateRedirect']);
|
||||
$routeCollection->get('account.googleAuthenticate-action', 'googleAuthenticate/code', [RVR\Controller\UserController::class, 'authenticateWithGoogle']);
|
||||
});
|
||||
|
||||
Container::$sessionHandler = new SokoWeb\Session\DatabaseSessionHandler();
|
||||
Container::$sessionHandler = new DatabaseSessionHandler();
|
||||
|
||||
session_set_save_handler(Container::$sessionHandler, true);
|
||||
session_start([
|
||||
@@ -56,19 +91,32 @@ if (isset($_COOKIE[session_name()])) {
|
||||
]);
|
||||
}
|
||||
|
||||
// this is needed to handle old type of session IDs
|
||||
if (!Container::$sessionHandler->validateId(session_id())) {
|
||||
session_regenerate_id(true);
|
||||
}
|
||||
|
||||
Container::$request = new SokoWeb\Request\Request(
|
||||
Container::$request = new Request(
|
||||
$_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'],
|
||||
$_GET,
|
||||
$_POST,
|
||||
getallheaders(),
|
||||
$_SESSION,
|
||||
new RVR\Repository\UserRepository()
|
||||
new UserRepository()
|
||||
);
|
||||
|
||||
if (!Container::$request->session()->has('anti_csrf_token')) {
|
||||
Container::$request->session()->set('anti_csrf_token', bin2hex(random_bytes(16)));
|
||||
}
|
||||
|
||||
$appConfig = [
|
||||
'antiCsrfTokenName' => 'anti_csrf_token',
|
||||
'antiCsrfTokenErrorResponse' => ['error' => 'no_valid_anti_csrf_token'],
|
||||
'antiCsrfTokenExceptions' => ['oauth/token'],
|
||||
'loginRouteId' => 'login',
|
||||
'error404View' => 'error/404'
|
||||
];
|
||||
|
||||
$httpReponse = new HttpResponse(
|
||||
Container::$request,
|
||||
Container::$routeCollection,
|
||||
$appConfig,
|
||||
$_SERVER['REQUEST_METHOD'],
|
||||
$_SERVER['REQUEST_URI']
|
||||
);
|
||||
$httpReponse->render();
|
||||
Reference in new issue
Block a user