This commit is contained in:
45
app/Controllers/Auth/RegisterController.php
Normal file
45
app/Controllers/Auth/RegisterController.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Auth;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\UserModel;
|
||||
|
||||
class RegisterController extends BaseController
|
||||
{
|
||||
public function showRegistrationForm()
|
||||
{
|
||||
helper(['form']);
|
||||
$data = [];
|
||||
echo view('auth/register', $data);
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
helper(['form']);
|
||||
$rules = [
|
||||
'name' => 'required|min_length[2]|max_length[50]',
|
||||
'email' => 'required|min_length[4]|max_length[100]|valid_email|is_unique[users.email]',
|
||||
'password' => 'required|min_length[4]|max_length[50]',
|
||||
'confirmpassword' => 'matches[password]'
|
||||
];
|
||||
|
||||
if ($this->validate($rules)) {
|
||||
$user = new userModel();
|
||||
$data = [
|
||||
'name' => $this->request->getVar('name'),
|
||||
'email' => $this->request->getVar('email'),
|
||||
'password' => password_hash($this->request->getVar('password'), PASSWORD_DEFAULT)
|
||||
];
|
||||
|
||||
$user->save($data);
|
||||
$authSession = new SessionConroller();
|
||||
$authSession->authorised($data);
|
||||
|
||||
return redirect()->to('/');
|
||||
} else {
|
||||
$data['validation'] = $this->validator;
|
||||
echo view('auth/register', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user