Completed
Push — master ( 4962bf...d1af8f )
by Martijn van
02:36
created
code/AdminLoginForm.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -3,66 +3,66 @@
 block discarded – undo
3 3
 class AdminLoginForm extends MemberLoginForm
4 4
 {
5 5
 
6
-    public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
7
-    {
8
-        parent::__construct($controller, $name, $fields, $actions, $checkCurrentUser);
6
+	public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
7
+	{
8
+		parent::__construct($controller, $name, $fields, $actions, $checkCurrentUser);
9 9
 
10
-        if ($this->Actions()->fieldByName('forgotPassword')) {
11
-            // replaceField won't work, since it's a dataless field
12
-            $this->Actions()->removeByName('forgotPassword');
13
-            $this->Actions()->push(new LiteralField(
14
-                'forgotPassword',
15
-                '<p id="ForgotPassword"><a href="AdminSecurity/lostpassword">'
16
-                . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'
17
-            ));
18
-        }
10
+		if ($this->Actions()->fieldByName('forgotPassword')) {
11
+			// replaceField won't work, since it's a dataless field
12
+			$this->Actions()->removeByName('forgotPassword');
13
+			$this->Actions()->push(new LiteralField(
14
+				'forgotPassword',
15
+				'<p id="ForgotPassword"><a href="AdminSecurity/lostpassword">'
16
+				. _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'
17
+			));
18
+		}
19 19
 
20
-        Requirements::customScript(<<<JS
20
+		Requirements::customScript(<<<JS
21 21
 			(function() {
22 22
 				var el = document.getElementById("AdminLoginForm_LoginForm_Email");
23 23
 				if(el && el.focus) el.focus();
24 24
 			})();
25 25
 JS
26
-        );
27
-    }
26
+		);
27
+	}
28 28
 
29
-    /**
30
-     * @param array $data
31
-     */
32
-    public function forgotPassword($data)
33
-    {
34
-        if($data['Email']) {
35
-            /* @var $member Member */
36
-            if ($member = Member::get()->where("Email = '".Convert::raw2sql($data['Email'])."'")->first()) {
37
-                $token = $member->generateAutologinTokenAndStoreHash();
38
-                $this->sendPasswordResetLinkEmail($member, $token);
39
-            }
29
+	/**
30
+	 * @param array $data
31
+	 */
32
+	public function forgotPassword($data)
33
+	{
34
+		if($data['Email']) {
35
+			/* @var $member Member */
36
+			if ($member = Member::get()->where("Email = '".Convert::raw2sql($data['Email'])."'")->first()) {
37
+				$token = $member->generateAutologinTokenAndStoreHash();
38
+				$this->sendPasswordResetLinkEmail($member, $token);
39
+			}
40 40
 
41
-            return $this->controller->redirect('AdminSecurity/passwordsent/' . urlencode($data['Email']));
42
-        }
41
+			return $this->controller->redirect('AdminSecurity/passwordsent/' . urlencode($data['Email']));
42
+		}
43 43
 
44
-        $this->sessionMessage(
45
-            _t('Member.ENTEREMAIL', 'Please enter an email address to get a password reset link.'),
46
-            'bad'
47
-        );
44
+		$this->sessionMessage(
45
+			_t('Member.ENTEREMAIL', 'Please enter an email address to get a password reset link.'),
46
+			'bad'
47
+		);
48 48
 
49
-        return $this->controller->redirect('AdminSecurity/lostpassword');
50
-    }
49
+		return $this->controller->redirect('AdminSecurity/lostpassword');
50
+	}
51 51
 
52
-    /**
53
-     * @param Member $member
54
-     * @param string $token
55
-     */
56
-    protected function sendPasswordResetLinkEmail($member, $token)
57
-    {
58
-        /* @var $email Member_ForgotPasswordEmail */
59
-        $email = Member_ForgotPasswordEmail::create();
60
-        $email->populateTemplate($member);
61
-        $email->populateTemplate(array(
62
-            'PasswordResetLink' => AdminSecurity::getPasswordResetLink($member, $token)
63
-        ));
64
-        $email->setTo($member->Email);
65
-        $email->send();
66
-    }
52
+	/**
53
+	 * @param Member $member
54
+	 * @param string $token
55
+	 */
56
+	protected function sendPasswordResetLinkEmail($member, $token)
57
+	{
58
+		/* @var $email Member_ForgotPasswordEmail */
59
+		$email = Member_ForgotPasswordEmail::create();
60
+		$email->populateTemplate($member);
61
+		$email->populateTemplate(array(
62
+			'PasswordResetLink' => AdminSecurity::getPasswordResetLink($member, $token)
63
+		));
64
+		$email->setTo($member->Email);
65
+		$email->send();
66
+	}
67 67
 
68 68
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@
 block discarded – undo
31 31
      */
32 32
     public function forgotPassword($data)
33 33
     {
34
-        if($data['Email']) {
34
+        if ($data['Email']) {
35 35
             /* @var $member Member */
36
-            if ($member = Member::get()->where("Email = '".Convert::raw2sql($data['Email'])."'")->first()) {
36
+            if ($member = Member::get()->where("Email = '" . Convert::raw2sql($data['Email']) . "'")->first()) {
37 37
                 $token = $member->generateAutologinTokenAndStoreHash();
38 38
                 $this->sendPasswordResetLinkEmail($member, $token);
39 39
             }
Please login to merge, or discard this patch.
code/model/IpAccess.php 2 patches
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -13,170 +13,170 @@
 block discarded – undo
13 13
  */
14 14
 class IpAccess extends Object
15 15
 {
16
-    /**
17
-     * @var array
18
-     */
19
-    public $allowedIps = array();
20
-
21
-    /**
22
-     * @config
23
-     * @var array
24
-     */
25
-    private static $allowed_ips = array();
26
-
27
-    /**
28
-     * @var string
29
-     */
30
-    private $ip = '';
31
-
32
-    /**
33
-     * IpAccess constructor.
34
-     *
35
-     * @param string $ip
36
-     * @param array $allowedIps
37
-     */
38
-    public function __construct($ip = '', $allowedIps = array())
39
-    {
40
-        parent::__construct();
41
-        $this->ip = $ip;
42
-
43
-        self::config()->allowed_ips = $allowedIps;
44
-    }
45
-
46
-    /**
47
-     * @param $ip
48
-     */
49
-    public function setIp($ip)
50
-    {
51
-        $this->ip = $ip;
52
-    }
53
-
54
-    /**
55
-     * @return array
56
-     */
57
-    public function getAllowedIps()
58
-    {
59
-        if (!empty($this->allowedIps)) {
60
-            Deprecation::notice('1.1', 'Use the "IpAccess.allowed_ips" config setting instead');
61
-            self::config()->allowed_ips = $this->allowedIps;
62
-        }
63
-        return (array)self::config()->allowed_ips;
64
-    }
65
-
66
-    /**
67
-     * @return bool
68
-     */
69
-    public function isEnabled()
70
-    {
71
-        return (bool)Config::inst()->get('IpAccess', 'enabled');
72
-    }
73
-
74
-    /**
75
-     * @return bool
76
-     */
77
-    public function hasAccess()
78
-    {
79
-        if(!$this->isEnabled() || empty($this->getAllowedIps())) {
80
-            return true;
81
-        }
82
-
83
-        return ($this->matchExact() || $this->matchRange() || $this->matchCIDR() || $this->matchWildCard());
84
-    }
85
-
86
-    /**
87
-     * @param Controller $controller
88
-     * @throws SS_HTTPResponse_Exception
89
-     */
90
-    public function respondNoAccess(Controller $controller)
91
-    {
92
-        $response = null;
93
-        if (class_exists('ErrorPage', true)) {
94
-            $response = ErrorPage::response_for(403);
95
-        }
96
-        $controller->httpError(403, $response ? $response : 'The requested page could not be found.');
97
-    }
98
-
99
-    /**
100
-     * @return string
101
-     */
102
-    public function matchExact()
103
-    {
104
-        return in_array($this->ip, $this->getAllowedIps()) ? $this->ip : '';
105
-    }
106
-
107
-    /**
108
-     * Try to match against a ip range
109
-     *
110
-     * Example : 192.168.1.50-100
111
-     *
112
-     * @return string
113
-     */
114
-    public function matchRange()
115
-    {
116
-        $ranges = array_filter($this->getAllowedIps(), function ($ip) {
117
-            return strstr($ip, '-');
118
-        });
119
-
120
-        if (!$ranges) {
121
-            return '';
122
-        }
123
-
124
-        $ipFirstPart = substr($this->ip, 0, strrpos($this->ip, '.') + 1);
125
-        $ipLastpart  = substr(strrchr($this->ip, '.'), 1);
126
-
127
-        foreach ($ranges as $range) {
128
-            $rangeFirstPart = substr($range, 0, strrpos($range, '.') + 1);
129
-            list ($start, $end) = explode('-', substr(strrchr($range, '.'), 1));
130
-            if($ipFirstPart === $rangeFirstPart && $ipLastpart >= $start && $ipLastpart <= $end) {
131
-                return $range;
132
-            }
133
-        }
134
-    }
135
-
136
-    /**
137
-     * Try to match cidr range
138
-     *
139
-     * Example : 192.168.1.0/24
140
-     *
141
-     * @return string
142
-     */
143
-    public function matchCIDR()
144
-    {
145
-        if ($ranges = array_filter($this->getAllowedIps(), function ($ip) {
146
-            return strstr($ip, '/');
147
-        })
148
-        ) {
149
-            foreach ($ranges as $cidr) {
150
-                list ($net, $mask) = explode('/', $cidr);
151
-                if ((ip2long($this->ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($net)) {
152
-                    return $cidr;
153
-                }
154
-            }
155
-        }
156
-        return '';
157
-    }
158
-
159
-    /**
160
-     * Try to match against a range that ends with a wildcard *
161
-     *
162
-     * Example : 192.168.1.*
163
-     * Example : 192.168.*
164
-     *
165
-     * @return string
166
-     */
167
-    public function matchWildCard()
168
-    {
169
-        if ($ranges = array_filter($this->getAllowedIps(), function ($ip) {
170
-            return substr($ip, -1) === '*';
171
-        })
172
-        ) {
173
-            foreach ($ranges as $range) {
174
-                if (substr($this->ip, 0, strlen(substr($range, 0, -1))) === substr($range, 0, -1)) {
175
-                    return $range;
176
-                }
177
-            }
178
-        }
179
-        return '';
180
-    }
16
+	/**
17
+	 * @var array
18
+	 */
19
+	public $allowedIps = array();
20
+
21
+	/**
22
+	 * @config
23
+	 * @var array
24
+	 */
25
+	private static $allowed_ips = array();
26
+
27
+	/**
28
+	 * @var string
29
+	 */
30
+	private $ip = '';
31
+
32
+	/**
33
+	 * IpAccess constructor.
34
+	 *
35
+	 * @param string $ip
36
+	 * @param array $allowedIps
37
+	 */
38
+	public function __construct($ip = '', $allowedIps = array())
39
+	{
40
+		parent::__construct();
41
+		$this->ip = $ip;
42
+
43
+		self::config()->allowed_ips = $allowedIps;
44
+	}
45
+
46
+	/**
47
+	 * @param $ip
48
+	 */
49
+	public function setIp($ip)
50
+	{
51
+		$this->ip = $ip;
52
+	}
53
+
54
+	/**
55
+	 * @return array
56
+	 */
57
+	public function getAllowedIps()
58
+	{
59
+		if (!empty($this->allowedIps)) {
60
+			Deprecation::notice('1.1', 'Use the "IpAccess.allowed_ips" config setting instead');
61
+			self::config()->allowed_ips = $this->allowedIps;
62
+		}
63
+		return (array)self::config()->allowed_ips;
64
+	}
65
+
66
+	/**
67
+	 * @return bool
68
+	 */
69
+	public function isEnabled()
70
+	{
71
+		return (bool)Config::inst()->get('IpAccess', 'enabled');
72
+	}
73
+
74
+	/**
75
+	 * @return bool
76
+	 */
77
+	public function hasAccess()
78
+	{
79
+		if(!$this->isEnabled() || empty($this->getAllowedIps())) {
80
+			return true;
81
+		}
82
+
83
+		return ($this->matchExact() || $this->matchRange() || $this->matchCIDR() || $this->matchWildCard());
84
+	}
85
+
86
+	/**
87
+	 * @param Controller $controller
88
+	 * @throws SS_HTTPResponse_Exception
89
+	 */
90
+	public function respondNoAccess(Controller $controller)
91
+	{
92
+		$response = null;
93
+		if (class_exists('ErrorPage', true)) {
94
+			$response = ErrorPage::response_for(403);
95
+		}
96
+		$controller->httpError(403, $response ? $response : 'The requested page could not be found.');
97
+	}
98
+
99
+	/**
100
+	 * @return string
101
+	 */
102
+	public function matchExact()
103
+	{
104
+		return in_array($this->ip, $this->getAllowedIps()) ? $this->ip : '';
105
+	}
106
+
107
+	/**
108
+	 * Try to match against a ip range
109
+	 *
110
+	 * Example : 192.168.1.50-100
111
+	 *
112
+	 * @return string
113
+	 */
114
+	public function matchRange()
115
+	{
116
+		$ranges = array_filter($this->getAllowedIps(), function ($ip) {
117
+			return strstr($ip, '-');
118
+		});
119
+
120
+		if (!$ranges) {
121
+			return '';
122
+		}
123
+
124
+		$ipFirstPart = substr($this->ip, 0, strrpos($this->ip, '.') + 1);
125
+		$ipLastpart  = substr(strrchr($this->ip, '.'), 1);
126
+
127
+		foreach ($ranges as $range) {
128
+			$rangeFirstPart = substr($range, 0, strrpos($range, '.') + 1);
129
+			list ($start, $end) = explode('-', substr(strrchr($range, '.'), 1));
130
+			if($ipFirstPart === $rangeFirstPart && $ipLastpart >= $start && $ipLastpart <= $end) {
131
+				return $range;
132
+			}
133
+		}
134
+	}
135
+
136
+	/**
137
+	 * Try to match cidr range
138
+	 *
139
+	 * Example : 192.168.1.0/24
140
+	 *
141
+	 * @return string
142
+	 */
143
+	public function matchCIDR()
144
+	{
145
+		if ($ranges = array_filter($this->getAllowedIps(), function ($ip) {
146
+			return strstr($ip, '/');
147
+		})
148
+		) {
149
+			foreach ($ranges as $cidr) {
150
+				list ($net, $mask) = explode('/', $cidr);
151
+				if ((ip2long($this->ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($net)) {
152
+					return $cidr;
153
+				}
154
+			}
155
+		}
156
+		return '';
157
+	}
158
+
159
+	/**
160
+	 * Try to match against a range that ends with a wildcard *
161
+	 *
162
+	 * Example : 192.168.1.*
163
+	 * Example : 192.168.*
164
+	 *
165
+	 * @return string
166
+	 */
167
+	public function matchWildCard()
168
+	{
169
+		if ($ranges = array_filter($this->getAllowedIps(), function ($ip) {
170
+			return substr($ip, -1) === '*';
171
+		})
172
+		) {
173
+			foreach ($ranges as $range) {
174
+				if (substr($this->ip, 0, strlen(substr($range, 0, -1))) === substr($range, 0, -1)) {
175
+					return $range;
176
+				}
177
+			}
178
+		}
179
+		return '';
180
+	}
181 181
 
182 182
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
             Deprecation::notice('1.1', 'Use the "IpAccess.allowed_ips" config setting instead');
61 61
             self::config()->allowed_ips = $this->allowedIps;
62 62
         }
63
-        return (array)self::config()->allowed_ips;
63
+        return (array) self::config()->allowed_ips;
64 64
     }
65 65
 
66 66
     /**
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
      */
69 69
     public function isEnabled()
70 70
     {
71
-        return (bool)Config::inst()->get('IpAccess', 'enabled');
71
+        return (bool) Config::inst()->get('IpAccess', 'enabled');
72 72
     }
73 73
 
74 74
     /**
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      */
77 77
     public function hasAccess()
78 78
     {
79
-        if(!$this->isEnabled() || empty($this->getAllowedIps())) {
79
+        if (!$this->isEnabled() || empty($this->getAllowedIps())) {
80 80
             return true;
81 81
         }
82 82
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      */
114 114
     public function matchRange()
115 115
     {
116
-        $ranges = array_filter($this->getAllowedIps(), function ($ip) {
116
+        $ranges = array_filter($this->getAllowedIps(), function($ip) {
117 117
             return strstr($ip, '-');
118 118
         });
119 119
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         foreach ($ranges as $range) {
128 128
             $rangeFirstPart = substr($range, 0, strrpos($range, '.') + 1);
129 129
             list ($start, $end) = explode('-', substr(strrchr($range, '.'), 1));
130
-            if($ipFirstPart === $rangeFirstPart && $ipLastpart >= $start && $ipLastpart <= $end) {
130
+            if ($ipFirstPart === $rangeFirstPart && $ipLastpart >= $start && $ipLastpart <= $end) {
131 131
                 return $range;
132 132
             }
133 133
         }
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
      */
143 143
     public function matchCIDR()
144 144
     {
145
-        if ($ranges = array_filter($this->getAllowedIps(), function ($ip) {
145
+        if ($ranges = array_filter($this->getAllowedIps(), function($ip) {
146 146
             return strstr($ip, '/');
147 147
         })
148 148
         ) {
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      */
167 167
     public function matchWildCard()
168 168
     {
169
-        if ($ranges = array_filter($this->getAllowedIps(), function ($ip) {
169
+        if ($ranges = array_filter($this->getAllowedIps(), function($ip) {
170 170
             return substr($ip, -1) === '*';
171 171
         })
172 172
         ) {
Please login to merge, or discard this patch.