-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAuthTemplateTrait.php
128 lines (111 loc) · 2.92 KB
/
AuthTemplateTrait.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
namespace Charcoal\Admin\Template;
/**
*
*/
trait AuthTemplateTrait
{
/**
* Retrieve the base URI of the application.
*
* @param mixed $targetPath Optional target path.
* @throws RuntimeException If the base URI is missing.
* @return string|null
*/
abstract public function baseUrl($targetPath = null);
/**
* Retrieve the URI of the administration-area.
*
* @param mixed $targetPath Optional target path.
* @throws RuntimeException If the admin URI is missing.
* @return UriInterface|null
*/
abstract public function adminUrl($targetPath = null);
/**
* Retrieve the admin's configset.
*
* @param string|null $key Optional data key to retrieve from the configset.
* @param mixed|null $default The default value to return if data key does not exist.
* @return mixed|AdminConfig
*/
abstract protected function adminConfig($key = null, $default = null);
/**
* @return string
*/
public function urlLogin()
{
return $this->adminUrl('login');
}
/**
* @return string
*/
public function urlLostPassword()
{
return $this->adminUrl('account/lost-password');
}
/**
* @return string
*/
public function urlResetPassword()
{
return $this->adminUrl('account/reset-password');
}
/**
* Get the "Back to website" label.
*
* @return string|boolean The button's label,
* TRUE to use the default label,
* or FALSE to disable the link.
*/
public function returnToSiteLabel()
{
$label = $this->adminConfig('login.visit_site');
if ($label === false) {
return false;
}
if (empty($label) || $label === true) {
$label = $this->translator()->translate('Back to website');
} else {
$label = $this->translator()->translate($label);
}
return '← '.$label;
}
/**
* Get the background image, from admin config.
*
* @return string
*/
public function backgroundImage()
{
$backdrop = $this->adminConfig('login.background_image');
if (empty($backdrop)) {
return '';
}
return $this->baseUrl($backdrop);
}
/**
* Get the background video, from admin config.
*
* @return string
*/
public function backgroundVideo()
{
$backdrop = $this->adminConfig('login.background_video');
if (empty($backdrop)) {
return '';
}
return $this->baseUrl($backdrop);
}
/**
* @return string
*/
public function avatarImage()
{
$logo = $this->adminConfig('login.logo') ?:
$this->adminConfig('login_logo', 'assets/admin/images/avatar.jpg');
if (empty($logo)) {
return '';
}
return $this->baseUrl($logo);
}
}