Subversion Repositories cheapmusic

Rev

Rev 57 | 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
65 - 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'])) {
65 - 19
        $_SESSION['sessData']['userLoggedIn'] = true;
20
        $_SESSION['sessData']['userID'] = $rememberUserId;
34 - 21
    }
25 - 22
}
23
 
24
// Get session data
65 - 25
$sessData = !empty($_SESSION['sessData']) ? $_SESSION['sessData'] : array();
25 - 26
 
27
// Redirect to homepage if user not logged in
65 - 28
$userLoggedIn = (!empty($sessData['userLoggedIn']) && !empty($sessData['userID'])) ? true : false;
29 - 29
 
65 - 30
switch ($pageFile) {
31
    case 'account.php':
32
    case 'editAccount.php':
33
    case 'changePassword.php':
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
            }
46
            else {
47
                $userPicture = $userData['picture'];
48
            }
49
            $userName = $userData['first_name'] . ' ' . $userData['last_name'];
50
            $userTheme = $userData['theme'];
51
        }
52
        else {
31 - 53
            MySessionHandler::commit(session_id());
65 - 54
            header("Location: index.php");
55
            exit();
56
        }
57
    break;
58
    case 'forgotPassword.php':
59
    case 'registration.php':
60
    case 'resetPassword.php':
61
        if ($userLoggedIn) {
31 - 62
            MySessionHandler::commit(session_id());
65 - 63
            header("Location: account.php");
64
            exit();
65
        }
66
    break;
67
    case 'index.php':
68
        if ($userLoggedIn) {
31 - 69
            MySessionHandler::commit(session_id());
65 - 70
            header("Location: account.php");
71
            exit();
72
        }
73
        else {
74
            // Include social login handler
75
            require_once 'socialLogin.php';
76
        }
77
        // fall through
78
 
79
    default:
80
        $userData = array();
25 - 81
}
82
 
83
// Get status message from session
65 - 84
if (!empty($sessData['status']['msg'])) {
25 - 85
    $statusMsg = $sessData['status']['msg'];
86
    $statusMsgType = $sessData['status']['type'];
87
    unset($_SESSION['sessData']['status']);
26 - 88
}
31 - 89
 
90
MySessionHandler::commit(session_id());