Subversion Repositories cheapmusic

Rev

Rev 35 | Rev 57 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
25 - 1
<?php
2
// Get current page file name
3
$pageFile = basename($_SERVER['PHP_SELF']);
4
 
5
// Include config file && User class
6
require_once 'config.php';
7
require_once 'User.class.php';
8
 
34 - 9
// Check whether user ID is available in cookie and cookie hash matches
25 - 10
if(isset($_COOKIE['rememberUserId']) && !empty($rememberUserId)){
34 - 11
    require_once 'includes/password.php';
12
    $user = new User();
13
    $conditions['where'] = array(
14
        'id' => $_COOKIE['rememberUserId'],
15
    );
16
    $conditions['return_type'] = 'single';
17
    $userData = $user->getRows($conditions);
18
    if (!empty($userData) && password_verify($userData['password'] . $userData['id'], $_COOKIE['hash'])) {
35 - 19
	$_SESSION['sessData']['userLoggedIn'] = true;
26 - 20
	$_SESSION['sessData']['userID'] = $rememberUserId;
34 - 21
    }
25 - 22
}
23
 
24
// Get session data
25
$sessData = !empty($_SESSION['sessData'])?$_SESSION['sessData']:array();
26
 
27
// Redirect to homepage if user not logged in
28
$userLoggedIn = (!empty($sessData['userLoggedIn']) && !empty($sessData['userID']))?true:false;
29 - 29
 
25 - 30
switch($pageFile){
31
	case 'account.php':
26 - 32
	case 'editAccount.php':
33
	case 'changePassword.php':
25 - 34
		if($userLoggedIn){
35
			$user = new User();
36
			$conditions['where'] = array(
37
				'id' => $sessData['userID'],
38
			);
39
			$conditions['return_type'] = 'single';
40
			$userData = $user->getRows($conditions);
41
 
42
			$httpPos = strpos($userData['picture'], 'http');
43
			if($httpPos === false){
44
				$userPicture = !empty($userData['picture'])?UPLOAD_URL.'profile_picture/'.$userData['picture']:PUBLIC_URL.'images/default.png';
45
			}else{
46
				$userPicture = $userData['picture'];
47
			}
48
			$userName = $userData['first_name'].' '.$userData['last_name'];
49
		}else{
31 - 50
            MySessionHandler::commit(session_id());
30 - 51
			header("Location: index.php");
25 - 52
			exit();
53
		}
54
		break;
55
	case 'forgotPassword.php':
56
	case 'registration.php':
57
	case 'resetPassword.php':
58
		if($userLoggedIn){
31 - 59
            MySessionHandler::commit(session_id());
25 - 60
			header("Location: account.php");
61
			exit();
62
		}
63
		break;
29 - 64
	case 'index.php':
25 - 65
		if($userLoggedIn){
31 - 66
            MySessionHandler::commit(session_id());
25 - 67
			header("Location: account.php");
68
			exit();
69
		}else{
70
			// Include social login handler
71
			require_once 'socialLogin.php';
72
		}
26 - 73
		// fall through
25 - 74
	default:
75
		$userData = array();
76
}
77
 
78
// Get status message from session
79
if(!empty($sessData['status']['msg'])){
80
    $statusMsg = $sessData['status']['msg'];
81
    $statusMsgType = $sessData['status']['type'];
82
    unset($_SESSION['sessData']['status']);
26 - 83
}
31 - 84
 
85
MySessionHandler::commit(session_id());