/
Authenticated.php
52 lines (40 loc) · 1.05 KB
/
Authenticated.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace Statamic\Auth\Protect\Protectors;
class Authenticated extends Protector
{
public function protect()
{
if (auth()->check()) {
return;
}
if ($this->isLoginUrl()) {
return;
}
if (! $this->getLoginUrl()) {
abort(403);
}
abort(redirect($this->getLoginUrl()));
}
protected function getLoginUrl()
{
if (! $url = array_get($this->config, 'login_url')) {
return null;
}
if (! $this->shouldAppendRedirect()) {
return $url;
}
$url = parse_url($url);
if ($query = array_get($url, 'query')) {
$query .= '&';
}
return $url['path'].'?'.$query.'redirect='.$this->url;
}
protected function isLoginUrl()
{
return parse_url($this->url, PHP_URL_PATH) === parse_url($this->getLoginUrl(), PHP_URL_PATH);
}
protected function shouldAppendRedirect()
{
return array_get($this->config, 'append_redirect', false);
}
}