Exemplo n.º 1
0
                     $error = 'Błąd w formularzu';
                 }
             } else {
                 $error = 'Błąd w formularzu1';
             }
             break;
         case 'loginFromStorage':
             if (isset($_POST['id']) && isset($_POST['user']) && isset($_POST['mail']) && isset($_POST['token'])) {
                 if (!isset($_SESSION['id'])) {
                     if (DbConfig::checkToken($_POST['token'])) {
                         $db = DbConfig::getInstance();
                         $query = $db->prepare("SELECT * FROM users WHERE (login = ?) LIMIT 1");
                         $query->execute([$_POST['user']]);
                         $results = $query->fetch();
                         if ($results) {
                             $_SESSION['token'] = DbConfig::getToken();
                             $_SESSION['user'] = $_POST['user'];
                             $_SESSION['mail'] = $results['mail'];
                             $_SESSION['id'] = $results['id'];
                             $_SESSION['lastTime'] = time();
                             $success = true;
                         }
                     }
                 }
             }
             break;
     }
 }
 if ($error != null) {
     echo json_encode(['success' => false, 'data' => $error]);
     exit;