Completed
Push — master ( 736eaa...f4bae8 )
by Martijn van
02:32
created

AdminSecurity::init()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 1 Features 0
Metric Value
c 6
b 1
f 0
dl 0
loc 17
rs 9.4285
cc 3
eloc 9
nc 4
nop 0
1
<?php
2
3
4
/**
5
 * Class AdminSecurity
6
 */
7
class AdminSecurity extends Security
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
    /**
10
     * @var array
11
     */
12
    private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
13
        'passwordsent',
14
        'ChangePasswordForm'
15
    );
16
17
    /**
18
     * Template thats used to render the pages.
19
     *
20
     * @config
21
     * @var string
22
     */
23
    private static $template_main = 'AdminLogin';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $template_main is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
24
25
    /**
26
     * @return void
27
     */
28
    public function init()
29
    {
30
        parent::init();
31
32
        $access = new IpAccess($this->getRequest()->getIP());
33
        if (!$access->hasAccess()) {
34
            $access->respondNoAccess($this);
35
        }
36
37
        if (Config::inst()->get('AdminLogin', 'UseTheme') !== true) {
38
            // this prevents loading frontend css and javscript files
39
            Object::useCustomClass('Page_Controller', 'AdminLoginPage_Controller');
40
            Requirements::css('adminlogin/css/style.css');
41
        }
42
43
        Object::useCustomClass('MemberLoginForm', 'AdminLoginForm');
44
    }
45
46
    /**
47
     * @param null $action
48
     * @return string
49
     */
50
    public function Link($action = null)
51
    {
52
        return "AdminSecurity/$action";
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public static function isAdminLogin()
59
    {
60
        return strstr(self::getBackUrl(), '/admin/');
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public static function getBackUrl()
67
    {
68
        $request = Controller::curr()->getRequest();
69
        if ($url = $request->requestVar('BackURL')) {
70
            return $url;
71
        }
72
        return '';
73
    }
74
75
    /**
76
     * @param SS_HTTPRequest $request
77
     * @return SS_HTTPResponse|HTMLText
78
     */
79
    public function passwordsent($request)
80
    {
81
        return parent::passwordsent($request);
82
    }
83
84
    /**
85
     * @see Security::getPasswordResetLink()
86
     * We overload this, so we can add the BackURL to the password resetlink
87
     * @param Member $member
88
     * @param string $autologinToken
89
     * @return string
90
     */
91
    public static function getPasswordResetLink($member, $autologinToken)
92
    {
93
        $autologinToken      = urldecode($autologinToken);
94
        $selfControllerClass = __CLASS__;
95
        $selfController      = new $selfControllerClass();
96
        return $selfController->Link('changepassword') . "?m={$member->ID}&t=$autologinToken";
97
    }
98
99
    /**
100
     * @return ChangePasswordForm
101
     */
102
    public function ChangePasswordForm()
103
    {
104
        return new ChangePasswordForm($this, 'ChangePasswordForm');
105
    }
106
}
107