Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Finishes #213
  • Loading branch information
NaysKutzu committed Feb 9, 2025
1 parent e720e60 commit 5c33291
Show file tree
Hide file tree
Showing 21 changed files with 1,230 additions and 608 deletions.
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Build Frontend",
"type": "node-terminal",
"command": "php mythicalclient frontend:build",
"request": "launch"

},
{
"name": "Watch Backend",
"type": "node-terminal",
"command": "php mythicalclient backend:watch",
"request": "launch"
},
{
"name": "Lint Backend",
"type": "node-terminal",
"command": "php mythicalclient backend:lint",
"request": "launch"
}
]
}
5 changes: 2 additions & 3 deletions backend/app/Api/System/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@
ConfigInterface::COMPANY_COUNTRY => $config->getSetting(ConfigInterface::COMPANY_COUNTRY, 'MythicalCountry'),
ConfigInterface::COMPANY_VAT => $config->getSetting(ConfigInterface::COMPANY_VAT, '1234567890'),

ConfigInterface::ENABLE_PAYPAL => $config->getSetting(ConfigInterface::ENABLE_PAYPAL,'false'),
ConfigInterface::ENABLE_STRIPE => $config->getSetting(ConfigInterface::ENABLE_STRIPE,'false'),
ConfigInterface::ENABLE_PAYPAL => $config->getSetting(ConfigInterface::ENABLE_PAYPAL, 'false'),
ConfigInterface::ENABLE_STRIPE => $config->getSetting(ConfigInterface::ENABLE_STRIPE, 'false'),

ConfigInterface::PAYPAL_CLIENT_ID => $config->getSetting(ConfigInterface::PAYPAL_CLIENT_ID, ''),
ConfigInterface::PAYPAL_WEBHOOK_ID => $config->getSetting(ConfigInterface::PAYPAL_WEBHOOK_ID, ''),
ConfigInterface::PAYPAL_IS_SANDBOX => $config->getSetting(ConfigInterface::PAYPAL_IS_SANDBOX, 'false'),

ConfigInterface::STRIPE_PUBLISHABLE_KEY => $config->getSetting(ConfigInterface::STRIPE_PUBLISHABLE_KEY, ''),
Expand Down
118 changes: 59 additions & 59 deletions backend/app/Api/User/Auth/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,72 +20,72 @@
use MythicalClient\CloudFlare\CloudFlareRealIP;

$router->add('/api/user/auth/login', function (): void {
$appInstance = App::getInstance(true);
$config = $appInstance->getConfig();
$appInstance = App::getInstance(true);
$config = $appInstance->getConfig();

$appInstance->allowOnlyPOST();
$appInstance->allowOnlyPOST();

/**
* Check if the required fields are set.
*
* @var string
*/
if (!isset($_POST['login']) || $_POST['login'] == '') {
$appInstance->BadRequest('Bad Request', ['error_code' => 'MISSING_LOGIN']);
}
/**
* Check if the required fields are set.
*
* @var string
*/
if (!isset($_POST['login']) || $_POST['login'] == '') {
$appInstance->BadRequest('Bad Request', ['error_code' => 'MISSING_LOGIN']);
}

if (!isset($_POST['password']) || $_POST['password'] == '') {
$appInstance->BadRequest('Bad Request', ['error_code' => 'MISSING_PASSWORD']);
}
if (!isset($_POST['password']) || $_POST['password'] == '') {
$appInstance->BadRequest('Bad Request', ['error_code' => 'MISSING_PASSWORD']);
}

/**
* Process the turnstile response.
*
* IF the turnstile is enabled
*/
if ($appInstance->getConfig()->getSetting(ConfigInterface::TURNSTILE_ENABLED, 'false') == 'true') {
if (!isset($_POST['turnstileResponse']) || $_POST['turnstileResponse'] == '') {
$appInstance->BadRequest('Bad Request', ['error_code' => 'TURNSTILE_FAILED']);
}
$cfTurnstileResponse = $_POST['turnstileResponse'];
if (!Turnstile::validate($cfTurnstileResponse, CloudFlareRealIP::getRealIP(), $config->getSetting(ConfigInterface::TURNSTILE_KEY_PRIV, 'XXXX'))) {
$appInstance->BadRequest('Invalid TurnStile Key', ['error_code' => 'TURNSTILE_FAILED']);
}
}
$login = $_POST['login'];
$password = $_POST['password'];
/**
* Process the turnstile response.
*
* IF the turnstile is enabled
*/
if ($appInstance->getConfig()->getSetting(ConfigInterface::TURNSTILE_ENABLED, 'false') == 'true') {
if (!isset($_POST['turnstileResponse']) || $_POST['turnstileResponse'] == '') {
$appInstance->BadRequest('Bad Request', ['error_code' => 'TURNSTILE_FAILED']);
}
$cfTurnstileResponse = $_POST['turnstileResponse'];
if (!Turnstile::validate($cfTurnstileResponse, CloudFlareRealIP::getRealIP(), $config->getSetting(ConfigInterface::TURNSTILE_KEY_PRIV, 'XXXX'))) {
$appInstance->BadRequest('Invalid TurnStile Key', ['error_code' => 'TURNSTILE_FAILED']);
}
}
$login = $_POST['login'];
$password = $_POST['password'];

$login = User::login($login, $password);
if (APP_DEBUG) {
// Set the cookie to expire in 1 year if the app is in debug mode
setcookie('user_token', $login, time() + 3600 * 31 * 360, '/');
$login = User::login($login, $password);
if (APP_DEBUG) {
// Set the cookie to expire in 1 year if the app is in debug mode
setcookie('user_token', $login, time() + 3600 * 31 * 360, '/');

} else {
setcookie('user_token', $login, time() + 3600, '/');
}
if ($login == 'false') {
$appInstance->BadRequest('Invalid login credentials', ['error_code' => 'INVALID_CREDENTIALS']);
} else {
if (User::getInfo($login, UserColumns::VERIFIED, false) == 'false') {
if (Mail::isEnabled() == true) {
User::logout();
$appInstance->BadRequest('Account not verified', ['error_code' => 'ACCOUNT_NOT_VERIFIED']);
}
}
} else {
setcookie('user_token', $login, time() + 3600, '/');
}
if ($login == 'false') {
$appInstance->BadRequest('Invalid login credentials', ['error_code' => 'INVALID_CREDENTIALS']);
} else {
if (User::getInfo($login, UserColumns::VERIFIED, false) == 'false') {
if (Mail::isEnabled() == true) {
User::logout();
$appInstance->BadRequest('Account not verified', ['error_code' => 'ACCOUNT_NOT_VERIFIED']);
}
}

if (User::getInfo($login, UserColumns::BANNED, false) != 'NO') {
User::logout();
$appInstance->BadRequest('Account is banned', ['error_code' => 'ACCOUNT_BANNED']);
}
if (User::getInfo($login, UserColumns::BANNED, false) != 'NO') {
User::logout();
$appInstance->BadRequest('Account is banned', ['error_code' => 'ACCOUNT_BANNED']);
}

if (User::getInfo($login, UserColumns::DELETED, false) == 'true') {
User::logout();
$appInstance->BadRequest('Account is deleted', ['error_code' => 'ACCOUNT_DELETED']);
}
if (User::getInfo($login, UserColumns::DELETED, false) == 'true') {
User::logout();
$appInstance->BadRequest('Account is deleted', ['error_code' => 'ACCOUNT_DELETED']);
}

if (User::getInfo($login, UserColumns::TWO_FA_ENABLED, false) == 'true') {
User::updateInfo($login, UserColumns::TWO_FA_BLOCKED, 'true', false);
}
$appInstance->OK('Successfully logged in', []);
}
if (User::getInfo($login, UserColumns::TWO_FA_ENABLED, false) == 'true') {
User::updateInfo($login, UserColumns::TWO_FA_BLOCKED, 'true', false);
}
$appInstance->OK('Successfully logged in', []);
}
});
24 changes: 13 additions & 11 deletions backend/app/Api/User/Services/AddFunds.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<?php

/*
* This file is part of MythicalClient.
* Please view the LICENSE file that was distributed with this source code.
*
* # MythicalSystems License v2.0
*
* ## Copyright (c) 2021–2025 MythicalSystems and Cassian Gherman
*
* Breaking any of the following rules will result in a permanent ban from the MythicalSystems community and all of its services.
*/

use MythicalClient\App;
use MythicalClient\Plugins\PluginDB;
use MythicalClient\Chat\User\Session;
use MythicalClient\Chat\Orders\Orders;
use MythicalClient\Chat\Services\Services;
use MythicalClient\Chat\columns\UserColumns;
use MythicalClient\Chat\Orders\OrdersConfig;
use MythicalClient\Chat\Orders\OrdersInvoices;
use MythicalClient\Chat\Services\ServiceCategories;
use MythicalClient\Plugins\Providers\PluginProviderHelper;


$router->add('/api/user/addfunds', function () {
global $pluginManager;
global $pluginManager;
App::init();
$appInstance = App::getInstance(true);
$appInstance->allowOnlyPOST();
$session = new Session($appInstance);


});
56 changes: 53 additions & 3 deletions backend/app/Api/WebHooks/PayPal.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,56 @@
<?php

$router->add('/api/webhooks/paypal', function () {
use MythicalClient\App;
use MythicalClient\Chat\columns\UserColumns;
use MythicalClient\Chat\User\Session;


});
/*
* This file is part of MythicalClient.
* Please view the LICENSE file that was distributed with this source code.
*
* # MythicalSystems License v2.0
*
* ## Copyright (c) 2021–2025 MythicalSystems and Cassian Gherman
*
* Breaking any of the following rules will result in a permanent ban from the MythicalSystems community and all of its services.
*/


// Route handlers
$router->post('/api/webhooks/paypal', function() {
$paypal = new MythicalClient\Gateways\PayPal();
$paypal->handleIPN();
});

$router->get('/api/paypal/process', function() {
App::init();
$app = App::getInstance(true);
$session = new Session($app);

try {
if (!isset($_GET['coins']) || empty($_GET['coins'])) {
throw new \InvalidArgumentException('Missing coins parameter');
}

$paypal = new MythicalClient\Gateways\PayPal();
$redirectUrl = $paypal->createPayment(
(float)$_GET['coins'],
$session->getInfo(UserColumns::UUID, false)
);

header("Location: $redirectUrl");
exit;
} catch (\Throwable $e) {
$app->getLogger()->error('PayPal process error: ' . $e->getMessage());
header('Location: /?error=payment_failed&message=' . $e->getMessage());
exit;
}
});

$router->add('/api/paypal/finish', function() {
App::init();
$app = App::getInstance(true);

header('Location: /dashboard');
exit;
});
Loading

0 comments on commit 5c33291

Please sign in to comment.