registration
This commit is contained in:
parent
3ef7f2946b
commit
60f8797173
@ -7,6 +7,7 @@ use kernel\AdminController;
|
||||
use kernel\Flash;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\modules\secure\models\forms\LoginForm;
|
||||
use kernel\modules\secure\models\forms\RegisterForm;
|
||||
use kernel\modules\user\service\UserService;
|
||||
|
||||
class SecureController extends AdminController
|
||||
@ -16,7 +17,6 @@ class SecureController extends AdminController
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
// $this->cgView->viewPath = KERNEL_DIR . "/views/secure/";
|
||||
$this->cgView->viewPath = KERNEL_MODULES_DIR. "/secure/views/";
|
||||
$this->cgView->layout = "/login.php";
|
||||
$this->userService = new UserService();
|
||||
@ -61,4 +61,31 @@ class SecureController extends AdminController
|
||||
$this->redirect("/", code: 302);
|
||||
}
|
||||
|
||||
public function actionRegister()
|
||||
{
|
||||
$this->cgView->render('register.php');
|
||||
}
|
||||
|
||||
public function actionRegistration(): void
|
||||
{
|
||||
$regForm = new RegisterForm();
|
||||
$regForm->load($_REQUEST);
|
||||
|
||||
if ($this->userService->getByField('username', $regForm->getItem("username"))) {
|
||||
Flash::setMessage("error", "Username already exists.");
|
||||
$this->redirect("/admin/register", code: 302);
|
||||
}
|
||||
|
||||
if ($this->userService->getByField('email', $regForm->getItem("email"))) {
|
||||
Flash::setMessage("error", "Email already exists.");
|
||||
$this->redirect("/admin/register", code: 302);
|
||||
}
|
||||
|
||||
$user = $this->userService->create($regForm);
|
||||
if ($user){
|
||||
setcookie('user_id', $user->id, time()+60*60*24, '/', $_SERVER['SERVER_NAME'], false);
|
||||
$this->redirect("/admin", code: 302);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
19
kernel/modules/secure/models/forms/RegisterForm.php
Normal file
19
kernel/modules/secure/models/forms/RegisterForm.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\modules\secure\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
class RegisterForm extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'username' => 'required|min-str-len:5|max-str-len:50',
|
||||
'email' => 'required|email|max-str-len:50',
|
||||
'password' => 'required|min-str-len:6|max-str-len:50',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -14,6 +14,8 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||
App::$collector->get('/login', [\kernel\modules\secure\controllers\SecureController::class, 'actionLogin']);
|
||||
App::$collector->get('/logout', [\kernel\modules\secure\controllers\SecureController::class, 'actionLogout']);
|
||||
App::$collector->post('/auth', [\kernel\modules\secure\controllers\SecureController::class, 'actionAuth']);
|
||||
App::$collector->get('/register', [\kernel\modules\secure\controllers\SecureController::class, 'actionRegister']);
|
||||
App::$collector->post('/registration', [\kernel\modules\secure\controllers\SecureController::class, 'actionRegistration']);
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "api"], function (CgRouteCollector $router){
|
||||
|
@ -48,10 +48,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
<div class="col-3">
|
||||
<!-- Simple link -->
|
||||
<a href="#!">Забыл пароль?</a>
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
<!-- Simple link -->
|
||||
<a href="/admin/register">Регистрация</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Submit button -->
|
||||
|
57
kernel/modules/secure/views/register.php
Normal file
57
kernel/modules/secure/views/register.php
Normal file
@ -0,0 +1,57 @@
|
||||
<!-- Section: Design Block -->
|
||||
<section class=" text-center text-lg-start">
|
||||
<style>
|
||||
.rounded-t-5 {
|
||||
border-top-left-radius: 0.5rem;
|
||||
border-top-right-radius: 0.5rem;
|
||||
}
|
||||
|
||||
@media (min-width: 992px) {
|
||||
.rounded-tr-lg-0 {
|
||||
border-top-right-radius: 0;
|
||||
}
|
||||
|
||||
.rounded-bl-lg-5 {
|
||||
border-bottom-left-radius: 0.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<div class="card mb-3">
|
||||
<div class="row g-0 d-flex align-items-center">
|
||||
<div class="col-lg-4 d-none d-lg-flex">
|
||||
<img src="https://mdbootstrap.com/img/new/ecommerce/vertical/004.jpg" alt="Trendy Pants and Shoes"
|
||||
class="w-100 rounded-t-5 rounded-tr-lg-0 rounded-bl-lg-5" />
|
||||
</div>
|
||||
<div class="col-lg-8">
|
||||
<div class="card-body py-5 px-md-5">
|
||||
|
||||
<form action="/admin/registration" method="post">
|
||||
<!--Username input -->
|
||||
<div data-mdb-input-init class="form-outline mb-4">
|
||||
<input type="text" id="form2Example1" class="form-control" name="username" />
|
||||
<label class="form-label" for="form2Example1">Логин</label>
|
||||
</div>
|
||||
|
||||
<!-- Email input -->
|
||||
<div data-mdb-input-init class="form-outline mb-4">
|
||||
<input type="email" id="form2Example1" class="form-control" name="email" />
|
||||
<label class="form-label" for="form2Example1">Email</label>
|
||||
</div>
|
||||
|
||||
<!-- Password input -->
|
||||
<div data-mdb-input-init class="form-outline mb-4">
|
||||
<input type="password" id="form2Example2" class="form-control" name="password" />
|
||||
<label class="form-label" for="form2Example2">Пароль</label>
|
||||
</div>
|
||||
|
||||
<!-- Submit button -->
|
||||
<button type="submit" data-mdb-button-init data-mdb-ripple-init class="btn btn-primary btn-block mb-4">Регистрация</button>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<!-- Section: Design Block -->
|
Loading…
Reference in New Issue
Block a user