Skip to content

Commit

Permalink
Validate account name according to https://learn.microsoft.com/en-us/…
Browse files Browse the repository at this point in the history
  • Loading branch information
Seb G committed Oct 15, 2024
1 parent 192f006 commit eb8d1aa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 59 deletions.
63 changes: 11 additions & 52 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,9 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/AzureWebStorageExplorer/bin/Debug/net8.0/AzureWebStorageExplorer.dll",
"args": [],
"cwd": "${workspaceFolder}/src/AzureWebStorageExplorer",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"MOCK": "true"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": "BlazorWASM",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/wasm/bin/Debug/net8.0/wasm.dll",
"args": [],
"cwd": "${workspaceFolder}/src/wasm",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Blazor WEB",
"type": "coreclr",
Expand Down Expand Up @@ -89,10 +48,10 @@
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
2 changes: 1 addition & 1 deletion src/web/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<AzureStorageWebExplorerVersion>2.16.4</AzureStorageWebExplorerVersion>
<AzureStorageWebExplorerVersion>2.17.0</AzureStorageWebExplorerVersion>
</PropertyGroup>
</Project>
8 changes: 4 additions & 4 deletions src/web/Pages/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<div class="header">Sign in</div>
<div class="meta">Sign in with your Azure Key or Shared Access Signature</div>
<div class="description">
<div class="ui left icon input">
<input @bind="AzureAccount" type="text" placeholder="Azure account" @onkeyup="NavigateOnEnter">
<div class="ui left icon input @AccountClass">
<input @bind="AzureAccount" type="text" placeholder="Azure account" @onkeyup="NavigateOnEnter" @onblur="ValidateAccount">
<i class="user icon"></i>
</div>
<p></p>
Expand All @@ -26,7 +26,7 @@
<i class="linkify icon"></i>
</div>
@* <p></p> *@
@* <hr> *@
@* <hr> *@
<p style="font-weight: bold;">Or</p>

@* <p></p> *@
Expand All @@ -44,7 +44,7 @@

@if (ShowError)
{
<div class="ui left pointing red basic label">Invalid account or key</div>
<div class="ui left pointing red basic label">@AccountErrorMessage</div>
}
</div>
</div>
Expand Down
22 changes: 21 additions & 1 deletion src/web/Pages/Login.razor.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
using Microsoft.AspNetCore.Components.Web;
using StorageLibrary;
using web.Utils;

namespace web.Pages
Expand All @@ -12,6 +12,8 @@ public partial class Login
public bool ShowError { get; set; }
public string? ErrorMessage { get; set; }
public string? AzureAccount { get; set; } = "";
public string? AccountErrorMessage { get; set; } = "";
public string? AccountClass { get; set; } = "";
public string? AzureKey { get; set; } = "";
public string AzureUrl { get; set; } = "core.windows.net";
public string? ConnectionString { get; set; }
Expand All @@ -30,6 +32,23 @@ private void NavigateOnEnter(KeyboardEventArgs args)
}
}

private void ValidateAccount(FocusEventArgs args)
{
string validpattern = "^[a-z0-9]{3,24}$";
if (!Regex.IsMatch(AzureAccount!, validpattern))
{
ShowError = true;
AccountErrorMessage = $"Account is not a valid name";
AccountClass = "error";
}
else
{
ShowError = false;
AccountErrorMessage = string.Empty;
AccountClass = "";
}
}

protected override async Task OnInitializedAsync()
{
string? connString = Environment.GetEnvironmentVariable(Util.AZURE_STORAGE_CONNECTIONSTRING);
Expand Down Expand Up @@ -84,6 +103,7 @@ private async Task SignIn()
catch (Exception ex)
{
ShowError = true;
AccountErrorMessage = "Invalid account or account key";
ErrorMessage = ex.Message;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/web/Shared/Version.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="@Class">
<div class="version">
<a href="https://hub.docker.com/r/sebagomez/azurestorageexplorer">v @CurrentVersion</a> by <a href="https://twitter.com/sebagomez">@@sebagomez</a>
<div>Made with <a href="https://en.wikipedia.org/wiki/Mate_(drink)" title="Mate">🧉</a> in 🇺🇾 and 🇨🇦</div>
<div>Made with <a href="https://en.wikipedia.org/wiki/Mate_(drink)" title="Mate">🧉</a> in <i class="uy flag"></i> and <i class="ca flag"></i></div>
</div>
</div>
@code {
Expand Down

0 comments on commit eb8d1aa

Please sign in to comment.