AdminSecurity::Link()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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