Bicycle/App/Controller/IndexController.php
2026-08-10 23:24:03 +03:00

49 lines
1.5 KiB
PHP

<?php
/**
* @package Bicycle
* @author Egor Isaev
* @description IndexController.php
* @copyright (c) 03/06/2026
*/
namespace App\Controller;
use Services\Auth;
use System\Classes\Controller;
use System\Classes\HTTP\Request as HTTPRequest;
use System\Classes\MyException;
use System\Classes\Request;
use System\Classes\Validation;
/**
* Главная страница = страница входа (пока в проекте нет ничего, кроме авторизации).
*/
class IndexController extends Controller
{
/**
* @return string
* @throws MyException
*/
public function indexAction(): string
{
$request = Request::$current;
$error = null;
if ($request->method() === HTTPRequest::POST) {
$validation = Validation::factory($request->post())
->label('login', 'Логин')
->label('password', 'Пароль')
->rule('login', 'required')
->rule('password', 'required');
if ($validation->check() && Auth::instance()->login($request->post('login'), $request->post('password'))) {
return $this->renderContent('index', ['error' => null, 'user' => Auth::instance()->getUser()]);
}
$error = 'Неверный логин или пароль';
}
return $this->renderContent('index', ['error' => $error, 'user' => Auth::instance()->getUser()]);
}
}