-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathhome.php
55 lines (44 loc) · 1.61 KB
/
home.php
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
46
47
48
49
50
51
52
53
54
55
<?php
class Home extends Controller{
public function index(){
/*
* URL parameters can be recieved as an argument by specifying a variable for it in function declaration
* EX: public function index($param1 , $param2){}
* and can be used inside the function
* - processed by the function model
* - sent to the view
*/
//loggedin user info
global $loggedUser;
//getting index model
$index = $this->model('Index');
//showing home/index view
$this->view('home/index', ['user' => $loggedUser ]);
}
/*
* login method includes a new object of login class
* checks if user credentials [username,passwords] are provided using POST
* if so it checks if user credentials are right using Login model
* else it views the login page
*/
public function login(){
$login = $this->model('Login');
if(isset($_POST['username'])){
$login->username = $_POST['username'];
$login->password = $_POST['password'];
$user = $login->userlogin();
if(!$user){
$this->view('home/login', [ 'error' => 'loginError' ]);
}else{
$this->view('home/index', [ 'msg' => 'loginSuccess','user' => $user ]);
}
}else{
$this->view('home/login');
}
}
public function logout(){
$logout = $this->model('Logout');
$logout->userLogout();
$this->view('home/login',['msg' => 'logoutSuccess']);
}
}