1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Class AdminSecurity. |
6
|
|
|
*/ |
7
|
|
|
class AdminSecurity extends Security |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var array |
11
|
|
|
*/ |
12
|
|
|
private static $allowed_actions = [ |
|
|
|
|
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'; |
|
|
|
|
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
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.