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

Remove handcoded error in user screens #14119

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,35 @@ public override async Task<IDisplayResult> EditAsync(User user, BuildEditorConte

var site = await _siteService.GetSiteSettingsAsync();
var settings = site.As<LoginSettings>();

var canEditUserInfo = await CanEditUserInfoAsync(user);
return Combine(
Initialize<EditUserNameViewModel>("UserName_Edit", async model =>
Initialize<EditUserNameViewModel>("UserName_Edit", model =>
{
model.UserName = user.UserName;

model.AllowEditing = context.IsNew || (settings.AllowChangingUsername && await CanEditUserInfoAsync(user));
model.AllowEditing = context.IsNew || (settings.AllowChangingUsername && canEditUserInfo);

}).Location("Content:1"),

Initialize<EditUserEmailViewModel>("UserEmail_Edit", async model =>
Initialize<EditUserEmailViewModel>("UserEmail_Edit", model =>
{
model.Email = user.Email;

model.AllowEditing = context.IsNew || (settings.AllowChangingEmail && await CanEditUserInfoAsync(user));
model.AllowEditing = context.IsNew || (settings.AllowChangingEmail && canEditUserInfo);

}).Location("Content:1.3"),

Initialize<EditUserPhoneNumberViewModel>("UserPhoneNumber_Edit", async model =>
Initialize<EditUserPhoneNumberViewModel>("UserPhoneNumber_Edit", model =>
{
model.PhoneNumber = user.PhoneNumber;
model.PhoneNumberConfirmed = user.PhoneNumberConfirmed;

model.AllowEditing = context.IsNew || await CanEditUserInfoAsync(user);
model.AllowEditing = context.IsNew || canEditUserInfo;

}).Location("Content:1.3")
);
}


public override async Task<IDisplayResult> UpdateAsync(User user, UpdateEditorContext context)
{
if (!await _authorizationService.AuthorizeAsync(_httpContextAccessor.HttpContext.User, CommonPermissions.EditUsers, user))
Expand Down Expand Up @@ -104,20 +103,22 @@ public override async Task<IDisplayResult> UpdateAsync(User user, UpdateEditorCo
{
var site = await _siteService.GetSiteSettingsAsync();
var settings = site.As<LoginSettings>();

if (settings.AllowChangingUsername && await CanEditUserInfoAsync(user) && await context.Updater.TryUpdateModelAsync(userNameModel, Prefix))
{
user.UserName = userNameModel.UserName;
}

if (settings.AllowChangingEmail && await CanEditUserInfoAsync(user) && await context.Updater.TryUpdateModelAsync(emailModel, Prefix))
{
user.Email = emailModel.Email;
}

if (await CanEditUserInfoAsync(user) && await context.Updater.TryUpdateModelAsync(phoneNumberModel, Prefix))
if (await CanEditUserInfoAsync(user))
{
user.PhoneNumber = phoneNumberModel.PhoneNumber;
if (settings.AllowChangingUsername && await context.Updater.TryUpdateModelAsync(userNameModel, Prefix))
{
user.UserName = userNameModel.UserName;
}

if (settings.AllowChangingEmail && await context.Updater.TryUpdateModelAsync(emailModel, Prefix))
{
user.Email = emailModel.Email;
}

if (await context.Updater.TryUpdateModelAsync(phoneNumberModel, Prefix))
{
user.PhoneNumber = phoneNumberModel.PhoneNumber;
}
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<div class="input-group col-md-4">
<span class="input-group-text"><i class="fa-solid fa-envelope" aria-hidden="true"></i></span>
<input asp-for="Email" class="form-control" type="email" asp-is-disabled="@(!Model.AllowEditing)" />
<span asp-validation-for="Email" class="text-danger">@T["The email is invalid."]</span>
<span asp-validation-for="Email" class="text-danger"></span>
</div>
</div>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<div class="input-group col-md-4">
<span class="input-group-text"><i class="fa-solid fa-user" aria-hidden="true"></i></span>
<input asp-for="UserName" class="form-control" autofocus asp-is-disabled="@(!Model.AllowEditing)" />
<span asp-validation-for="UserName" class="text-danger">@T["The user name is required."]</span>
<span asp-validation-for="UserName" class="text-danger"></span>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
}
</span>
</div>
<span asp-validation-for="PhoneNumber" class="text-danger"></span>
</div>