|
@@ -14,12 +14,12 @@ class Login extends Controller
|
|
|
{
|
|
{
|
|
|
public function Login($f3)
|
|
public function Login($f3)
|
|
|
{
|
|
{
|
|
|
- if ($f3->exists('SESSION.user_id')) {
|
|
|
|
|
|
|
+ if ($f3->exists('SESSION.user')) {
|
|
|
$f3->reroute('/homemenu');
|
|
$f3->reroute('/homemenu');
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $f3->clear('SESSION');
|
|
|
|
|
|
|
+ $f3->clear('SESSION.user');
|
|
|
$f3->clear('COOKIE.username');
|
|
$f3->clear('COOKIE.username');
|
|
|
|
|
|
|
|
$f3->set('CONTENT', 'login.tpl');
|
|
$f3->set('CONTENT', 'login.tpl');
|
|
@@ -31,15 +31,16 @@ class Login extends Controller
|
|
|
*
|
|
*
|
|
|
* @param string $username
|
|
* @param string $username
|
|
|
* @param string $password
|
|
* @param string $password
|
|
|
- * @return int|null
|
|
|
|
|
|
|
+ * @return int|\OpenMind\System\User
|
|
|
*/
|
|
*/
|
|
|
- private function checkLogin(string $username, string $password): ?int
|
|
|
|
|
|
|
+ private function checkLogin(string $username, string $password): ?User
|
|
|
{
|
|
{
|
|
|
- $accounts = \F3::get('users.PASSWORD');
|
|
|
|
|
- foreach ($accounts as $index => $account) {
|
|
|
|
|
- $exist = password_verify("{$username}|{$password}", $account);
|
|
|
|
|
|
|
+ $user = new User(['username=?', $username]);
|
|
|
|
|
+
|
|
|
|
|
+ if (!$user->dry()) {
|
|
|
|
|
+ $exist = password_verify("{$username}|{$password}", $user->saltedpassword);
|
|
|
if ($exist)
|
|
if ($exist)
|
|
|
- return $index;
|
|
|
|
|
|
|
+ return $user;
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -48,23 +49,21 @@ class Login extends Controller
|
|
|
* Check if username and password are correct
|
|
* Check if username and password are correct
|
|
|
*
|
|
*
|
|
|
* @param $f3
|
|
* @param $f3
|
|
|
|
|
+ * @throws \Exception
|
|
|
*/
|
|
*/
|
|
|
public function LoginForm($f3)
|
|
public function LoginForm($f3)
|
|
|
{
|
|
{
|
|
|
$accountData = $this->getSanitizedPostRequest();
|
|
$accountData = $this->getSanitizedPostRequest();
|
|
|
|
|
|
|
|
- $userId = $this->checkLogin($accountData['username'], $accountData['password']);
|
|
|
|
|
|
|
+ $user = $this->checkLogin($accountData['username'], $accountData['password']);
|
|
|
|
|
|
|
|
- if (is_null($userId)) {
|
|
|
|
|
|
|
+ if (is_null($user)) {
|
|
|
http_response_code(500);
|
|
http_response_code(500);
|
|
|
- echo "Dati di accesso non corretti";
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ throw new \Exception("Dati di accesso non corretti");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $f3->set('SESSION.user_id', $userId);
|
|
|
|
|
- $user = new User($userId, $accountData['username']);
|
|
|
|
|
- $user->Save();
|
|
|
|
|
- $f3->set('USERID', $userId);
|
|
|
|
|
|
|
+ $user->Store();
|
|
|
|
|
+
|
|
|
$f3->set('COOKIE.username', $accountData['username']);
|
|
$f3->set('COOKIE.username', $accountData['username']);
|
|
|
|
|
|
|
|
$f3->reroute('/homemenu');
|
|
$f3->reroute('/homemenu');
|
|
@@ -72,7 +71,7 @@ class Login extends Controller
|
|
|
|
|
|
|
|
public function Logout($f3)
|
|
public function Logout($f3)
|
|
|
{
|
|
{
|
|
|
- $f3->clear('SESSION');
|
|
|
|
|
|
|
+ $f3->clear('SESSION.user');
|
|
|
$f3->clear('COOKIE.username');
|
|
$f3->clear('COOKIE.username');
|
|
|
$f3->reroute('/');
|
|
$f3->reroute('/');
|
|
|
}
|
|
}
|