Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Rework auth system
-> Added billing info
  • Loading branch information
NaysKutzu committed Nov 29, 2024
1 parent b770288 commit 64fa24a
Show file tree
Hide file tree
Showing 23 changed files with 581 additions and 129 deletions.
53 changes: 51 additions & 2 deletions .vscode/vscode.code-snippets
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
{

}
"Change Comment": {
"prefix": "changecomment",
"body": [
"/* ---------------------------",
" * Author: $1 Date: ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}",
" * ",
" * Changes: ",
" * - $2",
" * ",
" * ",
" * ---------------------------*/"
],
"description": "Snippet for a change comment with author and date"
},
"S_GetTranslation": {
"prefix": "S_GetTranslation",
"scope": "vue,ts,tsx,js,jsx,html",
"body": ["Translation.getTranslation('$1')"],
"description": "Get a translation from i18n!"
},
"S_GetTranslationTemplate": {
"prefix": "S_GetTranslationTemplate",
"scope": "vue,ts,tsx,js,jsx,html",
"body": ["{{ Translation.getTranslation('$1') }}"],
"description": "Get a translation from i18n!"
},
"S_GetSetting": {
"prefix": "S_GetSetting",
"scope": "vue,ts,tsx,js,jsx,html",
"body": ["Settings.getSetting('$1')"],
"description": "Get a setting from settings!"
},
"S_GetSettingVue": {
"prefix": "S_GetSetting",
"scope": "vue,ts,tsx,js,jsx,html",
"body": ["{{ Settings.getSetting('$1') }}"],
"description": "Get a setting from settings!"
},
"S_GetSessionInfo": {
"prefix": "S_GetSessionInfo",
"scope": "vue,ts,tsx,js,jsx,html",
"body": ["Session.getInfo('$1')"],
"description": "Get a session info like username or other user details!"
},
"S_GetSessionInfoVue": {
"prefix": "S_GetSessionInfo",
"scope": "vue,ts,tsx,js,jsx,html",
"body": ["{{ Session.getInfo('$1') }}"],
"description": "Get a session info like username or other user details!"
}
}
1 change: 1 addition & 0 deletions backend/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"settings.import": "../.vscode/settings.json",
"cSpell.words": [
"Cassian",
"doctypehtml",
Expand Down
25 changes: 12 additions & 13 deletions backend/app/Api/User/Auth/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,28 @@
$password = $_POST['password'];

$login = User::login($login, $password);
$token = $_COOKIE['user_token'];
if ($login) {
if ($token == "") {
$appInstance->BadRequest('Something behind went wrong!', ['error_code' => 'LOGIC_ERROR']);
}
if (User::getInfo($_COOKIE['user_token'], UserColumns::VERIFIED, false) == 'false') {
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) {
setcookie('user_token', '', time() - 123600, '/');
User::logout();
$appInstance->BadRequest('Account not verified', ['error_code' => 'ACCOUNT_NOT_VERIFIED']);
}
}

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

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

$appInstance->OK('Successfully logged in', []);
} else {
$appInstance->BadRequest('Invalid login credentials', ['error_code' => 'INVALID_CREDENTIALS']);
}
});
36 changes: 29 additions & 7 deletions backend/app/Api/User/Auth/Logout.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
<?php

/*
* This file is part of MythicalClient.
* Please view the LICENSE file that was distributed with this source code.
*
* MIT License
*
* (c) MythicalSystems <mythicalsystems.xyz> - All rights reserved
* (c) NaysKutzu <nayskutzu.xyz> - All rights reserved
* (c) Cassian Gherman <nayskutzu.xyz> - All rights reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

use MythicalClient\App;
use MythicalClient\Chat\User;
use MythicalClient\Mail\Mail;
use MythicalSystems\CloudFlare\Turnstile;
use MythicalClient\Config\ConfigInterface;
use MythicalSystems\CloudFlare\CloudFlare;
use MythicalClient\Chat\columns\UserColumns;

$router->get('/api/user/auth/logout', function (): void {
echo '<script>
Expand All @@ -27,4 +49,4 @@
App::getInstance(true)->getLogger()->error('Failed to logout user' . $e->getMessage());
header('location: /auth/login?href=api');
}
});
});
66 changes: 63 additions & 3 deletions backend/app/Api/User/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
*/

use MythicalClient\App;
use MythicalClient\Chat\Billing;
use MythicalClient\Chat\User;
use MythicalClient\Chat\Roles;
use MythicalClient\Chat\columns\UserColumns;
use MythicalClient\Chat\Billing;
use MythicalClient\Chat\Session;
use MythicalClient\Chat\columns\UserColumns;

$router->post('/api/user/session', function (): void {
App::init();
Expand All @@ -44,7 +44,67 @@
$appInstance->allowOnlyPOST();
$session = new Session($appInstance);

});

$router->post('/api/user/session/billing/update', function (): void {
App::init();
$appInstance = App::getInstance(true);
$config = $appInstance->getConfig();

$appInstance->allowOnlyPOST();
$session = new Session($appInstance);

try {
if (!isset($_POST['company_name']) && $_POST['company_name'] == '') {
$appInstance->BadRequest('Company name is missing!', ['error_code' => 'COMPANY_NAME_MISSING']);
}
$companyName = $_POST['company_name'];
if (!isset($_POST['vat_number']) && $_POST['vat_number'] == '') {
$appInstance->BadRequest('VAT Number is missing!', ['error_code' => 'VAT_NUMBER_MISSING']);
}
$vatNumber = $_POST['vat_number'];
if (!isset($_POST['address1']) && $_POST['address1'] == '') {
$appInstance->BadRequest('Address 1 is missing', ['error_code' => 'ADDRESS1_MISSING']);
}
$address1 = $_POST['address1'];
if (!isset($_POST['address2']) && $_POST['address2'] == '') {
$appInstance->BadRequest('Address 2 is missing', ['error_code' => 'ADDRESS2_MISSING']);
}
$address2 = $_POST['address2'];
if (!isset($_POST['city']) && $_POST['city'] == '') {
$appInstance->BadRequest('City is missing', ['error_code' => 'CITY_MISSING']);
}
$city = $_POST['city'];
if (!isset($_POST['country']) && $_POST['country'] == '') {
$appInstance->BadRequest('Country is missing', ['error_code' => 'COUNTRY_MISSING']);
}
$country = $_POST['country'];
if (!isset($_POST['state']) && $_POST['state'] == '') {
$appInstance->BadRequest('State is missing', ['error_code' => 'STATE_MISSING']);
}
$state = $_POST['state'];
if (!isset($_POST['postcode']) && $_POST['postcode'] == '') {
$appInstance->BadRequest('PostCode is missing', ['error_code' => 'POSTCODE_MISSING']);
}
$postcode = $_POST['postcode'];

Billing::updateBilling(
$session->getInfo(UserColumns::UUID, false),
$companyName,
$vatNumber,
$address1,
$address2,
$city,
$country,
$state,
$postcode
);

$appInstance->OK('Billing info saved successfully!', []);
} catch (Exception $e) {
$appInstance->getLogger()->error('Failed to save billing info! ' . $e->getMessage());
$appInstance->BadRequest('Bad Request', ['error_code' => 'DB_ERROR', 'error' => $e->getMessage()]);
}
});

$router->get('/api/user/session', function (): void {
Expand Down Expand Up @@ -80,7 +140,7 @@
'role_name' => Roles::getUserRoleName(User::getInfo($accountToken, UserColumns::UUID, false)),
'role_real_name' => Roles::getUserRoleName(User::getInfo($accountToken, UserColumns::UUID, false)),
],
'billing' => $billing
'billing' => $billing,
]);
} catch (Exception $e) {
$appInstance->BadRequest('Bad Request', ['error_code' => 'INVALID_ACCOUNT_TOKEN', 'error' => $e->getMessage()]);
Expand Down
5 changes: 2 additions & 3 deletions backend/app/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,15 @@ public function __construct(bool $softBoot)
self::InternalServerError($e->getMessage(), null);
}
/**
* Email correction
* Email correction.
*/
if ($this->getConfig()->getSetting('app_url', null) == null) {
$this->getConfig()->setSetting('app_url', $_SERVER['HTTP_HOST']);
}

/**
* Redis
* Redis.
*/

$redis = new FastChat\Redis();
if ($redis->testConnection() == false) {
self::init();
Expand Down
Loading

0 comments on commit 64fa24a

Please sign in to comment.