Skip to content

Commit

Permalink
clarify email as required with register/login #95
Browse files Browse the repository at this point in the history
  • Loading branch information
GeeSuth committed Nov 19, 2024
1 parent 4871935 commit d910f16
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
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

0 comments on commit d910f16

Please sign in to comment.