Example #1
0
require __DIR__ . '/./vendor/autoload.php';
require './config.php';
require './helpers/boot.php';
require_once './helpers/OnlineUser.php';
require_once './helpers/session.php';
require_once './helpers/User.php';
require './helpers/functions.php';
use Illuminate\Validation\Factory as ValidatorFactory;
use Symfony\Component\Translation\Translator;
$error = 0;
const ERROR_DB = 1;
const ERROR_INVALID = 3;
const ERROR_VALFAIL = 4;
const ERROR_MAILTAKEN = 5;
$session = new Session();
$session->redirectIfAuth('./admin/index.php', './trainer/index.php', './doctor/index.php', './index.php');
$factory = new ValidatorFactory(new Translator('en'));
$messages = getErrorMessages();
if (isset($_POST['type'])) {
    $type = $_POST['type'];
    if ($type == "login") {
        if ($_POST['email'] == $admin_email && $_POST['password'] == $admin_password) {
            $session->logIn(1, Session::USER_ADMIN);
            $session->redirectIfAuth('./admin/index.php', './trainer/index.php', './doctor/index.php', './index.php');
        }
        $validator = $factory->make($_POST, ['email' => 'required', 'password' => 'required'], $messages);
        if ($validator->passes()) {
            $u = User::where('email', $_POST['email'])->where('password', $_POST['password'])->first();
            if ($u) {
                $session->logIn($u->id, $u->type);
                $session->redirectIfAuth('./admin/index.php', './trainer/index.php', './doctor/index.php', './index.php');