|
@@ -0,0 +1,66 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+namespace Modules;
|
|
|
|
|
+/**
|
|
|
|
|
+ * @author Open Mind
|
|
|
|
|
+ * @date 09/04/2018
|
|
|
|
|
+ * @time 16:15
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+class BaseController
|
|
|
|
|
+{
|
|
|
|
|
+ protected $db;
|
|
|
|
|
+ protected $isLogged;
|
|
|
|
|
+
|
|
|
|
|
+ public function __construct($f3)
|
|
|
|
|
+ {
|
|
|
|
|
+// $this->db = new \DB\SQL($f3->get('DB'), $f3->get('dbuser'), $f3->get('dbpass'), array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_PERSISTENT => TRUE));
|
|
|
|
|
+ $this->isLogged = $this->checkLogin($f3->get('COOKIE.username'), $f3->get('COOKIE.password'));
|
|
|
|
|
+
|
|
|
|
|
+ if ($this->isLogged)
|
|
|
|
|
+ return;
|
|
|
|
|
+
|
|
|
|
|
+ $f3->clear('COOKIE.username');
|
|
|
|
|
+ $f3->clear('COOKIE.password');
|
|
|
|
|
+
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Check if login is valid
|
|
|
|
|
+ * @param $email
|
|
|
|
|
+ * @param $password
|
|
|
|
|
+ * @return bool
|
|
|
|
|
+ */
|
|
|
|
|
+ private function checkLogin($username, $password)
|
|
|
|
|
+ {
|
|
|
|
|
+ return password_verify("{$username}|{$password}", \F3::get('PASSWORD'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function Login($f3)
|
|
|
|
|
+ {
|
|
|
|
|
+ $f3->clear('SESSION');
|
|
|
|
|
+
|
|
|
|
|
+ $accountData = $f3->clean($f3->get('POST'));
|
|
|
|
|
+
|
|
|
|
|
+ if (!$this->checkLogin($accountData['username'], $accountData['password'])) {
|
|
|
|
|
+ http_response_code(500);
|
|
|
|
|
+ echo "Dati di accesso non corretto";
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $f3->set('COOKIE.username', $accountData['username']);
|
|
|
|
|
+ $f3->set('COOKIE.password', $accountData['password']);
|
|
|
|
|
+ http_response_code(200);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function Logout($f3)
|
|
|
|
|
+ {
|
|
|
|
|
+ WriteLog("user {$f3->get('COOKIE.username')}");
|
|
|
|
|
+ $f3->clear('SESSION');
|
|
|
|
|
+ $f3->clear('COOKIE.username');
|
|
|
|
|
+ $f3->clear('COOKIE.password');
|
|
|
|
|
+ $f3->reroute($f3->get('BASEURL'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|