54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use App\Models\User;
|
||
|
use Illuminate\Validation\Rule;
|
||
|
use Illuminate\Http\Request;
|
||
|
|
||
|
class UserController extends Controller
|
||
|
{
|
||
|
public function create()
|
||
|
{
|
||
|
return view('users.register');
|
||
|
}
|
||
|
|
||
|
public function store(Request $request)
|
||
|
{
|
||
|
$formFields = $request->validate([
|
||
|
'rz_username' => ['required', Rule::unique('users', 'rz_username')],
|
||
|
'full_name' => ['required', 'min:3'],
|
||
|
'organisation_unit' => 'required',
|
||
|
'password' => 'required|min:6'
|
||
|
//'password' => 'required|confirmed|min:6'
|
||
|
]);
|
||
|
|
||
|
// Hash Password
|
||
|
$formFields['hashed_password'] = bcrypt($formFields['password']);
|
||
|
|
||
|
$user = User::create($formFields);
|
||
|
|
||
|
auth()->login($user);
|
||
|
return redirect('/home');
|
||
|
}
|
||
|
|
||
|
public function login()
|
||
|
{
|
||
|
return view('users.login');
|
||
|
}
|
||
|
|
||
|
public function authenticate(Request $request)
|
||
|
{
|
||
|
$formFields = $request->validate([
|
||
|
'rz_username' => 'required',
|
||
|
'password' => 'required'
|
||
|
]);
|
||
|
|
||
|
if (auth()->attempt($formFields)) {
|
||
|
$request->session()->regenerate();
|
||
|
|
||
|
return redirect('/home');
|
||
|
}
|
||
|
}
|
||
|
}
|