-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-> Added auth system :)
- Loading branch information
Showing
24 changed files
with
496 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"cSpell.words": [ | ||
"Swal", | ||
"sweetalert" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
use MythicalClient\App; | ||
use MythicalClient\Chat\columns\EmailVerificationColumns; | ||
use MythicalClient\Chat\columns\UserColumns; | ||
use MythicalClient\Chat\User; | ||
use MythicalClient\Chat\Verification; | ||
use MythicalSystems\CloudFlare\Turnstile; | ||
use MythicalClient\Config\ConfigInterface; | ||
use MythicalSystems\CloudFlare\CloudFlare; | ||
use MythicalSystems\Utils\XChaCha20; | ||
|
||
$router->get("/api/user/auth/reset", function (): void { | ||
App::init(); | ||
$appInstance = App::getInstance(true); | ||
$config = $appInstance->getConfig(); | ||
|
||
$appInstance->allowOnlyGET(); | ||
|
||
if (isset($_GET['code']) && $_GET['code'] != '') { | ||
$code = $_GET['code']; | ||
|
||
if (Verification::verify($code, EmailVerificationColumns::$type_password)) { | ||
$appInstance->OK('Code is valid', ['reset_code' => $code]); | ||
} else { | ||
$appInstance->BadRequest('Bad Request', ['error_code' => 'INVALID_CODE']); | ||
} | ||
} else { | ||
$appInstance->BadRequest('Bad Request', ['error_code' => 'MISSING_CODE']); | ||
} | ||
}); | ||
|
||
$router->post("/api/user/auth/reset", function (): void { | ||
App::init(); | ||
$appInstance = App::getInstance(true); | ||
$config = $appInstance->getConfig(); | ||
|
||
$appInstance->allowOnlyPOST(); | ||
|
||
if (!isset($_POST['email_code']) || $_POST['email_code'] == '') { | ||
$appInstance->BadRequest('Bad Request', ['error_code' => 'MISSING_CODE']); | ||
} | ||
|
||
if (!isset($_POST['password']) || $_POST['password'] == '') { | ||
$appInstance->BadRequest('Bad Request', ['error_code' => 'MISSING_PASSWORD']); | ||
} | ||
|
||
if (!isset($_POST['confirmPassword']) || $_POST['confirmPassword'] == '') { | ||
$appInstance->BadRequest('Bad Request', ['error_code' => 'MISSING_PASSWORD_CONFIRM']); | ||
} | ||
|
||
if ($_POST['password'] != $_POST['confirmPassword']) { | ||
$appInstance->BadRequest('Bad Request', ['error_code' => 'PASSWORDS_DO_NOT_MATCH']); | ||
} | ||
|
||
$code = $_POST['email_code']; | ||
$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, CloudFlare::getRealUserIP(), $config->getSetting(ConfigInterface::TURNSTILE_KEY_PRIV, 'XXXX'))) { | ||
$appInstance->BadRequest('Invalid TurnStile Key', ['error_code' => 'TURNSTILE_FAILED']); | ||
} | ||
} | ||
|
||
if (Verification::verify($code, EmailVerificationColumns::$type_password)) { | ||
$uuid = Verification::getUserUUID($code); | ||
if ($uuid == null || $uuid == '') { | ||
$appInstance->BadRequest('Bad Request', ['error_code' => 'INVALID_CODE']); | ||
} | ||
$userToken = User::getTokenFromUUID($uuid); | ||
if ($userToken == null || $userToken == '') { | ||
$appInstance->BadRequest('Bad Request', ['error_code' => 'INVALID_CODE']); | ||
} | ||
|
||
if (User::updateInfo($userToken, UserColumns::PASSWORD, $password, true) == true) { | ||
Verification::delete($code); | ||
$appInstance->OK('Password has been reset', []); | ||
} else { | ||
$appInstance->BadRequest('Failed to reset password', ['error_code' => 'FAILED_TO_RESET_PASSWORD']); | ||
} | ||
|
||
} else { | ||
$appInstance->BadRequest('Bad Request', ['error_code' => 'INVALID_CODE']); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
DATABASE_HOST=mythicalclient_database | ||
DATABASE_PORT=3306 | ||
DATABASE_USER=mythical | ||
DATABASE_PASSWORD="Pizza2007!" | ||
DATABASE_DATABASE=mythicalclient | ||
DATABASE_ENCRYPTION=xchacha20 | ||
DATABASE_ENCRYPTION_KEY="Wk2nAV0QHORNEg8/ZQQBeqdW4p2G8lp747RpP6T9yxs=" | ||
REDIS_PASSWORD="eufefwefwefw" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
DATABASE_HOST=mythicalclient_database | ||
DATABASE_HOST=127.0.0.1 | ||
DATABASE_PORT=3306 | ||
DATABASE_USER=mythical | ||
DATABASE_PASSWORD="Pizza2007!" | ||
DATABASE_PASSWORD= | ||
DATABASE_DATABASE=mythicalclient | ||
DATABASE_ENCRYPTION=xchacha20 | ||
DATABASE_ENCRYPTION_KEY="Wk2nAV0QHORNEg8/ZQQBeqdW4p2G8lp747RpP6T9yxs=" | ||
DATABASE_ENCRYPTION_KEY=zKZ7//AocUD2wCuzjW5rdTbb8FvGBgKTZ8iCATslZ/8= | ||
REDIS_PASSWORD="eufefwefwefw" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.