From 7960751630e408373c0516b88d8403bd766470c7 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 5 Sep 2019 10:43:38 +0300 Subject: [PATCH 1/2] added manage profile page --- .../Toolbar/UserMenu/Default.cshtml | 2 +- .../Account/Localization/Resources/en.json | 19 +++++- .../Volo.Abp.Account.HttpApi.csproj | 1 + .../Abp/Account/AbpAccountHttpApiModule.cs | 2 + .../AbpAccountUserMenuContributor.cs | 16 ++--- .../AbpAccountWebAutomapperProfile.cs | 14 ++++ .../AbpAccountWebModule.cs | 15 ++++- .../Pages/Account/Manage.cshtml | 50 ++++++++++++++ .../Pages/Account/Manage.cshtml.cs} | 43 +++++++----- .../Pages/Account/Manage.js | 50 ++++++++++++++ .../Volo.Abp.Account.Web.csproj | 2 + .../AbpIdentityWebAutoMapperProfile.cs | 12 ---- .../AbpIdentityWebModule.cs | 9 --- .../Shared/ChangePasswordModal.cshtml | 20 ------ .../Shared/ChangePasswordModal.cshtml.cs | 67 ------------------- .../Shared/PersonalSettingsModal.cshtml | 40 ----------- .../Identity/Shared/change-password-modal.js | 18 ----- .../Shared/personal-settings-modal.js | 18 ----- ...nyName.MyProjectName.IdentityServer.csproj | 1 + .../MyProjectNameIdentityServerModule.cs | 2 + .../Menus/MyProjectNameMenuContributor.cs | 16 ++++- .../MyProjectNameWebModule.cs | 6 +- 22 files changed, 204 insertions(+), 219 deletions(-) create mode 100644 modules/account/src/Volo.Abp.Account.Web/AbpAccountWebAutomapperProfile.cs create mode 100644 modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml rename modules/{identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml.cs => account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml.cs} (56%) create mode 100644 modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.js delete mode 100644 modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/ChangePasswordModal.cshtml delete mode 100644 modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/ChangePasswordModal.cshtml.cs delete mode 100644 modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml delete mode 100644 modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/change-password-modal.js delete mode 100644 modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/personal-settings-modal.js diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/Toolbar/UserMenu/Default.cshtml b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/Toolbar/UserMenu/Default.cshtml index 329737c3d2..9f8c9856f5 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/Toolbar/UserMenu/Default.cshtml +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/Toolbar/UserMenu/Default.cshtml @@ -21,7 +21,7 @@ var cssClass = string.IsNullOrEmpty(menuItem.CssClass) ? string.Empty : menuItem.CssClass; var disabled = menuItem.IsDisabled ? "disabled" : string.Empty; - + @menuItem.DisplayName } diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json index 892e60f89e..f5167f51f2 100644 --- a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json @@ -16,6 +16,23 @@ "Register": "Register", "InvalidLoginRequest": "Invalid login request", "ThereAreNoLoginSchemesConfiguredForThisClient": "There are no login schemes configured for this client.", - "LogInUsingYourProviderAccount": "Log in using your {0} account" + "LogInUsingYourProviderAccount": "Log in using your {0} account", + "DisplayName:CurrentPassword": "Current password", + "DisplayName:NewPassword": "New password", + "DisplayName:NewPasswordConfirm": "Confirm new password", + "PasswordChangedMessage": "Your password has been changed successfully.", + "DisplayName:UserName": "User name", + "DisplayName:Email": "Email", + "DisplayName:Name": "Name", + "DisplayName:Surname": "Surname", + "DisplayName:Password": "Password", + "DisplayName:EmailAddress": "Email address", + "DisplayName:PhoneNumber": "Phone number", + "PersonalSettings": "Personal settings", + "PersonalSettingsSaved": "Personal settings saved", + "PasswordChanged": "Password changed", + "NewPasswordConfirmFailed": "Please confirm the new password.", + "Manage": "Manage", + "ManageYourProfile": "Manage your profile" } } \ No newline at end of file diff --git a/modules/account/src/Volo.Abp.Account.HttpApi/Volo.Abp.Account.HttpApi.csproj b/modules/account/src/Volo.Abp.Account.HttpApi/Volo.Abp.Account.HttpApi.csproj index 8c028185c7..798c7e404e 100644 --- a/modules/account/src/Volo.Abp.Account.HttpApi/Volo.Abp.Account.HttpApi.csproj +++ b/modules/account/src/Volo.Abp.Account.HttpApi/Volo.Abp.Account.HttpApi.csproj @@ -12,6 +12,7 @@ + diff --git a/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AbpAccountHttpApiModule.cs b/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AbpAccountHttpApiModule.cs index 3a58d11643..0e210dd8de 100644 --- a/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AbpAccountHttpApiModule.cs +++ b/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AbpAccountHttpApiModule.cs @@ -1,6 +1,7 @@ using Localization.Resources.AbpUi; using Volo.Abp.Account.Localization; using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.Identity; using Volo.Abp.Localization; using Volo.Abp.Modularity; @@ -8,6 +9,7 @@ namespace Volo.Abp.Account { [DependsOn( typeof(AbpAccountApplicationContractsModule), + typeof(AbpIdentityHttpApiModule), typeof(AbpAspNetCoreMvcModule))] public class AbpAccountHttpApiModule : AbpModule { diff --git a/modules/account/src/Volo.Abp.Account.Web/AbpAccountUserMenuContributor.cs b/modules/account/src/Volo.Abp.Account.Web/AbpAccountUserMenuContributor.cs index 2741aabe82..9bdd8095ed 100644 --- a/modules/account/src/Volo.Abp.Account.Web/AbpAccountUserMenuContributor.cs +++ b/modules/account/src/Volo.Abp.Account.Web/AbpAccountUserMenuContributor.cs @@ -2,17 +2,13 @@ using Localization.Resources.AbpUi; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Localization; +using Volo.Abp.Account.Localization; using Volo.Abp.UI.Navigation; namespace Volo.Abp.Account.Web { public class AbpAccountUserMenuContributor : IMenuContributor { - public AbpAccountUserMenuContributor() - { - - } - public Task ConfigureMenuAsync(MenuConfigurationContext context) { if (context.Menu.Name != StandardMenus.User) @@ -20,13 +16,11 @@ namespace Volo.Abp.Account.Web return Task.CompletedTask; } - var l = context.ServiceProvider.GetRequiredService>(); - - context.Menu.AddItem(new ApplicationMenuItem("Account.ChangePassword", l["ChangePassword"], icon: "fa fa-key", url: "#", elementId: "abp-account-change-password")); - - context.Menu.AddItem(new ApplicationMenuItem("Account.PersonalSettings", l["PersonalInfo"], icon: "fa fa-info", url: "#", elementId: "abp-account-personal-settings")); + var uiResource = context.ServiceProvider.GetRequiredService>(); + var accountResource = context.ServiceProvider.GetRequiredService>(); - context.Menu.AddItem(new ApplicationMenuItem("Account.Logout", l["Logout"], url: "/Account/Logout", icon: "fa fa-power-off", order: int.MaxValue - 1000)); + context.Menu.AddItem(new ApplicationMenuItem("Account.Manage", accountResource["ManageYourProfile"], url: "/Account/Manage", icon: "fa fa-cog", order: 1000, null)); + context.Menu.AddItem(new ApplicationMenuItem("Account.Logout", uiResource["Logout"], url: "/Account/Logout", icon: "fa fa-power-off", order: int.MaxValue - 1000)); return Task.CompletedTask; } diff --git a/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebAutomapperProfile.cs b/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebAutomapperProfile.cs new file mode 100644 index 0000000000..ab7ea41269 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebAutomapperProfile.cs @@ -0,0 +1,14 @@ +using Volo.Abp.Account.Web.Pages.Account; +using Volo.Abp.Identity; +using AutoMapper; + +namespace Volo.Abp.Account.Web +{ + public class AbpAccountWebAutoMapperProfile : Profile + { + public AbpAccountWebAutoMapperProfile() + { + CreateMap(); + } + } +} diff --git a/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs b/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs index f7481b3485..5cada69450 100644 --- a/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs +++ b/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs @@ -1,8 +1,10 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Account.Localization; using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars; +using Volo.Abp.AutoMapper; using Volo.Abp.Identity.AspNetCore; using Volo.Abp.Modularity; using Volo.Abp.UI.Navigation; @@ -13,6 +15,7 @@ namespace Volo.Abp.Account.Web [DependsOn( typeof(AbpAccountHttpApiModule), typeof(AbpIdentityAspNetCoreModule), + typeof(AbpAutoMapperModule), typeof(AbpAspNetCoreMvcUiThemeSharedModule) )] public class AbpAccountWebModule : AbpModule @@ -41,6 +44,16 @@ namespace Volo.Abp.Account.Web { options.Contributors.Add(new AccountModuleToolbarContributor()); }); + + Configure(options => + { + options.Conventions.AuthorizePage("/Account/Manage"); + }); + + Configure(options => + { + options.AddProfile(validate: true); + }); } } } diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml new file mode 100644 index 0000000000..36c94271d1 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml @@ -0,0 +1,50 @@ +@page +@model Volo.Abp.Account.Web.Pages.Account.ManageModel +@using Volo.Abp.Identity.Settings +@using Volo.Abp.Settings +@using Volo.Abp.AspNetCore.Mvc.UI.Theming +@inject ISettingProvider SettingManager +@inject IThemeManager ThemeManager +@inherits Volo.Abp.Account.Web.Pages.Account.AccountPage +@{ + Layout = ThemeManager.CurrentTheme.GetApplicationLayout(); + 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); +} +@section scripts { + +} + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
\ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml.cs similarity index 56% rename from modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml.cs rename to modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml.cs index 8d1152b3fb..9fba470929 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml.cs @@ -1,18 +1,18 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; +using Volo.Abp.Identity; -namespace Volo.Abp.Identity.Web.Pages.Identity.Shared +namespace Volo.Abp.Account.Web.Pages.Account { - public class PersonalSettingsModal : AbpPageModel + public class ManageModel : AccountPageModel { - [BindProperty] + public ChangePasswordInfoModel ChangePasswordInfoModel { get; set; } + public PersonalSettingsInfoModel PersonalSettingsInfoModel { get; set; } - + private readonly IProfileAppService _profileAppService; - public PersonalSettingsModal(IProfileAppService profileAppService) + public ManageModel(IProfileAppService profileAppService) { _profileAppService = profileAppService; } @@ -23,19 +23,28 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Shared PersonalSettingsInfoModel = ObjectMapper.Map(user); } + } - public async Task OnPostAsync() - { - ValidateModel(); - - var updateDto = ObjectMapper.Map(PersonalSettingsInfoModel); + public class ChangePasswordInfoModel + { + [Required] + [StringLength(IdentityUserConsts.MaxPasswordLength)] + [Display(Name = "DisplayName:CurrentPassword")] + [DataType(DataType.Password)] + public string CurrentPassword { get; set; } - await _profileAppService.UpdateAsync(updateDto); + [Required] + [StringLength(IdentityUserConsts.MaxPasswordLength)] + [Display(Name = "DisplayName:NewPassword")] + [DataType(DataType.Password)] + public string NewPassword { get; set; } - return NoContent(); - } + [Required] + [StringLength(IdentityUserConsts.MaxPasswordLength)] + [Display(Name = "DisplayName:NewPasswordConfirm")] + [DataType(DataType.Password)] + public string NewPasswordConfirm { get; set; } } - public class PersonalSettingsInfoModel { [Required] diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.js b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.js new file mode 100644 index 0000000000..844151c71b --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.js @@ -0,0 +1,50 @@ +(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.currentPassword == '') { + abp.message.error(l("NewPasswordConfirmFailed")); + return; + } + + if (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); \ No newline at end of file diff --git a/modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj b/modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj index 86706f28d5..f06fb190ed 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj +++ b/modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj @@ -24,12 +24,14 @@ + + diff --git a/modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebAutoMapperProfile.cs b/modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebAutoMapperProfile.cs index 4c991466e9..c8651d8e88 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebAutoMapperProfile.cs +++ b/modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebAutoMapperProfile.cs @@ -1,6 +1,5 @@ using AutoMapper; using Volo.Abp.Identity.Web.Pages.Identity.Roles; -using Volo.Abp.Identity.Web.Pages.Identity.Shared; using CreateUserModalModel = Volo.Abp.Identity.Web.Pages.Identity.Users.CreateModalModel; using EditUserModalModel = Volo.Abp.Identity.Web.Pages.Identity.Users.EditModalModel; @@ -12,7 +11,6 @@ namespace Volo.Abp.Identity.Web { CreateUserMappings(); CreateRoleMappings(); - CreateProfileMappings(); } private void CreateUserMappings() @@ -33,10 +31,6 @@ namespace Volo.Abp.Identity.Web CreateMap() .ForMember(dest => dest.IsAssigned, opt => opt.Ignore()); - - CreateMap(); - - CreateMap(); } private void CreateRoleMappings() @@ -50,11 +44,5 @@ namespace Volo.Abp.Identity.Web //EditModal CreateMap(); } - - private void CreateProfileMappings() - { - CreateMap(); - CreateMap(); - } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebModule.cs b/modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebModule.cs index 072c8f3584..077499c48e 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebModule.cs +++ b/modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebModule.cs @@ -59,15 +59,6 @@ namespace Volo.Abp.Identity.Web options.Conventions.AuthorizePage("/Identity/Roles/CreateModal", IdentityPermissions.Roles.Create); options.Conventions.AuthorizePage("/Identity/Roles/EditModal", IdentityPermissions.Roles.Update); }); - - Configure(options => - { - options - .ScriptBundles - .Get(StandardBundles.Scripts.Global) - .AddFiles("/Pages/Identity/Shared/change-password-modal.js") - .AddFiles("/Pages/Identity/Shared/personal-settings-modal.js"); - }); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/ChangePasswordModal.cshtml b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/ChangePasswordModal.cshtml deleted file mode 100644 index 54bae13cbe..0000000000 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/ChangePasswordModal.cshtml +++ /dev/null @@ -1,20 +0,0 @@ -@page -@using Microsoft.AspNetCore.Mvc.Localization -@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal -@using Volo.Abp.Identity.Localization -@using Volo.Abp.Identity.Web.Pages.Identity.Shared -@model ChangePasswordModal -@inject IHtmlLocalizer L -@{ - Layout = null; -} - - - - - - - - - - \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/ChangePasswordModal.cshtml.cs b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/ChangePasswordModal.cshtml.cs deleted file mode 100644 index c698b6b6f6..0000000000 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/ChangePasswordModal.cshtml.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Localization; -using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; -using Volo.Abp.Identity.Localization; - -namespace Volo.Abp.Identity.Web.Pages.Identity.Shared -{ - public class ChangePasswordModal : AbpPageModel - { - [BindProperty] - public ChangePasswordInfoModel ChangePasswordInfoModel { get; set; } - - private readonly IProfileAppService _profileAppService; - private readonly IStringLocalizer _localizer; - - public ChangePasswordModal( - IProfileAppService profileAppService, - IStringLocalizer localizer) - { - _profileAppService = profileAppService; - _localizer = localizer; - } - - public async Task OnPostAsync() - { - ValidateModel(); - - if (ChangePasswordInfoModel.NewPassword != ChangePasswordInfoModel.NewPasswordConfirm) - { - throw new UserFriendlyException(_localizer.GetString("Identity.PasswordConfirmationFailed").Value); - } - - await _profileAppService.ChangePasswordAsync( - new ChangePasswordInput() - { - CurrentPassword = ChangePasswordInfoModel.CurrentPassword, - NewPassword = ChangePasswordInfoModel.NewPassword - } - ); - - return NoContent(); - } - } - - public class ChangePasswordInfoModel - { - [Required] - [StringLength(IdentityUserConsts.MaxPasswordLength)] - [Display(Name = "DisplayName:CurrentPassword")] - [DataType(DataType.Password)] - public string CurrentPassword { get; set; } - - [Required] - [StringLength(IdentityUserConsts.MaxPasswordLength)] - [Display(Name = "DisplayName:NewPassword")] - [DataType(DataType.Password)] - public string NewPassword { get; set; } - - [Required] - [StringLength(IdentityUserConsts.MaxPasswordLength)] - [Display(Name = "DisplayName:NewPasswordConfirm")] - [DataType(DataType.Password)] - public string NewPasswordConfirm { get; set; } - } -} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml deleted file mode 100644 index 4c18be54eb..0000000000 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml +++ /dev/null @@ -1,40 +0,0 @@ -@page -@using Microsoft.AspNetCore.Mvc.Localization -@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal -@using Volo.Abp.Identity.Localization -@using Volo.Abp.Identity.Settings -@using Volo.Abp.Identity.Web.Pages.Identity.Shared -@using Volo.Abp.Settings -@model PersonalSettingsModal -@inject IHtmlLocalizer L -@inject ISettingProvider SettingProvider -@{ - Layout = null; - var isUserNameUpdateEnabled = await SettingProvider.IsTrueAsync(IdentitySettingNames.User.IsUserNameUpdateEnabled); - var isEmailUpdateEnabled = await SettingProvider.IsTrueAsync(IdentitySettingNames.User.IsEmailUpdateEnabled); -} - -
- - - - - - - - - - - - - - - - - - - - - - -
\ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/change-password-modal.js b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/change-password-modal.js deleted file mode 100644 index c377ea718b..0000000000 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/change-password-modal.js +++ /dev/null @@ -1,18 +0,0 @@ -(function ($) { - - var l = abp.localization.getResource('AbpIdentity'); - var _changePasswordModal = new abp.ModalManager(abp.appPath + 'Identity/Shared/ChangePasswordModal'); - - $(function () { - - $("#abp-account-change-password").click(function (e) { - e.preventDefault(); - _changePasswordModal.open(); - }); - - _changePasswordModal.onResult(function () { - abp.message.success(l("PasswordChangedMessage")); - }); - }); - -})(jQuery); diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/personal-settings-modal.js b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/personal-settings-modal.js deleted file mode 100644 index 36cd526a29..0000000000 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/personal-settings-modal.js +++ /dev/null @@ -1,18 +0,0 @@ -(function ($) { - - var l = abp.localization.getResource('AbpIdentity'); - var _personalSettingsModal = new abp.ModalManager(abp.appPath + 'Identity/Shared/PersonalSettingsModal'); - - $(function () { - - $("#abp-account-personal-settings").click(function (e) { - e.preventDefault(); - _personalSettingsModal.open(); - }); - - _personalSettingsModal.onResult(function () { - //abp.message.success(l("PersonalSettingsSavedMessage")); - }); - }); - -})(jQuery); diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj index a13d76c3c1..d07eb744e8 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj @@ -44,6 +44,7 @@ + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs index a3b3bf27aa..48aba988b3 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs @@ -12,6 +12,7 @@ using MyCompanyName.MyProjectName.Localization; using MyCompanyName.MyProjectName.MultiTenancy; using StackExchange.Redis; using Volo.Abp; +using Volo.Abp.Account; using Volo.Abp.Account.Web; using Volo.Abp.AspNetCore.Mvc.UI; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap; @@ -31,6 +32,7 @@ namespace MyCompanyName.MyProjectName [DependsOn( typeof(AbpAutofacModule), typeof(AbpAccountWebIdentityServerModule), + typeof(AbpAccountApplicationModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule), typeof(MyProjectNameEntityFrameworkCoreDbMigrationsModule) )] diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/Menus/MyProjectNameMenuContributor.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/Menus/MyProjectNameMenuContributor.cs index 17162b42c7..6a8b55292c 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/Menus/MyProjectNameMenuContributor.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/Menus/MyProjectNameMenuContributor.cs @@ -1,8 +1,11 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Localization; using MyCompanyName.MyProjectName.Localization; using MyCompanyName.MyProjectName.MultiTenancy; +using Volo.Abp.Account.Localization; using Volo.Abp.TenantManagement.Web.Navigation; using Volo.Abp.UI.Navigation; @@ -10,6 +13,13 @@ namespace MyCompanyName.MyProjectName.Web.Menus { public class MyProjectNameMenuContributor : IMenuContributor { + private readonly IConfigurationRoot _configurationRoot; + + public MyProjectNameMenuContributor(IConfigurationRoot configurationRoot) + { + _configurationRoot = configurationRoot; + } + public async Task ConfigureMenuAsync(MenuConfigurationContext context) { if (context.Menu.Name == StandardMenus.Main) @@ -40,7 +50,11 @@ namespace MyCompanyName.MyProjectName.Web.Menus private Task ConfigureUserMenuAsync(MenuConfigurationContext context) { var l = context.ServiceProvider.GetRequiredService>(); + var accountStringLocalizer = context.ServiceProvider.GetRequiredService>(); + + var identityServerUrl = _configurationRoot["AuthServer:Authority"] ?? ""; + context.Menu.AddItem(new ApplicationMenuItem("Account.Manage", accountStringLocalizer["ManageYourProfile"], $"{identityServerUrl.EnsureEndsWith('/')}Account/Manage", icon: "fa fa-cog", order: 1000, null, "_blank")); context.Menu.AddItem(new ApplicationMenuItem("Account.Logout", l["Logout"], url: "/Account/Logout", icon: "fa fa-power-off", order: int.MaxValue - 1000)); return Task.CompletedTask; diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs index 301a53f28d..7c76ea4363 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs @@ -72,7 +72,7 @@ namespace MyCompanyName.MyProjectName.Web ConfigureAuthentication(context, configuration); ConfigureAutoMapper(); ConfigureVirtualFileSystem(hostingEnvironment); - ConfigureNavigationServices(); + ConfigureNavigationServices(configuration); ConfigureSwaggerServices(context.Services); ConfigureMultiTenancy(); } @@ -156,11 +156,11 @@ namespace MyCompanyName.MyProjectName.Web } } - private void ConfigureNavigationServices() + private void ConfigureNavigationServices(IConfigurationRoot configuration) { Configure(options => { - options.MenuContributors.Add(new MyProjectNameMenuContributor()); + options.MenuContributors.Add(new MyProjectNameMenuContributor(configuration)); }); } From 92f3cc02a774b32299c98c340fc913a8b662fe5b Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 20 Sep 2019 20:44:14 +0800 Subject: [PATCH 2/2] Revert "Add IIdentityStoreAutoSaveChanges." --- .../Abp/Identity/IdentityRoleAppService.cs | 48 +++++++---------- .../Abp/Identity/IdentityUserAppService.cs | 54 ++++++++----------- .../Identity/IIdentityStoreAutoSaveChanges.cs | 7 --- .../Volo/Abp/Identity/IdentityRoleManager.cs | 15 ------ .../Volo/Abp/Identity/IdentityRoleStore.cs | 1 - .../Volo/Abp/Identity/IdentityUserManager.cs | 15 ------ .../Volo/Abp/Identity/IdentityUserStore.cs | 1 - 7 files changed, 41 insertions(+), 100 deletions(-) delete mode 100644 modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityStoreAutoSaveChanges.cs diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs index a56b78ca2a..939d9739d2 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs @@ -41,54 +41,44 @@ namespace Volo.Abp.Identity [Authorize(IdentityPermissions.Roles.Create)] public async Task CreateAsync(IdentityRoleCreateDto input) { - using (_roleManager.AutoSaveRoleChanges(false)) - { - var role = new IdentityRole(GuidGenerator.Create(), input.Name, CurrentTenant.Id); + var role = new IdentityRole(GuidGenerator.Create(), input.Name, CurrentTenant.Id); - role.IsDefault = input.IsDefault; - role.IsPublic = input.IsPublic; + role.IsDefault = input.IsDefault; + role.IsPublic = input.IsPublic; - (await _roleManager.CreateAsync(role)).CheckErrors(); - await CurrentUnitOfWork.SaveChangesAsync(); + (await _roleManager.CreateAsync(role)).CheckErrors(); + await CurrentUnitOfWork.SaveChangesAsync(); - return ObjectMapper.Map(role); - } + return ObjectMapper.Map(role); } [Authorize(IdentityPermissions.Roles.Update)] public async Task UpdateAsync(Guid id, IdentityRoleUpdateDto input) { - using (_roleManager.AutoSaveRoleChanges(false)) - { - var role = await _roleManager.GetByIdAsync(id); - role.ConcurrencyStamp = input.ConcurrencyStamp; + var role = await _roleManager.GetByIdAsync(id); + role.ConcurrencyStamp = input.ConcurrencyStamp; - (await _roleManager.SetRoleNameAsync(role, input.Name)).CheckErrors(); + (await _roleManager.SetRoleNameAsync(role, input.Name)).CheckErrors(); - role.IsDefault = input.IsDefault; - role.IsPublic = input.IsPublic; + role.IsDefault = input.IsDefault; + role.IsPublic = input.IsPublic; - (await _roleManager.UpdateAsync(role)).CheckErrors(); - await CurrentUnitOfWork.SaveChangesAsync(); + (await _roleManager.UpdateAsync(role)).CheckErrors(); + await CurrentUnitOfWork.SaveChangesAsync(); - return ObjectMapper.Map(role); - } + return ObjectMapper.Map(role); } [Authorize(IdentityPermissions.Roles.Delete)] public async Task DeleteAsync(Guid id) { - using (_roleManager.AutoSaveRoleChanges(false)) + var role = await _roleManager.FindByIdAsync(id.ToString()); + if (role == null) { - var role = await _roleManager.FindByIdAsync(id.ToString()); - if (role == null) - { - return; - } - - (await _roleManager.DeleteAsync(role)).CheckErrors(); - await CurrentUnitOfWork.SaveChangesAsync(); + return; } + + (await _roleManager.DeleteAsync(role)).CheckErrors(); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs index df22e1b985..ad87b0041f 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs @@ -53,55 +53,45 @@ namespace Volo.Abp.Identity [Authorize(IdentityPermissions.Users.Create)] public async Task CreateAsync(IdentityUserCreateDto input) { - using (_userManager.AutoSaveUserChanges(false)) - { - var user = new IdentityUser(GuidGenerator.Create(), input.UserName, input.Email, CurrentTenant.Id); + var user = new IdentityUser(GuidGenerator.Create(), input.UserName, input.Email, CurrentTenant.Id); - (await _userManager.CreateAsync(user, input.Password)).CheckErrors(); - await UpdateUserByInput(user, input); + (await _userManager.CreateAsync(user, input.Password)).CheckErrors(); + await UpdateUserByInput(user, input); - await CurrentUnitOfWork.SaveChangesAsync(); + await CurrentUnitOfWork.SaveChangesAsync(); - return ObjectMapper.Map(user); - } + return ObjectMapper.Map(user); } [Authorize(IdentityPermissions.Users.Update)] public async Task UpdateAsync(Guid id, IdentityUserUpdateDto input) { - using (_userManager.AutoSaveUserChanges(false)) - { - var user = await _userManager.GetByIdAsync(id); - user.ConcurrencyStamp = input.ConcurrencyStamp; + var user = await _userManager.GetByIdAsync(id); + user.ConcurrencyStamp = input.ConcurrencyStamp; - (await _userManager.SetUserNameAsync(user, input.UserName)).CheckErrors(); - await UpdateUserByInput(user, input); - (await _userManager.UpdateAsync(user)).CheckErrors(); - await CurrentUnitOfWork.SaveChangesAsync(); + (await _userManager.SetUserNameAsync(user, input.UserName)).CheckErrors(); + await UpdateUserByInput(user, input); + (await _userManager.UpdateAsync(user)).CheckErrors(); + await CurrentUnitOfWork.SaveChangesAsync(); - return ObjectMapper.Map(user); - } + return ObjectMapper.Map(user); } [Authorize(IdentityPermissions.Users.Delete)] public async Task DeleteAsync(Guid id) { - using (_userManager.AutoSaveUserChanges(false)) + if (CurrentUser.Id == id) { - if (CurrentUser.Id == id) - { - throw new BusinessException(code: IdentityErrorCodes.UserSelfDeletion); - } - - var user = await _userManager.FindByIdAsync(id.ToString()); - if (user == null) - { - return; - } - - (await _userManager.DeleteAsync(user)).CheckErrors(); - await CurrentUnitOfWork.SaveChangesAsync(); + throw new BusinessException(code: IdentityErrorCodes.UserSelfDeletion); } + + var user = await _userManager.FindByIdAsync(id.ToString()); + if (user == null) + { + return; + } + + (await _userManager.DeleteAsync(user)).CheckErrors(); } [Authorize(IdentityPermissions.Users.Update)] diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityStoreAutoSaveChanges.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityStoreAutoSaveChanges.cs deleted file mode 100644 index af4cb3362f..0000000000 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityStoreAutoSaveChanges.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Volo.Abp.Identity -{ - public interface IIdentityStoreAutoSaveChanges - { - bool AutoSaveChanges { get; set; } - } -} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs index 429012bfca..c66d501146 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs @@ -69,20 +69,5 @@ namespace Volo.Abp.Identity return await base.DeleteAsync(role); } - - public IDisposable AutoSaveRoleChanges(bool autoSaveChanges) - { - if (!(Store is IIdentityStoreAutoSaveChanges store)) - { - throw new InvalidOperationException(Store.GetType().FullName + " does not support AutoSaveChanges"); - } - - var currentAutoSaveChanges = store.AutoSaveChanges; - store.AutoSaveChanges = autoSaveChanges; - return new DisposeAction(() => - { - store.AutoSaveChanges = currentAutoSaveChanges; - }); - } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs index 60c41ab0a8..175b051a48 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs @@ -20,7 +20,6 @@ namespace Volo.Abp.Identity public class IdentityRoleStore : IRoleStore, IRoleClaimStore, - IIdentityStoreAutoSaveChanges, ITransientDependency { private readonly IIdentityRoleRepository _roleRepository; diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs index 7212b8f0d2..dc4b2fe4b2 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs @@ -75,20 +75,5 @@ namespace Volo.Abp.Identity return IdentityResult.Success; } - - public IDisposable AutoSaveUserChanges(bool autoSaveChanges) - { - if (!(Store is IIdentityStoreAutoSaveChanges store)) - { - throw new InvalidOperationException(Store.GetType().FullName + " does not support AutoSaveChanges"); - } - - var currentAutoSaveChanges = store.AutoSaveChanges; - store.AutoSaveChanges = autoSaveChanges; - return new DisposeAction(() => - { - store.AutoSaveChanges = currentAutoSaveChanges; - }); - } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs index 9e302ef6c9..bac63a0c11 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs @@ -31,7 +31,6 @@ namespace Volo.Abp.Identity IUserAuthenticationTokenStore, IUserAuthenticatorKeyStore, IUserTwoFactorRecoveryCodeStore, - IIdentityStoreAutoSaveChanges, ITransientDependency { private const string InternalLoginProvider = "[AspNetUserStore]";