Exemplo n.º 1
0
            if (strcmp($_POST['action'], 'login') == 0 && isset($_POST['email']) && isset($_POST['password'])) {
                $email = trim($_POST['email']);
                $password = trim($_POST['password']);
                $cdi = new ClientDaoImp($entityManager);
                $client = $cdi->getClientByEmail($email);
                if ($client == null) {
                    echo json_encode(array('flag' => 'EMAIL_NULL'));
                } else {
                    if (strcmp($client->getPassword(), md5($password)) == 0) {
                        $cl = $_SESSION['client'];
                        $cdi = new ClientDaoImp($entityManager);
                        $client = $cdi->getClientById($cl->getId());
                        if ($client != null) {
                            foreach ($client->getOrders() as $order) {
                                if (!$order->getValid()) {
                                    $order->setValid(true);
                                }
                            }
                        }
                        $entityManager->flush();
                        echo json_encode(array('flag' => 'PASSWD_OK'));
                    } else {
                        echo json_encode(array('flag' => 'PASSWD_NULL'));
                    }
                }
            } else {
                echo json_encode(array('flag', 'error: Action not found'));
            }
        }
    }
}