From 2cefa5c94216f50d10aa909d2101a14a141e1497 Mon Sep 17 00:00:00 2001 From: Salih Date: Wed, 5 Jul 2023 17:46:20 +0300 Subject: [PATCH 1/2] Add extra properties to User Edit Modal --- .../Volo/Abp/Identity/IdentityUserDto.cs | 4 ++ .../Volo/Abp/Identity/Localization/en.json | 9 +++- .../Volo/Abp/Identity/Localization/tr.json | 9 +++- .../AbpIdentityWebAutoMapperProfile.cs | 4 ++ .../Pages/Identity/Users/EditModal.cshtml | 46 +++++++++++++++++++ .../Pages/Identity/Users/EditModal.cshtml.cs | 37 ++++++++++++++- 6 files changed, 106 insertions(+), 3 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserDto.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserDto.cs index 014b372d19..368ffaaf81 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserDto.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserDto.cs @@ -27,10 +27,14 @@ public class IdentityUserDto : ExtensibleFullAuditedEntityDto, IMultiTenan public bool IsActive { get; set; } public bool LockoutEnabled { get; set; } + + public int AccessFailedCount { get; set; } public DateTimeOffset? LockoutEnd { get; set; } public string ConcurrencyStamp { get; set; } public int EntityVersion { get; set; } + + public DateTimeOffset? LastPasswordChangeTime { get; set; } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/en.json b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/en.json index 724ec04300..82fe4be3f0 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/en.json +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/en.json @@ -113,6 +113,13 @@ "Description:Abp.Identity.SignIn.EnablePhoneNumberConfirmation": "Whether the phoneNumber can be confirmed by the user.", "Description:Abp.Identity.SignIn.RequireConfirmedPhoneNumber": "Whether a confirmed telephone number is required to sign in.", "Description:Abp.Identity.User.IsUserNameUpdateEnabled": "Whether the username can be updated by the user.", - "Description:Abp.Identity.User.IsEmailUpdateEnabled": "Whether the email can be updated by the user." + "Description:Abp.Identity.User.IsEmailUpdateEnabled": "Whether the email can be updated by the user.", + "Details": "Details", + "CreatedBy": "Created by", + "ModifiedBy": "Modified by", + "ModificationTime": "Modification time", + "PasswordChangedTime": "Password changed time", + "LockoutEnd": "Lockout end", + "AccessFailedCount": "Access failed count" } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/tr.json b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/tr.json index c8957dc3e7..ce5b29421a 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/tr.json +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/tr.json @@ -113,6 +113,13 @@ "Description:Abp.Identity.SignIn.EnablePhoneNumberConfirmation": "Oturum açmak için telefon numarası gerekli", "Description:Abp.Identity.SignIn.RequireConfirmedPhoneNumber": "Oturum açmak için onaylanmış bir telefon numarasının gerekli olup olmadığı.", "Description:Abp.Identity.User.IsUserNameUpdateEnabled": "Kullanıcı adının, kullanıcının kendisi tarafından güncellenebilirliği.", - "Description:Abp.Identity.User.IsEmailUpdateEnabled": "E-posta alanının, kullanıcının kendisi tarafından güncellenebilirliği" + "Description:Abp.Identity.User.IsEmailUpdateEnabled": "E-posta alanının, kullanıcının kendisi tarafından güncellenebilirliği", + "Details": "Detaylar", + "CreatedBy": "Oluşturan", + "ModifiedBy": "Düzenleyen", + "ModificationTime": "Düzenleme zamanı", + "PasswordChangedTime": "Şifre değiştirme zamanı", + "LockoutEnd": "Kilitlenme bitişi", + "AccessFailedCount": "Başarısız giriş denemesi sayısı" } } diff --git a/modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebAutoMapperProfile.cs b/modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebAutoMapperProfile.cs index 0fe498e49a..e032b3352f 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebAutoMapperProfile.cs +++ b/modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebAutoMapperProfile.cs @@ -35,6 +35,10 @@ public class AbpIdentityWebAutoMapperProfile : Profile CreateMap() .ForMember(dest => dest.IsAssigned, opt => opt.Ignore()); + + CreateMap() + .ForMember(dest => dest.CreatedBy, opt => opt.Ignore()) + .ForMember(dest => dest.ModifiedBy, opt => opt.Ignore()); } protected virtual void CreateRoleMappings() diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml index 28d0fd6da6..9262ee2a81 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml @@ -83,8 +83,54 @@ } + +
+
+ @L["CreatedBy"] : @ConvertUserFriendlyFormat(Model.Detail.CreatedBy) +
+
+ @L["CreationTime"] : @ConvertUserFriendlyFormat(Model.Detail.CreationTime) +
+
+ @L["ModifiedBy"] : @ConvertUserFriendlyFormat(Model.Detail.ModifiedBy) +
+
+ @L["ModificationTime"] : @ConvertUserFriendlyFormat(Model.Detail.LastModificationTime) +
+
+ @L["PasswordChangedTime"] : @ConvertUserFriendlyFormat(Model.Detail.LastPasswordChangeTime) +
+
+ @L["LockoutEnd"] : @ConvertUserFriendlyFormat(Model.Detail.LockoutEnd) +
+
+ @L["AccessFailedCount"] : @Model.Detail.AccessFailedCount +
+
+
+ +@functions +{ + const string DateTimeFormat = "MMMM dd, yyyy — HH:mm"; + const string DefaultEmptyValue = "-"; + + static string ConvertUserFriendlyFormat(DateTime? dateTime) + { + return dateTime == null ? DefaultEmptyValue : dateTime.Value.ToString(DateTimeFormat); + } + + static string ConvertUserFriendlyFormat(DateTimeOffset? dateTime) + { + return dateTime == null ? DefaultEmptyValue : dateTime.Value.ToString(DateTimeFormat); + } + + static string ConvertUserFriendlyFormat(string value) + { + return value.IsNullOrWhiteSpace() ? DefaultEmptyValue : value; + } +} diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs index 2b15d794ac..cf1b7a5a3f 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs @@ -19,6 +19,8 @@ public class EditModalModel : IdentityPageModel [BindProperty] public AssignedRoleViewModel[] Roles { get; set; } + + public DetailViewModel Detail { get; set; } protected IIdentityUserAppService IdentityUserAppService { get; } @@ -29,7 +31,9 @@ public class EditModalModel : IdentityPageModel public virtual async Task OnGetAsync(Guid id) { - UserInfo = ObjectMapper.Map(await IdentityUserAppService.GetAsync(id)); + var user = await IdentityUserAppService.GetAsync(id); + + UserInfo = ObjectMapper.Map(user); Roles = ObjectMapper.Map, AssignedRoleViewModel[]>((await IdentityUserAppService.GetAssignableRolesAsync()).Items); @@ -41,9 +45,25 @@ public class EditModalModel : IdentityPageModel role.IsAssigned = true; } } + + Detail = ObjectMapper.Map(user); + + Detail.CreatedBy = await GetUserNameOrNullAsync(user.CreatorId); + Detail.ModifiedBy = await GetUserNameOrNullAsync(user.LastModifierId); return Page(); } + + private async Task GetUserNameOrNullAsync(Guid? userId) + { + if (!userId.HasValue) + { + return null; + } + + var user = await IdentityUserAppService.GetAsync(userId.Value); + return user.UserName; + } public virtual async Task OnPostAsync() { @@ -100,4 +120,19 @@ public class EditModalModel : IdentityPageModel public bool IsAssigned { get; set; } } + + public class DetailViewModel + { + public string CreatedBy { get; set; } + public DateTime? CreationTime { get; set; } + + public string ModifiedBy { get; set; } + public DateTime? LastModificationTime { get; set; } + + public DateTimeOffset? LastPasswordChangeTime { get; set; } + + public DateTimeOffset? LockoutEnd { get; set; } + + public int AccessFailedCount { get; set; } + } } From b4dd0ca96aa0965d6a4d8092b04135ddc904d33f Mon Sep 17 00:00:00 2001 From: Salih Date: Fri, 7 Jul 2023 10:48:10 +0300 Subject: [PATCH 2/2] Refactor --- .../Volo/Abp/Identity/Localization/en.json | 6 +++--- .../Volo/Abp/Identity/Localization/tr.json | 6 +++--- .../Pages/Identity/Users/EditModal.cshtml | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/en.json b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/en.json index 82fe4be3f0..2446650c60 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/en.json +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/en.json @@ -118,8 +118,8 @@ "CreatedBy": "Created by", "ModifiedBy": "Modified by", "ModificationTime": "Modification time", - "PasswordChangedTime": "Password changed time", - "LockoutEnd": "Lockout end", - "AccessFailedCount": "Access failed count" + "PasswordUpdateTime": "Password update time", + "LockoutEndTime": "Lockout end time", + "FailedAccessCount": "Failed access count" } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/tr.json b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/tr.json index ce5b29421a..6d19fea5ea 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/tr.json +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/tr.json @@ -118,8 +118,8 @@ "CreatedBy": "Oluşturan", "ModifiedBy": "Düzenleyen", "ModificationTime": "Düzenleme zamanı", - "PasswordChangedTime": "Şifre değiştirme zamanı", - "LockoutEnd": "Kilitlenme bitişi", - "AccessFailedCount": "Başarısız giriş denemesi sayısı" + "PasswordUpdateTime": "Şifre güncelleme zamanı", + "LockoutEndTime": "Kilitlenme bitiş zamanı", + "FailedAccessCount": "Başarısız giriş denemesi sayısı" } } diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml index 9262ee2a81..079ffa01b9 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml @@ -98,13 +98,13 @@ @L["ModificationTime"] : @ConvertUserFriendlyFormat(Model.Detail.LastModificationTime)
- @L["PasswordChangedTime"] : @ConvertUserFriendlyFormat(Model.Detail.LastPasswordChangeTime) + @L["PasswordUpdateTime"] : @ConvertUserFriendlyFormat(Model.Detail.LastPasswordChangeTime)
- @L["LockoutEnd"] : @ConvertUserFriendlyFormat(Model.Detail.LockoutEnd) + @L["LockoutEndTime"] : @ConvertUserFriendlyFormat(Model.Detail.LockoutEnd)
- @L["AccessFailedCount"] : @Model.Detail.AccessFailedCount + @L["FailedAccessCount"] : @Model.Detail.AccessFailedCount
@@ -121,12 +121,12 @@ static string ConvertUserFriendlyFormat(DateTime? dateTime) { - return dateTime == null ? DefaultEmptyValue : dateTime.Value.ToString(DateTimeFormat); + return dateTime == null ? DefaultEmptyValue : dateTime.Value.ToUniversalTime().ToString(DateTimeFormat); } static string ConvertUserFriendlyFormat(DateTimeOffset? dateTime) { - return dateTime == null ? DefaultEmptyValue : dateTime.Value.ToString(DateTimeFormat); + return dateTime == null ? DefaultEmptyValue : dateTime.Value.UtcDateTime.ToString(DateTimeFormat); } static string ConvertUserFriendlyFormat(string value)