first commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
/**
|
||||
* Logowanie jednego uzytkownika wprost z .env (user_email + user_password).
|
||||
* ponytail: jawne haslo z .env, narzedzie jednoosobowe. Podniesc do password_hash,
|
||||
* jesli kiedys pojawi sie wielu uzytkownikow / tabela users.
|
||||
*/
|
||||
class Auth extends BaseController
|
||||
{
|
||||
public function login()
|
||||
{
|
||||
if (session()->get('logged_in')) {
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
if (strtolower($this->request->getMethod()) === 'post') {
|
||||
$email = trim((string) $this->request->getPost('email'));
|
||||
$pass = (string) $this->request->getPost('password');
|
||||
|
||||
$okEmail = (string) env('user_email');
|
||||
$okPass = (string) env('user_password');
|
||||
|
||||
if ($okEmail !== '' && hash_equals($okEmail, $email) && hash_equals($okPass, $pass)) {
|
||||
session()->set([
|
||||
'logged_in' => true,
|
||||
'user_email' => $email,
|
||||
]);
|
||||
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
return redirect()->back()->with('error', 'Nieprawidłowy email lub hasło.');
|
||||
}
|
||||
|
||||
return view('auth/login');
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
session()->destroy();
|
||||
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user