mirror of https://github.com/abpframework/abp.git
19 changed files with 417 additions and 168 deletions
@ -0,0 +1,59 @@ |
|||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
using Volo.Abp.Auditing; |
||||
|
using Volo.Abp.Identity; |
||||
|
using Volo.Abp.Validation; |
||||
|
|
||||
|
namespace Volo.Abp.Account.Web.Pages.Account.Components.ProfileManagementGroup.Password |
||||
|
{ |
||||
|
public class AccountProfilePasswordManagementGroupViewComponent : AbpViewComponent |
||||
|
{ |
||||
|
private readonly IProfileAppService _profileAppService; |
||||
|
|
||||
|
public AccountProfilePasswordManagementGroupViewComponent( |
||||
|
IProfileAppService profileAppService) |
||||
|
{ |
||||
|
_profileAppService = profileAppService; |
||||
|
} |
||||
|
|
||||
|
public async Task<IViewComponentResult> InvokeAsync() |
||||
|
{ |
||||
|
var user = await _profileAppService.GetAsync(); |
||||
|
|
||||
|
var model = new ChangePasswordInfoModel |
||||
|
{ |
||||
|
HideOldPasswordInput = !user.HasPassword |
||||
|
}; |
||||
|
|
||||
|
return View("~/Pages/Account/Components/ProfileManagementGroup/Password/Default.cshtml", model); |
||||
|
} |
||||
|
|
||||
|
public class ChangePasswordInfoModel |
||||
|
{ |
||||
|
[Required] |
||||
|
[DynamicStringLength(typeof(IdentityUserConsts), nameof(IdentityUserConsts.MaxPasswordLength))] |
||||
|
[Display(Name = "DisplayName:CurrentPassword")] |
||||
|
[DataType(DataType.Password)] |
||||
|
[DisableAuditing] |
||||
|
public string CurrentPassword { get; set; } |
||||
|
|
||||
|
[Required] |
||||
|
[DynamicStringLength(typeof(IdentityUserConsts), nameof(IdentityUserConsts.MaxPasswordLength))] |
||||
|
[Display(Name = "DisplayName:NewPassword")] |
||||
|
[DataType(DataType.Password)] |
||||
|
[DisableAuditing] |
||||
|
public string NewPassword { get; set; } |
||||
|
|
||||
|
[Required] |
||||
|
[DynamicStringLength(typeof(IdentityUserConsts), nameof(IdentityUserConsts.MaxPasswordLength))] |
||||
|
[Display(Name = "DisplayName:NewPasswordConfirm")] |
||||
|
[DataType(DataType.Password)] |
||||
|
[DisableAuditing] |
||||
|
public string NewPasswordConfirm { get; set; } |
||||
|
|
||||
|
public bool HideOldPasswordInput { get; set; } |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
@using Volo.Abp.Account.Localization |
||||
|
@using Volo.Abp.Users |
||||
|
@using Microsoft.AspNetCore.Mvc.Localization |
||||
|
@inject IHtmlLocalizer<AccountResource> L |
||||
|
@inject ICurrentUser CurrentUser |
||||
|
@model Volo.Abp.Account.Web.Pages.Account.Components.ProfileManagementGroup.Password.AccountProfilePasswordManagementGroupViewComponent.ChangePasswordInfoModel |
||||
|
|
||||
|
<h4>@L["ChangePassword"]</h4><hr/> |
||||
|
<form id="ChangePasswordForm"> |
||||
|
@if (!Model.HideOldPasswordInput) |
||||
|
{ |
||||
|
<abp-input asp-for="CurrentPassword"/> |
||||
|
} |
||||
|
<abp-input asp-for="NewPassword"/> |
||||
|
<abp-input asp-for="NewPasswordConfirm"/> |
||||
|
<abp-button type="submit" button-type="Primary" text="@L["Submit"].Value"/> |
||||
|
</form> |
||||
@ -0,0 +1,31 @@ |
|||||
|
(function ($) { |
||||
|
$(function () { |
||||
|
var l = abp.localization.getResource("AbpAccount"); |
||||
|
|
||||
|
$('#ChangePasswordForm').submit(function (e) { |
||||
|
e.preventDefault(); |
||||
|
|
||||
|
if (!$('#ChangePasswordForm').valid()) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
var input = $('#ChangePasswordForm').serializeFormToObject(); |
||||
|
|
||||
|
if ( |
||||
|
input.newPassword != input.newPasswordConfirm || |
||||
|
input.newPassword == '' |
||||
|
) { |
||||
|
abp.message.error(l('NewPasswordConfirmFailed')); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
if (input.currentPassword && input.currentPassword == ''){ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
volo.abp.identity.profile.changePassword(input).then(function (result) { |
||||
|
abp.message.success(l('PasswordChanged')); |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
|
})(jQuery); |
||||
@ -0,0 +1,56 @@ |
|||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
using Volo.Abp.Identity; |
||||
|
using Volo.Abp.Validation; |
||||
|
|
||||
|
namespace Volo.Abp.Account.Web.Pages.Account.Components.ProfileManagementGroup.PersonalInfo |
||||
|
{ |
||||
|
public class AccountProfilePersonalInfoManagementGroupViewComponent : AbpViewComponent |
||||
|
{ |
||||
|
private readonly IProfileAppService _profileAppService; |
||||
|
|
||||
|
public AccountProfilePersonalInfoManagementGroupViewComponent( |
||||
|
IProfileAppService profileAppService) |
||||
|
{ |
||||
|
_profileAppService = profileAppService; |
||||
|
|
||||
|
ObjectMapperContext = typeof(AbpAccountWebModule); |
||||
|
} |
||||
|
|
||||
|
public async Task<IViewComponentResult> InvokeAsync() |
||||
|
{ |
||||
|
var user = await _profileAppService.GetAsync(); |
||||
|
|
||||
|
var model = ObjectMapper.Map<ProfileDto, PersonalInfoModel>(user); |
||||
|
|
||||
|
return View("~/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.cshtml", model); |
||||
|
} |
||||
|
|
||||
|
public class PersonalInfoModel |
||||
|
{ |
||||
|
[Required] |
||||
|
[DynamicStringLength(typeof(IdentityUserConsts), nameof(IdentityUserConsts.MaxUserNameLength))] |
||||
|
[Display(Name = "DisplayName:UserName")] |
||||
|
public string UserName { get; set; } |
||||
|
|
||||
|
[Required] |
||||
|
[DynamicStringLength(typeof(IdentityUserConsts), nameof(IdentityUserConsts.MaxEmailLength))] |
||||
|
[Display(Name = "DisplayName:Email")] |
||||
|
public string Email { get; set; } |
||||
|
|
||||
|
[DynamicStringLength(typeof(IdentityUserConsts), nameof(IdentityUserConsts.MaxNameLength))] |
||||
|
[Display(Name = "DisplayName:Name")] |
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
[DynamicStringLength(typeof(IdentityUserConsts), nameof(IdentityUserConsts.MaxSurnameLength))] |
||||
|
[Display(Name = "DisplayName:Surname")] |
||||
|
public string Surname { get; set; } |
||||
|
|
||||
|
[DynamicStringLength(typeof(IdentityUserConsts), nameof(IdentityUserConsts.MaxPhoneNumberLength))] |
||||
|
[Display(Name = "DisplayName:PhoneNumber")] |
||||
|
public string PhoneNumber { get; set; } |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
@using Volo.Abp.Account.Localization |
||||
|
@using Volo.Abp.Users |
||||
|
@using Microsoft.AspNetCore.Mvc.Localization |
||||
|
@using Volo.Abp.AspNetCore.Mvc.UI.Theming |
||||
|
@using Volo.Abp.Identity.Settings |
||||
|
@using Volo.Abp.Settings |
||||
|
@inject IHtmlLocalizer<AccountResource> L |
||||
|
@inject ICurrentUser CurrentUser |
||||
|
@inject ISettingProvider SettingManager |
||||
|
@inject IThemeManager ThemeManager |
||||
|
@model Volo.Abp.Account.Web.Pages.Account.Components.ProfileManagementGroup.PersonalInfo.AccountProfilePersonalInfoManagementGroupViewComponent.PersonalInfoModel |
||||
|
@{ |
||||
|
var isUserNameUpdateEnabled = string.Equals(await SettingManager.GetOrNullAsync(IdentitySettingNames.User.IsUserNameUpdateEnabled), "true", |
||||
|
StringComparison.OrdinalIgnoreCase); |
||||
|
|
||||
|
var isEmailUpdateEnabled = string.Equals(await SettingManager.GetOrNullAsync(IdentitySettingNames.User.IsEmailUpdateEnabled), "true", |
||||
|
StringComparison.OrdinalIgnoreCase); |
||||
|
} |
||||
|
|
||||
|
<h4>@L["PersonalSettings"]</h4><hr/> |
||||
|
<form method="post" id="PersonalSettingsForm"> |
||||
|
|
||||
|
<abp-input asp-for="UserName" readonly="!isUserNameUpdateEnabled"/> |
||||
|
|
||||
|
<abp-row> |
||||
|
<abp-column size-md="_6"> |
||||
|
<abp-input asp-for="Name"/> |
||||
|
</abp-column> |
||||
|
<abp-column size-md="_6"> |
||||
|
<abp-input asp-for="Surname"/> |
||||
|
</abp-column> |
||||
|
</abp-row> |
||||
|
|
||||
|
<abp-input asp-for="Email" readonly="!isEmailUpdateEnabled"/> |
||||
|
|
||||
|
<abp-input asp-for="PhoneNumber"/> |
||||
|
|
||||
|
<abp-button type="submit" button-type="Primary" text="@L["Submit"].Value"/> |
||||
|
</form> |
||||
@ -0,0 +1,19 @@ |
|||||
|
(function ($) { |
||||
|
$(function () { |
||||
|
var l = abp.localization.getResource("AbpAccount"); |
||||
|
|
||||
|
$('#PersonalSettingsForm').submit(function (e) { |
||||
|
e.preventDefault(); |
||||
|
|
||||
|
if (!$('#PersonalSettingsForm').valid()) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
var input = $('#PersonalSettingsForm').serializeFormToObject(); |
||||
|
|
||||
|
volo.abp.identity.profile.update(input).then(function (result) { |
||||
|
abp.notify.success(l('PersonalSettingsSaved')); |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
|
})(jQuery); |
||||
@ -1,47 +0,0 @@ |
|||||
(function ($) { |
|
||||
var l = abp.localization.getResource('AbpAccount'); |
|
||||
|
|
||||
var _profileService = volo.abp.identity.profile; |
|
||||
|
|
||||
$('#ChangePasswordForm').submit(function (e) { |
|
||||
e.preventDefault(); |
|
||||
|
|
||||
if (!$('#ChangePasswordForm').valid()) { |
|
||||
return false; |
|
||||
} |
|
||||
|
|
||||
var input = $('#ChangePasswordForm').serializeFormToObject() |
|
||||
.changePasswordInfoModel; |
|
||||
|
|
||||
if ( |
|
||||
input.newPassword != input.newPasswordConfirm || |
|
||||
input.newPassword == '' |
|
||||
) { |
|
||||
abp.message.error(l('NewPasswordConfirmFailed')); |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
if (input.currentPassword && input.currentPassword == ''){ |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
_profileService.changePassword(input).then(function (result) { |
|
||||
abp.message.success(l('PasswordChanged')); |
|
||||
}); |
|
||||
}); |
|
||||
|
|
||||
$('#PersonalSettingsForm').submit(function (e) { |
|
||||
e.preventDefault(); |
|
||||
|
|
||||
if (!$('#PersonalSettingsForm').valid()) { |
|
||||
return false; |
|
||||
} |
|
||||
|
|
||||
var input = $('#PersonalSettingsForm').serializeFormToObject() |
|
||||
.personalSettingsInfoModel; |
|
||||
|
|
||||
_profileService.update(input).then(function (result) { |
|
||||
abp.notify.success(l('PersonalSettingsSaved')); |
|
||||
}); |
|
||||
}); |
|
||||
})(jQuery); |
|
||||
@ -0,0 +1,48 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Localization; |
||||
|
using Volo.Abp.Account.Localization; |
||||
|
using Volo.Abp.Account.Web.Pages.Account.Components.ProfileManagementGroup.Password; |
||||
|
using Volo.Abp.Account.Web.Pages.Account.Components.ProfileManagementGroup.PersonalInfo; |
||||
|
using Volo.Abp.Identity; |
||||
|
using Volo.Abp.Users; |
||||
|
|
||||
|
namespace Volo.Abp.Account.Web.ProfileManagement |
||||
|
{ |
||||
|
public class AccountProfileManagementPageContributor : IProfileManagementPageContributor |
||||
|
{ |
||||
|
public async Task ConfigureAsync(ProfileManagementPageCreationContext context) |
||||
|
{ |
||||
|
var l = context.ServiceProvider.GetRequiredService<IStringLocalizer<AccountResource>>(); |
||||
|
|
||||
|
if (await IsPasswordChangeEnabled(context)) |
||||
|
{ |
||||
|
context.Groups.Add( |
||||
|
new ProfileManagementPageGroup( |
||||
|
"Volo.Abp.Account.Password", |
||||
|
l["ProfileTab:Password"], |
||||
|
typeof(AccountProfilePasswordManagementGroupViewComponent) |
||||
|
) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
context.Groups.Add( |
||||
|
new ProfileManagementPageGroup( |
||||
|
"Volo.Abp.Account.PersonalInfo", |
||||
|
l["ProfileTab:PersonalInfo"], |
||||
|
typeof(AccountProfilePersonalInfoManagementGroupViewComponent) |
||||
|
) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task<bool> IsPasswordChangeEnabled(ProfileManagementPageCreationContext context) |
||||
|
{ |
||||
|
var userManager = context.ServiceProvider.GetRequiredService<IdentityUserManager>(); |
||||
|
var currentUser = context.ServiceProvider.GetRequiredService<ICurrentUser>(); |
||||
|
|
||||
|
var user = await userManager.GetByIdAsync(currentUser.GetId()); |
||||
|
|
||||
|
return !user.IsExternal; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.Account.Web.ProfileManagement |
||||
|
{ |
||||
|
public interface IProfileManagementPageContributor |
||||
|
{ |
||||
|
Task ConfigureAsync(ProfileManagementPageCreationContext context); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Abp.Account.Web.ProfileManagement |
||||
|
{ |
||||
|
public class ProfileManagementPageCreationContext |
||||
|
{ |
||||
|
public IServiceProvider ServiceProvider { get; } |
||||
|
|
||||
|
public List<ProfileManagementPageGroup> Groups { get; } |
||||
|
|
||||
|
public ProfileManagementPageCreationContext(IServiceProvider serviceProvider) |
||||
|
{ |
||||
|
ServiceProvider = serviceProvider; |
||||
|
|
||||
|
Groups = new List<ProfileManagementPageGroup>(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
using System; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.Account.Web.ProfileManagement |
||||
|
{ |
||||
|
public class ProfileManagementPageGroup |
||||
|
{ |
||||
|
public string Id |
||||
|
{ |
||||
|
get => _id; |
||||
|
set => _id = Check.NotNullOrWhiteSpace(value, nameof(Id)); |
||||
|
} |
||||
|
private string _id; |
||||
|
|
||||
|
public string DisplayName |
||||
|
{ |
||||
|
get => _displayName; |
||||
|
set => _displayName = Check.NotNullOrWhiteSpace(value, nameof(DisplayName)); |
||||
|
} |
||||
|
private string _displayName; |
||||
|
|
||||
|
public Type ComponentType |
||||
|
{ |
||||
|
get => _componentType; |
||||
|
set => _componentType = Check.NotNull(value, nameof(ComponentType)); |
||||
|
} |
||||
|
private Type _componentType; |
||||
|
|
||||
|
public object Parameter { get; set; } |
||||
|
|
||||
|
public ProfileManagementPageGroup([NotNull] string id, [NotNull] string displayName, [NotNull] Type componentType, object parameter = null) |
||||
|
{ |
||||
|
Id = id; |
||||
|
DisplayName = displayName; |
||||
|
ComponentType = componentType; |
||||
|
Parameter = parameter; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Abp.Account.Web.ProfileManagement |
||||
|
{ |
||||
|
public class ProfileManagementPageOptions |
||||
|
{ |
||||
|
public List<IProfileManagementPageContributor> Contributors { get; } |
||||
|
|
||||
|
public ProfileManagementPageOptions() |
||||
|
{ |
||||
|
Contributors = new List<IProfileManagementPageContributor>(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue