forked from qutek/flight-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
45 lines (36 loc) · 939 Bytes
/
Copy pathindex.php
File metadata and controls
45 lines (36 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
require 'vendor/autoload.php';
if ( session_status() == PHP_SESSION_NONE ) {
session_start();
}
Flight::route('/', function(){
if ( !isset( $_SESSION['user'] ) ) {
Flight::redirect( '/login' );
exit();
}
Flight::render( 'dashboard', array( 'name' => $_SESSION['user'] ) );
});
Flight::route('GET /login', function(){
Flight::render( 'login' );
});
Flight::route('POST /login', function(){
$username = $_POST['username'];
$password = $_POST['password'];
// cek di database dan login / redirect kalo ga terdaftar
$exist = $username == 'user';
if ( $exist ) {
// logged in
$_SESSION['user'] = 'user';
Flight::redirect( '/' );
} else {
// kembalikan ke hlaman login
Flight::redirect( '/login' );
}
});
Flight::route( '/logout', function(){
if ( isset( $_SESSION['user'] ) ){
unset( $_SESSION['user'] );
}
Flight::redirect( '/login' );
});
Flight::start();