Exemple #1
0
 public static function login()
 {
     $connection = Flight::dbMain();
     try {
         $session = json_decode(file_get_contents("php://input"));
         if ($session == null) {
             throw new Exception(json_get_error());
         }
         $sql = "SELECT * FROM user WHERE user.user_name = :name and user.user_password = :password;";
         $query = $connection->prepare($sql);
         $password = hash('sha256', $session->Password);
         $query->bindParam(':name', $session->Name, PDO::PARAM_STR);
         $query->bindParam(':password', $password, PDO::PARAM_STR);
         $query->execute();
         $row = $query->fetch(PDO::FETCH_ASSOC);
         if ($query->rowCount() < 1) {
             throw new Exception("Username or Password is not exist");
         }
         $user = new User();
         $user->Id = (int) $row['id'];
         $user->Name = $row['user_name'];
         $user->DtCreated = $row['user_dt_created'];
         $user->DtExpired = $row['user_dt_expired'];
         // $user->Privilege = (int) $row['e_privilege_id'];
         // $user->Status = (int) $row['e_status_id'];
         // $user->Company = (int) $row['company_id'];
         // $user->Sim = $row['sim_id'] == null ? null : (int) $row['sim_id'];
         $user->Privilege = Privilege::select($row['e_privilege_id']);
         $user->Status = Status::select($row['e_status_id']);
         $user->Company = Company::select($row['company_id']);
         $user->Sim = Sim::select($row['sim_id']);
         Flight::ok($user);
     } catch (PDOException $pdoException) {
         Flight::error($pdoException);
     } catch (Exception $exception) {
         Flight::error($exception);
     } finally {
         $connection = null;
     }
 }
Exemple #2
0
 public static function selectByCompany($id)
 {
     $connection = Flight::dbMain();
     try {
         $sql = "SELECT * FROM user WHERE company_id = :company;";
         $query = $connection->prepare($sql);
         $query->bindParam(':company', $id, PDO::PARAM_INT);
         $query->execute();
         $rows = $query->fetchAll(PDO::FETCH_ASSOC);
         $result = array();
         foreach ($rows as $row) {
             $user = new User();
             $user->Id = (int) $row['id'];
             $user->Name = $row['user_name'];
             $user->DtCreated = $row['user_dt_created'];
             $user->DtExpired = $row['user_dt_expired'];
             // $user->Privilege = (int) $row['e_privilege_id'];
             // $user->Status = (int) $row['e_status_id'];
             // $user->Company = (int) $row['company_id'];
             // $user->Sim = $row['sim_id'] == null ? null : (int) $row['sim_id'];
             $user->Privilege = Privilege::select($row['e_privilege_id']);
             $user->Status = Status::select($row['e_status_id']);
             $user->Company = Company::select($row['company_id']);
             $user->Sim = Sim::select($row['sim_id']);
             array_push($result, $user);
         }
         return $result;
     } catch (PDOException $pdoException) {
         throw $pdoException;
     } catch (Exception $exception) {
         throw $exception;
     } finally {
         $connection = null;
     }
 }
Exemple #3
0
    }
});
//=============================================================================
//Privilege
//=============================================================================
Flight::route('GET /v1/main/privilege', function () {
    try {
        $array = Privilege::selectAll();
        Flight::ok($array);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
Flight::route('GET /v1/main/privilege/@id', function ($id) {
    try {
        $object = Privilege::select($id);
        Flight::ok($object);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
Flight::route('POST /v1/main/privilege', function () {
    try {
        $object = Privilege::insert();
        Flight::ok($object);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
Flight::route('PUT /v1/main/privilege/@id', function ($id) {
    try {