Skip to content

Commit

Permalink
clarify email as required with register/login #95 (#97)
Browse files Browse the repository at this point in the history
* use MapStaticAssets() instead UseStaticFiles()

* clarify email as required with register/login #95

* order MapStaticAssets() after Use*
  • Loading branch information
GeeSuth authored Nov 23, 2024
1 parent ed8e367 commit 625f34f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/Todo.Web/Server/bin/Debug/net8.0/Todo.Web.Server.dll",
"program": "${workspaceFolder}/Todo.Web/Server/bin/Debug/net9.0/Todo.Web.Server.dll",
"args": [],
"cwd": "${workspaceFolder}/Todo.Web/Server",
"launchSettingsProfile": "https",
Expand All @@ -37,7 +37,7 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/TodoApi/bin/Debug/net8.0/TodoApi.dll",
"program": "${workspaceFolder}/TodoApi/bin/Debug/net9.0/TodoApi.dll",
"args": [],
"cwd": "${workspaceFolder}/TodoApi",
"stopAtEntry": false,
Expand Down
18 changes: 9 additions & 9 deletions Todo.Web/Client/Components/LogInForm.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<EditForm Model="@this" class="form-horizontal py-5" OnValidSubmit="@Login">
<DataAnnotationsValidator />
<div class="mb-3">
<label for="username" class="form-label">User name</label>
<InputText id="username" class="form-control" @bind-Value="Username" />
<ValidationMessage For="@(() => Username)" />
<label for="email" class="form-label">Email</label>
<InputText id="email" class="form-control" @bind-Value="Email" />
<ValidationMessage For="@(() => Email)" />
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
Expand Down Expand Up @@ -34,8 +34,8 @@
string? alertMessage;

[Required]
[StringLength(15)]
public string? Username { get; set; }
[StringLength(256)]
public string? Email { get; set; }

[Required]
[StringLength(32, MinimumLength = 6, ErrorMessage = "The password must be between 6 and 32 characters long.")]
Expand All @@ -53,9 +53,9 @@
async Task Login()
{
alertMessage = null;
if (await Client.LoginAsync(Username, Password))
if (await Client.LoginAsync(Email, Password))
{
await OnLoggedIn.InvokeAsync(Username);
await OnLoggedIn.InvokeAsync(Email);
}
else
{
Expand All @@ -66,9 +66,9 @@
async Task Create()
{
alertMessage = null;
if (await Client.CreateUserAsync(Username, Password))
if (await Client.CreateUserAsync(Email, Password))
{
await OnLoggedIn.InvokeAsync(Username);
await OnLoggedIn.InvokeAsync(Email);
}
else
{
Expand Down
12 changes: 6 additions & 6 deletions Todo.Web/Client/TodoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,25 @@ public async Task<bool> DeleteTodoAsync(int id)
return (statusCode, todos);
}

public async Task<bool> LoginAsync(string? username, string? password)
public async Task<bool> LoginAsync(string? email, string? password)
{
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
{
return false;
}

var response = await client.PostAsJsonAsync("auth/login", new UserInfo { Email = username, Password = password });
var response = await client.PostAsJsonAsync("auth/login", new UserInfo { Email = email, Password = password });
return response.IsSuccessStatusCode;
}

public async Task<bool> CreateUserAsync(string? username, string? password)
public async Task<bool> CreateUserAsync(string? email, string? password)
{
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
{
return false;
}

var response = await client.PostAsJsonAsync("auth/register", new UserInfo { Email = username, Password = password });
var response = await client.PostAsJsonAsync("auth/register", new UserInfo { Email = email, Password = password });
return response.IsSuccessStatusCode;
}

Expand Down
2 changes: 1 addition & 1 deletion Todo.Web/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAntiforgery();

app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveWebAssemblyRenderMode();

Expand Down

0 comments on commit 625f34f

Please sign in to comment.