Download????????? ??? ??????????????? ?????? ?? ????????? ?????????
???? ? ?????? ?????????? ??????????? ??? ?? Ascoos OS ?????? ?? ?????????? ?? credentials ???? ?????? ???? ??? ???????????????, ????????????? ?? ?????????? ????????. ?? ??????? ????????? modular handlers ??? ?????????, ??????????????? ??? ?????????? ?????????.
??????
-
????????? credentials ?????? ?? ???????
-
??????????????? ?????? ????? ???????????? ?????????
-
????????? ????????? ????????? ? ?????????
?????? ??????? ??? Ascoos OS
-
TValidationHandler
????????? ????????? ??????? ?? ???????????????? ???????
-
TAuthenticationHandler
??????????????? ?????? ??? ?????????? token
-
TEventHandler
????????? ??? ?????????? ?????????
???? ???????
? ????????? ????????? ?? ??? ?????? PHP:
- validated_login_flow.php
???????????? ??? ?? ??????: ?????????, ??????????????? ??? ????????? ?????????.
??????????????
-
PHP ? 8.2
-
????????????? ?? Ascoos OS ? ??
AWES 26
??? ?????????
-
????????? ????????? ??? ????????? ?? ?????? `validated_login.log`.
-
??????????????? ?? handlers ??????????, ???????????????? ??? ?????????.
-
?????????? ?? handlers ?? ??? ??????????? ?????????.
-
????????????? ????????:
- `validation.failed`: ???????? ??????????
- `auth.success`: ???????? ???????????????
- `auth.failed`: ???????? ????????????????
-
????????? credentials ?????? ??? ??????? ??????????.
-
?? ? ????????? ????????, ???????????? ?? ?????? ??? ???????????? JSON ?? ?? ????.
-
?? ? ??????????????? ???????, ????????????? token ??? ???????????? ????????.
-
?? ????????, ???????????? ????????.
-
???????????? JSON ?? ?? ??????????.
?????????? ??????
$auth = new TAuthenticationHandler($properties);
$validator = new TValidationHandler($properties);
$events = new TEventHandler([], $properties);
$auth->setEventHandler($events);
$validator->setEventHandler($events);
$events->register('login', 'validation.failed', fn($errors) => $events->logger->log("Validation failed: " . json_encode($errors)));
$events->register('login', 'auth.success', fn($user) => $events->logger->log("Authentication successful for: $user"));
$events->register('login', 'auth.failed', fn($user) => $events->logger->log("Authentication failed for: $user"));
$credentials = ['username' => 'admin', 'password' => 'securePass123'];
$rules = ['username' => 'required|string|min:3', 'password' => 'required|string|min:8'];
if (!$validator->validate($credentials, $rules)) {
$validator->emit('validation.failed', $validator->getErrors());
echo json_encode(['status' => 'validation_error', 'errors' => $validator->getErrors()], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
return;
}
if ($auth->authenticate($credentials)) {
$token = $auth->generateToken();
$auth->emit('auth.success', $credentials['username']);
} else {
$auth->emit('auth.failed', $credentials['username']);
$token = null;
}
echo json_encode([
'user' => $credentials['username'],
'authenticated' => $token !== null,
'token' => $token
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
??????????? ??????????
?? ? ????????? ????????: {
"status": "validation_error",
"errors": {
"password": "?? ????? password ?????? ?? ???? ??????????? 8 ??????????."
}
}
?? ? ??????????????? ???????: {
"user": "admin",
"authenticated": true,
"token": "..."
}
?? ????????: {
"user": "admin",
"authenticated": false,
"token": null
}
?????
??????????
???????? ?? ??????????? ?? ?????? ???????????? ???????? ????????, ?????????? ??? ?????????? ??????? ? ????????????? ??????????? ????????????????. ????? ?? CONTRIBUTING.md ??? ???????.
????? ??????
???? ? ?????? ?????????? ??? ??? Ascoos General License (AGL). ????? ?? LICENSE.md.
|