Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clarify email as required with register/login #95 #97

Merged
merged 3 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,7 +40,7 @@
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.MapStaticAssets();
davidfowl marked this conversation as resolved.
Show resolved Hide resolved
app.UseAntiforgery();

app.MapRazorComponents<App>()
Expand Down
Loading