ConditionalLogin   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A login() 0 4 1
A check_conditions() 0 16 6
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * Conditional login
6
 * Used to implement the loading of custom pages
7
 * 2011, Noel Dieschburg <[email protected]>.
8
 */
9
class ConditionalLogin
10
{
11
    /**
12
     * Check conditions based in the $login_conditions see conditional_login.php file.
13
     *
14
     * @param array $user
15
     */
16
    public static function check_conditions($user)
17
    {
18
        $file = api_get_path(SYS_CODE_PATH).'auth/conditional_login/conditional_login.php';
19
        if (file_exists($file)) {
20
            include_once $file;
21
            if (isset($login_conditions)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $login_conditions seems to never exist and therefore isset should always be false.
Loading history...
22
                foreach ($login_conditions as $condition) {
23
                    //If condition fails we redirect to the URL defined by the condition
24
                    if (isset($condition['conditional_function'])) {
25
                        $function = $condition['conditional_function'];
26
                        $result = $function($user);
27
                        if (false == $result) {
28
                            $_SESSION['conditional_login']['uid'] = $user['user_id'];
29
                            $_SESSION['conditional_login']['can_login'] = false;
30
                            header("Location: ".$condition['url']);
31
                            exit;
32
                        }
33
                    }
34
                }
35
            }
36
        }
37
    }
38
39
    public static function login()
40
    {
41
        $_SESSION['conditional_login']['can_login'] = true;
42
        LoginRedirection::redirect();
43
    }
44
}
45