Skip to content

Commit

Permalink
feat(templates): add missing UI of change email in Boilerplate #7585 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
msynk authored May 26, 2024
1 parent 0f4df3b commit 1ba9364
Show file tree
Hide file tree
Showing 18 changed files with 414 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public async Task SendChangeEmailToken(SendEmailTokenRequestDto request, Cancell
throw new ResourceValidationException(result.Errors.Select(e => new LocalizedString(e.Code, e.Description)).ToArray());

var token = await userManager.GenerateUserTokenAsync(user!, TokenOptions.DefaultPhoneProvider, $"ChangeEmail:{request.Email},Date:{user.EmailTokenRequestedOn}");
var link = new Uri(HttpContext.Request.GetBaseUrl(), $"confirm?email={Uri.EscapeDataString(user.Email!)}&emailToken={Uri.EscapeDataString(token)}");
var link = new Uri(HttpContext.Request.GetBaseUrl(), $"profile?email={Uri.EscapeDataString(request.Email!)}&emailToken={Uri.EscapeDataString(token)}");

await emailService.SendEmailToken(user, request.Email!, token, link, cancellationToken);
}
Expand All @@ -103,13 +103,14 @@ public async Task ChangeEmail(ChangeEmailRequestDto request, CancellationToken c
{
var user = await userManager.FindByIdAsync(User.GetUserId().ToString());

var tokenIsVerified = await userManager.VerifyUserTokenAsync(user!, TokenOptions.DefaultPhoneProvider, $"ChangeEmail:{request.Email},Date:{user!.EmailTokenRequestedOn}", request.Token!);
var tokenIsValid = await userManager.VerifyUserTokenAsync(user!, TokenOptions.DefaultPhoneProvider, $"ChangeEmail:{request.Email},Date:{user!.EmailTokenRequestedOn}", request.Token!);

if (tokenIsVerified)
if (tokenIsValid is false)
throw new BadRequestException();

await ((IUserEmailStore<User>)userStore).SetEmailAsync(user!, request.Email, cancellationToken);
var result = await userManager.UpdateAsync(user!);

if (result.Succeeded is false)
throw new ResourceValidationException(result.Errors.Select(e => new LocalizedString(e.Code, e.Description)).ToArray());
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@
</data>
<data name="EditProfileTitle" xml:space="preserve">
<value>ویرایش پروفایل</value>
</data>
<data name="ChangeEmailTitle" xml:space="preserve">
<value>تغییر ایمیل</value>
</data>
<data name="NotFoundText" xml:space="preserve">
<value>چیزی پیدا نشد.</value>
Expand All @@ -221,6 +224,18 @@
</data>
<data name="Email" xml:space="preserve">
<value>ایمیل</value>
</data>
<data name="CurrentEmail" xml:space="preserve">
<value>ایمیل جاری</value>
</data>
<data name="NewEmail" xml:space="preserve">
<value>ایمیل جدید</value>
</data>
<data name="NewEmailPlaceholder" xml:space="preserve">
<value>ایمیل جدید را وارد کنید</value>
</data>
<data name="GoBack" xml:space="preserve">
<value>بازگشت</value>
</data>
<data name="PhoneNumber" xml:space="preserve">
<value>شماره تلفن</value>
Expand Down Expand Up @@ -320,6 +335,9 @@
</data>
<data name="ConfirmMessageInSignUp" xml:space="preserve">
<value>می خواهید یک حساب کاربری را تأیید کنید؟</value>
</data>
<data name="ConfirmMessageInProfile" xml:space="preserve">
<value>توکنی از قبل دارید؟</value>
</data>
<data name="ConfirmEmailHeaderText" xml:space="preserve">
<value>آدرس ایمیل</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@
</data>
<data name="EditProfileTitle" xml:space="preserve">
<value>Editer le profil</value>
</data>
<data name="ChangeEmailTitle" xml:space="preserve">
<value>Changer l'e-mail</value>
</data>
<data name="NotFoundText" xml:space="preserve">
<value>Il n'y a rien ici.</value>
Expand All @@ -220,7 +223,19 @@
<value>Confirmer le nouveau mot de passe</value>
</data>
<data name="Email" xml:space="preserve">
<value>E-mail</value>
<value>Email</value>
</data>
<data name="CurrentEmail" xml:space="preserve">
<value>Email actuel</value>
</data>
<data name="NewEmail" xml:space="preserve">
<value>Nouveau courriel</value>
</data>
<data name="NewEmailPlaceholder" xml:space="preserve">
<value>Entrez un nouvel e-mail</value>
</data>
<data name="GoBack" xml:space="preserve">
<value>Dos</value>
</data>
<data name="PhoneNumber" xml:space="preserve">
<value>Numéro de téléphone</value>
Expand Down Expand Up @@ -320,6 +335,9 @@
</data>
<data name="ConfirmMessageInSignUp" xml:space="preserve">
<value>Vous souhaitez confirmer un compte?</value>
</data>
<data name="ConfirmMessageInProfile" xml:space="preserve">
<value>Vous avez déjà un jeton?</value>
</data>
<data name="ConfirmEmailHeaderText" xml:space="preserve">
<value>Adresse e-mail</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@
</data>
<data name="EditProfileTitle" xml:space="preserve">
<value>Edit profile</value>
</data>
<data name="ChangeEmailTitle" xml:space="preserve">
<value>Change email</value>
</data>
<data name="NotFoundText" xml:space="preserve">
<value>There is nothing here.</value>
Expand All @@ -221,6 +224,18 @@
</data>
<data name="Email" xml:space="preserve">
<value>Email</value>
</data>
<data name="CurrentEmail" xml:space="preserve">
<value>Current email</value>
</data>
<data name="NewEmail" xml:space="preserve">
<value>New email</value>
</data>
<data name="NewEmailPlaceholder" xml:space="preserve">
<value>Enter new email</value>
</data>
<data name="GoBack" xml:space="preserve">
<value>Back</value>
</data>
<data name="PhoneNumber" xml:space="preserve">
<value>Phone Number</value>
Expand Down Expand Up @@ -320,6 +335,9 @@
</data>
<data name="ConfirmMessageInSignUp" xml:space="preserve">
<value>Want to confirm an account?</value>
</data>
<data name="ConfirmMessageInProfile" xml:space="preserve">
<value>Already have a token?</value>
</data>
<data name="ConfirmEmailHeaderText" xml:space="preserve">
<value>Email Address</value>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
@inherits AppComponentBase

<div>
@if (string.IsNullOrEmpty(message) is false)
{
<BitMessage Class="form-message-bar"
Severity="BitSeverity.Error"
OnDismiss="() => message = null">
@message
</BitMessage>
}

<BitTypography Variant="BitTypographyVariant.H2">
@Localizer[nameof(AppStrings.ChangeEmailTitle)]
</BitTypography>

<br />

@if (Loading)
{
<div class="loading-container">
<BitSpinner Size="BitSpinnerSize.Large" Label="Loading..." LabelPosition="BitLabelPosition.Top"></BitSpinner>
</div>
}
else
{
if (showConfirmation is false)
{
<EditForm Model="sendModel" OnValidSubmit="WrapHandled(SendToken)" class="change-email-form">
<AppDataAnnotationsValidator />

<div class="form-input-container">
<BitLabel>@Localizer[nameof(AppStrings.CurrentEmail)]</BitLabel>
<BitTag Appearance="BitAppearance.Standard" Text="@Email" Style="width:100%;max-width:unset" />
</div>

<div class="form-input-container">
<BitTextField @bind-Value="sendModel.Email"
Label="@Localizer[nameof(AppStrings.NewEmail)]"
Placeholder="@Localizer[nameof(AppStrings.NewEmailPlaceholder)]" />
<ValidationMessage For="@(() => sendModel.Email)" />
</div>

<BitButton IsLoading="isWaiting" ButtonType="BitButtonType.Submit">
@Localizer[nameof(AppStrings.Submit)]
</BitButton>
<br />
<div>
@Localizer[nameof(AppStrings.ConfirmMessageInProfile)]
<BitButton ButtonType="BitButtonType.Button"
ButtonStyle="BitButtonStyle.Text"
OnClick="() => showConfirmation = true">
@Localizer[nameof(AppStrings.Confirm)]
</BitButton>
</div>
</EditForm>
}
else
{
<BitTypography Variant="BitTypographyVariant.Subtitle1" Gutter>
@Localizer[nameof(AppStrings.ConfirmEmailSubtitle)]
<br />
@Localizer[nameof(AppStrings.ConfirmEmailMessage)]
</BitTypography>
<br />
<EditForm Model="changeModel" OnValidSubmit="WrapHandled(ChangeEmail)" class="change-email-form">
<AppDataAnnotationsValidator />

<div class="form-input-container">
<BitTextField @bind-Value="changeModel.Email"
IsEnabled="isEmailUnavailable"
Type="BitTextFieldType.Email"
Label="@Localizer[nameof(AppStrings.Email)]"
Placeholder="@Localizer[nameof(AppStrings.EmailPlaceholder)]" />
<ValidationMessage For="@(() => changeModel.Email)" />
</div>

<div class="form-input-container">
<BitTextField @bind-Value="changeModel.Token"
Type="BitTextFieldType.Number"
Label="@Localizer[nameof(AppStrings.EmailToken)]"
Placeholder="@Localizer[nameof(AppStrings.EmailTokenPlaceholder)]" />
<ValidationMessage For="@(() => changeModel.Token)" />
</div>
<br />
<BitButton IsLoading="isWaiting" ButtonType="BitButtonType.Submit">
@Localizer[nameof(AppStrings.EmailTokenConfirmButtonText)]
</BitButton>
<br />
<BitButton ButtonType="BitButtonType.Button"
ButtonStyle="BitButtonStyle.Text"
IconName="@BitIconName.Back"
OnClick="GoBack">
@Localizer[nameof(AppStrings.GoBack)]
</BitButton>
</EditForm>
@if (isEmailUnavailable is false)
{
<br />
<br />
<BitTypography Variant="BitTypographyVariant.Body1" Gutter>
@Localizer[nameof(AppStrings.NotReceivedConfirmationEmailMessage)]
</BitTypography>
<BitTypography Variant="BitTypographyVariant.Body1" Gutter>
@Localizer[nameof(AppStrings.CheckSpamMailMessage)]
</BitTypography>
<br />
<BitButton IsLoading="isWaiting"
ButtonType="BitButtonType.Button"
ButtonStyle="BitButtonStyle.Standard"
OnClick="WrapHandled(SendToken)">
@Localizer[nameof(AppStrings.ResendEmailTokenButtonText)]
</BitButton>
}
}
}
</div>
Loading

0 comments on commit 1ba9364

Please sign in to comment.