Skip to content

Commit 88f9726

Browse files
bergmaniaMigaroeziOvergaard
authored
Explicit endpoints returning the Login and BackOffice logos and background (#17696)
* Created explicit endpoints returning the login image instead of leaking the configuration. Thereby some hardcoded values have been changed, but the url will now be the same every time. * Remove magic concatenation for action lookup * remove unused backoffice asset (login.jpg) * remove unused umbraco logo assets * add manifest handlers * add mock handlers for the `security/back-office/graphics` endpoints to the backoffice * add mock handlers for the `security/back-office/graphics` endpoints to the login screen * chore: update msw service worker * feat: make static assets available for consumption without copying them from the login project * update consts with new location for static assets * feat: prefix login assets with `login-` * remove unused asset `logo.png` * feat: introduce a `/back-office/graphics/logo` endpoint to serve the logo "mark" used throughout all applications * feat: use the alternative logo for disabled javascript warning * feat: use the umbraco logo on the NoNodes.cshtml page * Do not expose the new readme in the package * feat: add logo.svg * feat: add `umb-app-logo` element to display the backoffice logo including server url and appropriate tags * feat: use the new `umb-app-logo` element relevant places and make sure to add the serverUrl in front of other graphics * feat: move logic to connectedCallback to prevent error from non-existing element * revert usage of HideBackOfficeLogo * feat: add alt text to logos * feat: add obsolete message and a hint to use BackOfficeLogo insted --------- Co-authored-by: Sven Geusens <[email protected]> Co-authored-by: Jacob Overgaard <[email protected]>
1 parent db7c78b commit 88f9726

File tree

29 files changed

+367
-83
lines changed

29 files changed

+367
-83
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using Asp.Versioning;
2+
using Microsoft.AspNetCore.Authorization;
3+
using Microsoft.AspNetCore.Builder;
4+
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.AspNetCore.Http;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.AspNetCore.StaticFiles;
8+
using Microsoft.Extensions.Options;
9+
using Umbraco.Cms.Api.Management.Routing;
10+
using Umbraco.Cms.Core;
11+
using Umbraco.Cms.Core.Configuration.Models;
12+
13+
namespace Umbraco.Cms.Api.Management.Controllers.Security;
14+
15+
[ApiVersion("1.0")]
16+
[VersionedApiBackOfficeRoute(Common.Security.Paths.BackOfficeApi.EndpointTemplate + "/graphics")]
17+
[ApiExplorerSettings(IgnoreApi = true)]
18+
public class BackOfficeGraphicsController : Controller
19+
{
20+
public const string LogoRouteName = nameof(BackOfficeGraphicsController) + "." + nameof(Logo);
21+
public const string LoginBackGroundRouteName = nameof(BackOfficeGraphicsController) + "." + nameof(LoginBackground);
22+
public const string LoginLogoRouteName = nameof(BackOfficeGraphicsController) + "." + nameof(LoginLogo);
23+
public const string LoginLogoAlternativeRouteName = nameof(BackOfficeGraphicsController) + "." + nameof(LoginLogoAlternative);
24+
25+
private readonly IOptions<ContentSettings> _contentSettings;
26+
private readonly IContentTypeProvider _contentTypeProvider;
27+
private readonly IWebHostEnvironment _webHostEnvironment;
28+
29+
public BackOfficeGraphicsController(IOptions<ContentSettings> contentSettings, IOptions<StaticFileOptions> staticFileOptions, IWebHostEnvironment webHostEnvironment)
30+
{
31+
_contentSettings = contentSettings;
32+
_webHostEnvironment = webHostEnvironment;
33+
_contentTypeProvider = staticFileOptions.Value.ContentTypeProvider ?? new FileExtensionContentTypeProvider();
34+
}
35+
36+
[HttpGet("login-background", Name = LoginBackGroundRouteName)]
37+
[AllowAnonymous]
38+
[MapToApiVersion("1.0")]
39+
public IActionResult LoginBackground() => HandleFileRequest(_contentSettings.Value.LoginBackgroundImage);
40+
41+
[HttpGet("logo", Name = LogoRouteName)]
42+
[AllowAnonymous]
43+
[MapToApiVersion("1.0")]
44+
public IActionResult Logo() => HandleFileRequest(_contentSettings.Value.BackOfficeLogo);
45+
46+
[HttpGet("login-logo", Name = LoginLogoRouteName)]
47+
[AllowAnonymous]
48+
[MapToApiVersion("1.0")]
49+
public IActionResult LoginLogo() => HandleFileRequest(_contentSettings.Value.LoginLogoImage);
50+
51+
[HttpGet("login-logo-alternative", Name = LoginLogoAlternativeRouteName)]
52+
[AllowAnonymous]
53+
[MapToApiVersion("1.0")]
54+
public IActionResult LoginLogoAlternative() => HandleFileRequest(_contentSettings.Value.LoginLogoImageAlternative);
55+
56+
private IActionResult HandleFileRequest(string virtualPath)
57+
{
58+
var filePath = Path.Combine(Constants.SystemDirectories.Umbraco, virtualPath).TrimStart(Constants.CharArrays.Tilde);
59+
var fileInfo = _webHostEnvironment.WebRootFileProvider.GetFileInfo(filePath);
60+
61+
if (fileInfo.PhysicalPath is null)
62+
{
63+
return NotFound();
64+
}
65+
66+
if (_contentTypeProvider.TryGetContentType(fileInfo.PhysicalPath, out var contentType))
67+
{
68+
Stream fileStream = fileInfo.CreateReadStream();
69+
return File(fileStream, contentType);
70+
}
71+
72+
return StatusCode(StatusCodes.Status412PreconditionFailed);
73+
}
74+
}

src/Umbraco.Cms.StaticAssets/Umbraco.Cms.StaticAssets.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
<Content Remove="$(LoginAssetsPath)\**" />
7373
</ItemGroup>
7474

75+
<ItemGroup>
76+
<Content Remove="wwwroot\umbraco\assets\README.md" />
77+
</ItemGroup>
78+
7579
<Target Name="RestoreLogin" Inputs="$(LoginProjectDirectory)package-lock.json" Outputs="$(LoginProjectDirectory)node_modules/.package-lock.json">
7680
<Message Importance="high" Text="Restoring Login NPM packages..." />
7781
<Exec Command="npm ci --no-fund --no-audit --prefer-offline" WorkingDirectory="$(LoginProjectDirectory)" />

src/Umbraco.Cms.StaticAssets/umbraco/UmbracoBackOffice/Index.cshtml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@using Microsoft.Extensions.Options
2+
@using Umbraco.Cms.Api.Management.Controllers.Security
23
@using Umbraco.Cms.Api.Management.Extensions
34
@using Umbraco.Cms.Core.Configuration.Models
45
@using Umbraco.Cms.Core.Logging
@@ -11,13 +12,12 @@
1112
@inject IJsonSerializer JsonSerializer
1213
@inject IProfilerHtml ProfilerHtml
1314
@inject IOptions<GlobalSettings> GlobalSettings
14-
@inject IOptions<ContentSettings> ContentSettings
1515

1616
@{
1717
bool.TryParse(Context.Request.Query["umbDebug"], out var isDebug);
1818
var backOfficePath = BackOfficePathGenerator.BackOfficePath;
1919
var backOfficeAssetsPath = BackOfficePathGenerator.BackOfficeAssetsPath;
20-
var loginLogoImage = ContentSettings.Value.LoginLogoImage;
20+
var loginLogoImageAlternative = Url.RouteUrl(BackOfficeGraphicsController.LoginLogoAlternativeRouteName, new {Version= "1"});
2121
}
2222

2323
<!DOCTYPE html>
@@ -54,8 +54,8 @@
5454
}
5555
</style>
5656
<div id="noscript-container">
57-
<h1 class="uui-h3" style="display: inline-flex; align-items: center; gap: 10px">
58-
<img aria-hidden="true" alt="logo" src="@loginLogoImage" style="width: 100%" />
57+
<h1 aria-hidden="true" class="uui-h3" style="display: inline-flex; align-items: center; gap: 10px">
58+
<img alt="logo" src="@loginLogoImageAlternative" style="width: 100%" />
5959
</h1>
6060
<p>For full functionality of Umbraco CMS it is necessary to enable JavaScript.</p>
6161
<p>Here are the <a href="https://www.enable-javascript.com/" target="_blank" rel="noopener" style="text-decoration: underline;">instructions how to enable JavaScript in your web browser</a>.</p>

src/Umbraco.Cms.StaticAssets/umbraco/UmbracoLogin/Index.cshtml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@using Microsoft.AspNetCore.Mvc.TagHelpers
22
@using Microsoft.Extensions.Options;
3+
@using Umbraco.Cms.Api.Management.Controllers.Security
34
@using Umbraco.Cms.Api.Management.Extensions
45
@using Umbraco.Cms.Api.Management.Security
56
@using Umbraco.Cms.Core.Configuration.Models
@@ -10,7 +11,6 @@
1011
@using Umbraco.Cms.Core.Serialization
1112
@using Umbraco.Cms.Web.Common.Hosting
1213
@using Umbraco.Extensions
13-
@inject IOptions<ContentSettings> ContentSettings
1414
@inject IOptions<SecuritySettings> SecuritySettings
1515
@inject IEmailSender EmailSender
1616
@inject IHostingEnvironment HostingEnvironment
@@ -23,9 +23,9 @@
2323
@{
2424
bool.TryParse(Context.Request.Query["umbDebug"], out var isDebug);
2525
var backOfficePath = GlobalSettings.Value.GetBackOfficePath(HostingEnvironment);
26-
var loginLogoImage = ContentSettings.Value.LoginLogoImage;
27-
var loginLogoImageAlternative = ContentSettings.Value.LoginLogoImageAlternative;
28-
var loginBackgroundImage = ContentSettings.Value.LoginBackgroundImage;
26+
var loginLogoImage = Url.RouteUrl(BackOfficeGraphicsController.LoginLogoRouteName, new {Version= "1"});
27+
var loginLogoImageAlternative = Url.RouteUrl(BackOfficeGraphicsController.LoginLogoAlternativeRouteName, new {Version= "1"});
28+
var loginBackgroundImage = Url.RouteUrl(BackOfficeGraphicsController.LoginBackGroundRouteName, new {Version= "1"});
2929
var usernameIsEmail = SecuritySettings.Value.UsernameIsEmail;
3030
var allowUserInvite = EmailSender.CanSendRequiredEmail();
3131
var allowPasswordReset = SecuritySettings.Value.AllowPasswordReset && EmailSender.CanSendRequiredEmail();
@@ -73,8 +73,8 @@
7373
}
7474
</style>
7575
<div id="noscript-container">
76-
<h1 class="uui-h3" style="display: inline-flex; align-items: center; gap: 10px">
77-
<img aria-hidden="true" alt="logo" src="@loginLogoImage" style="width: 100%" />
76+
<h1 aria-hidden="true" class="uui-h3" style="display: inline-flex; align-items: center; gap: 10px">
77+
<img alt="logo" src="@loginLogoImageAlternative" style="width: 100%" />
7878
</h1>
7979
<p>For full functionality of Umbraco CMS it is necessary to enable JavaScript.</p>
8080
<p>Here are the <a href="https://www.enable-javascript.com/" target="_blank" rel="noopener" style="text-decoration: underline;">instructions how to enable JavaScript in your web browser</a>.</p>

src/Umbraco.Cms.StaticAssets/umbraco/UmbracoWebsite/NoNodes.cshtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@using Microsoft.Extensions.Options
2+
@using Umbraco.Cms.Api.Management.Controllers.Security
23
@using Umbraco.Cms.Core.Configuration.Models
34
@using Umbraco.Cms.Core.Hosting
45
@using Umbraco.Cms.Core.Routing
@@ -8,6 +9,7 @@
89
@inject IOptions<GlobalSettings> globalSettings
910
@{
1011
var backOfficePath = globalSettings.Value.GetBackOfficePath(hostingEnvironment);
12+
var logoImage = Url.RouteUrl(BackOfficeGraphicsController.LogoRouteName, new {Version= "1"});
1113
}
1214
<!doctype html>
1315
<html class="no-js" lang="en">
@@ -26,7 +28,7 @@
2628
<article>
2729
<div>
2830
<div class="logo" aria-hidden="true">
29-
<img alt="Umbraco" src="umbraco/backoffice/assets/umbraco_logomark_white.svg" width="91" height="91" />
31+
<img alt="logo" src="@logoImage" height="91"/>
3032
</div>
3133

3234
<h1>Welcome to your Umbraco installation</h1>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Umbraco static assets
2+
3+
The files in this directory are static assets that are used by the Umbraco backoffice, installer, public-facing sites, and login screen. These files are served by the Umbraco backend and are not intended to be used by the front-end of your website.
4+
5+
## Structure
6+
7+
The assets are structured in the following way:
8+
9+
| Name | Description | Usage |
10+
| ---- |--------------------------------------------------------------------|---------------------------------------------------------------------------------|
11+
| `login.jpg` | The background image for the login screen. | /umbraco/management/api/v1/security/back-office/graphics/login-background |
12+
| `logo.svg` | The Umbraco logo for the Backoffice and other public facing sites. | /umbraco/management/api/v1/security/back-office/graphics/logo |
13+
| `logo_dark.svg` | The Umbraco logo in dark mode for the login screen. | /umbraco/management/api/v1/security/back-office/graphics/login-logo-alternative |
14+
| `logo_light.svg` | The Umbraco logo in light mode for the login screen. | /umbraco/management/api/v1/security/back-office/graphics/login-logo |
15+
16+
All assets are linked up through the BackOfficeGraphicsController which uses the constants defined in [ContentSettings](../../../../Umbraco.Core/Configuration/Models/ContentSettings.cs).

0 commit comments

Comments
 (0)