Browse Source

Implemented user password change.

pull/441/head
Alper Ebicoglu 8 years ago
parent
commit
15560b36e6
  1. 10
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/Menu/Default.cshtml
  2. 12
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/Toolbar/UserMenu/Default.cshtml
  3. 23
      framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuItem.cs
  4. 3
      framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json
  5. 3
      framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json
  6. 4
      modules/account/src/Volo.Abp.Account.Web/AbpAccountUserMenuContributor.cs
  7. 2
      modules/account/src/Volo.Abp.Account.Web/Localization/Resources/AbpAccount/Web/tr.json
  8. 2
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs
  9. 13
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs
  10. 3
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Localization/Domain/en.json
  11. 3
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Localization/Domain/tr.json
  12. 6
      modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs
  13. 10
      modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebModule.cs
  14. 6
      modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/en.json
  15. 6
      modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/tr.json
  16. 20
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/ChangePasswordModal.cshtml
  17. 61
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/ChangePasswordModal.cshtml.cs
  18. 18
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/change-password-modal.js
  19. 1
      modules/identity/src/Volo.Abp.Identity.Web/Volo.Abp.Identity.Web.csproj

10
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/Menu/Default.cshtml

@ -2,6 +2,10 @@
@model ApplicationMenu
@foreach (var menuItem in Model.Items)
{
var elementId = string.IsNullOrEmpty(menuItem.ElementId) ? string.Empty : $"id=\"{menuItem.ElementId}\"";
var cssClass = string.IsNullOrEmpty(menuItem.CssClass) ? string.Empty : menuItem.CssClass;
var disabled = menuItem.IsDisabled ? "disabled" : string.Empty;
if (menuItem.IsLeaf)
{
if (menuItem.Url == null)
@ -9,7 +13,7 @@
continue;
}
<li class="nav-item @(menuItem.IsDisabled ? "disabled" : "")">
<li class="nav-item @cssClass @disabled" @elementId>
<a class="nav-link" href="@(menuItem.Url ?? "#")">
@if (menuItem.Icon != null)
{
@ -29,7 +33,9 @@
<div class="dropdown-menu" aria-labelledby="Menu_@(menuItem.Name)">
@foreach (var childMenuItem in menuItem.Items)
{
<a class="dropdown-item" href="@(childMenuItem.Url ?? "#")">@childMenuItem.DisplayName</a>
<a class="dropdown-item @cssClass @disabled" href="@(childMenuItem.Url ?? "#")" @Html.Raw(elementId)>
@childMenuItem.DisplayName
</a>
}
</div>
</li>

12
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/Toolbar/UserMenu/Default.cshtml

@ -11,16 +11,20 @@
<a class="btn btn-link dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
@CurrentUser.UserName
</a>
@if (Model.Items.Any())
{
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
@foreach (var menuItem in Model.Items)
{
<a class="dropdown-item" href="@menuItem.Url">@menuItem.DisplayName</a>
}
var elementId = string.IsNullOrEmpty(menuItem.ElementId) ? string.Empty : $"id=\"{menuItem.ElementId}\"";
var cssClass = string.IsNullOrEmpty(menuItem.CssClass) ? string.Empty : menuItem.CssClass;
var disabled = menuItem.IsDisabled ? "disabled" : string.Empty;
@*<a class="dropdown-item" href="/Account/Logout">@L["Logout"]</a>*@
<a class="dropdown-item @cssClass @disabled" href="@(menuItem.Url ?? "#")" @Html.Raw(elementId)>
@menuItem.DisplayName
</a>
}
</div>
}
</div>

23
framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuItem.cs

@ -37,7 +37,7 @@ namespace Volo.Abp.UI.Navigation
/// Default value: 1000.
/// </summary>
public int Order { get; set; }
/// <summary>
/// The URL to navigate when this menu item is selected.
/// </summary>
@ -65,7 +65,7 @@ namespace Volo.Abp.UI.Navigation
/// Can be used to disable this menu item.
/// </summary>
public bool IsDisabled { get; set; }
/// <inheritdoc cref="IHasMenuItems.Items"/>
[NotNull]
public IList<ApplicationMenuItem> Items { get; }
@ -75,14 +75,27 @@ namespace Volo.Abp.UI.Navigation
/// </summary>
public object CustomData { get; set; }
/// <summary>
/// Can be used to render the element with a specific Id for DOM selections.
/// </summary>
public string ElementId { get; set; }
/// <summary>
/// Can be used to render the element with extra CSS classes.
/// </summary>
public string CssClass { get; set; }
public ApplicationMenuItem(
[NotNull] string name,
[NotNull] string name,
[NotNull] string displayName,
string url = null,
string icon = null,
int order = DefaultOrder,
object customData = null,
string target = null)
string target = null,
string elementId = null,
string cssClass = null)
{
Check.NotNullOrWhiteSpace(name, nameof(name));
Check.NotNullOrWhiteSpace(displayName, nameof(displayName));
@ -94,6 +107,8 @@ namespace Volo.Abp.UI.Navigation
Order = order;
CustomData = customData;
Target = target;
ElementId = elementId;
CssClass = cssClass;
Items = new List<ApplicationMenuItem>();
}

3
framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json

@ -33,6 +33,7 @@
"PagerNext": "Next",
"PagerPrevious": "Previous",
"PagerInfo": "Showing {0} to {1} of {2} entries.",
"DatatableActionDropdownDefaultText": "Actions"
"DatatableActionDropdownDefaultText": "Actions",
"ChangePassword": "Change password"
}
}

3
framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json

@ -33,6 +33,7 @@
"PagerNext": "Sonraki",
"PagerPrevious": "Önceki",
"PagerInfo": "{2} kayıttan {0} ile {1} arası gösteriliyor.",
"DatatableActionDropdownDefaultText": "İşlemler"
"DatatableActionDropdownDefaultText": "İşlemler",
"ChangePassword": "Şifre değiştir"
}
}

4
modules/account/src/Volo.Abp.Account.Web/AbpAccountUserMenuContributor.cs

@ -10,7 +10,7 @@ namespace Volo.Abp.Account.Web
{
public AbpAccountUserMenuContributor()
{
}
public Task ConfigureMenuAsync(MenuConfigurationContext context)
@ -22,6 +22,8 @@ namespace Volo.Abp.Account.Web
var l = context.ServiceProvider.GetRequiredService<IStringLocalizer<AbpUiResource>>();
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.Logout", l["Logout"], url: "/Account/Logout", icon: "fa fa-power-off", order: int.MaxValue - 1000));
return Task.CompletedTask;

2
modules/account/src/Volo.Abp.Account.Web/Localization/Resources/AbpAccount/Web/tr.json

@ -9,7 +9,7 @@
"UseAnotherServiceToLogin": "Başka bir servisle giriş yap",
"UserLockedOutMessage": "Kullanıcı hesabı hatalı giriş denemeleri nedeniyle kilitlenmiştir. Lütfen bir süre bekleyip tekrar deneyin.",
"InvalidUserNameOrPassword": "Kullanıcı adı ya da şifre geçersiz!",
"LoginIsNotAllowed": "You are not allowed to login! E-posta adresinizi ya da telefon numaranızı doğrulamanız gerekiyor.",
"LoginIsNotAllowed": "Giriş yapamazsınız! E-posta adresinizi ya da telefon numaranızı doğrulamanız gerekiyor.",
"SelfRegistrationDisabledMessage": "Bu uygulama için kullanıcıların kendi kendilerine kaydolmaları engellenmiştir. Yeni bir kullanıcı kaydetmek için lütfen uygulama yöneticisi ile iletişime geçin."
}
}

2
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs

@ -19,5 +19,7 @@ namespace Volo.Abp.Identity
Task<IdentityUserDto> FindByUsernameAsync(string username);
Task<IdentityUserDto> FindByEmailAsync(string email);
Task ChangePasswordAsync(string currentPassword, string newPassword);
}
}

13
modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs

@ -113,7 +113,6 @@ namespace Volo.Abp.Identity
await _permissionAppServiceHelper.UpdateAsync(UserPermissionValueProvider.ProviderName, id.ToString(), input);
}
[Authorize(IdentityPermissions.Users.Default)]
public async Task<IdentityUserDto> FindByUsernameAsync(string username)
{
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(
@ -121,7 +120,6 @@ namespace Volo.Abp.Identity
);
}
[Authorize(IdentityPermissions.Users.Default)]
public async Task<IdentityUserDto> FindByEmailAsync(string email)
{
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(
@ -129,6 +127,17 @@ namespace Volo.Abp.Identity
);
}
public async Task ChangePasswordAsync(string currentPassword, string newPassword)
{
if (!CurrentUser.Id.HasValue)
{
throw new AbpException("Current user Id is null!");
}
var currentUser = await _userManager.GetByIdAsync(CurrentUser.Id.Value);
(await _userManager.ChangePasswordAsync(currentUser, currentPassword, newPassword)).CheckErrors();
}
private async Task UpdateUserByInput(IdentityUser user, IdentityUserCreateOrUpdateDtoBase input)
{
(await _userManager.SetEmailAsync(user, input.Email)).CheckErrors();

3
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Localization/Domain/en.json

@ -25,6 +25,7 @@
"Identity.UserLockedOut": "User is locked out.",
"Identity.UserLockoutNotEnabled": "Lockout is not enabled for this user.",
"Identity.UserNameNotFound": "User {0} does not exist.",
"Identity.UserNotInRole": "User is not in role '{0}'."
"Identity.UserNotInRole": "User is not in role '{0}'.",
"Identity.PasswordConfirmationFailed": "Password does not match the confirm password."
}
}

3
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Localization/Domain/tr.json

@ -25,6 +25,7 @@
"Identity.UserLockedOut": "Kullanıcı hesabı kilitlenmiş.",
"Identity.UserLockoutNotEnabled": "Bu kullanıcı için hesap kilitleme etkin değil.",
"Identity.UserNameNotFound": "{0} kullanıcısı bulunamadı.",
"Identity.UserNotInRole": "Kullanıcı '{0}' rolünde değil."
"Identity.UserNotInRole": "Kullanıcı '{0}' rolünde değil.",
"Identity.PasswordConfirmationFailed": "Yeni şifre ile onay şifresi uyuşmuyor."
}
}

6
modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs

@ -64,7 +64,6 @@ namespace Volo.Abp.Identity
return _userAppService.UpdatePermissionsAsync(id, input);
}
//todo: add authorize attrbutes on the corresponding methods.
[HttpGet]
public virtual Task<IdentityUserDto> FindByUsernameAsync(string username)
{
@ -76,5 +75,10 @@ namespace Volo.Abp.Identity
{
return _userAppService.FindByEmailAsync(email);
}
public Task ChangePasswordAsync(string currentPassword, string newPassword)
{
return _userAppService.ChangePasswordAsync(currentPassword, newPassword);
}
}
}

10
modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebModule.cs

@ -3,6 +3,8 @@ using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling;
using Volo.Abp.AutoMapper;
using Volo.Abp.Identity.Localization;
using Volo.Abp.Identity.Web.Navigation;
@ -65,6 +67,14 @@ namespace Volo.Abp.Identity.Web
options.Conventions.AuthorizePage("/Identity/Roles/CreateModal", IdentityPermissions.Roles.Create);
options.Conventions.AuthorizePage("/Identity/Roles/EditModal", IdentityPermissions.Roles.Update);
});
Configure<BundlingOptions>(options =>
{
options
.ScriptBundles
.Get(StandardBundles.Scripts.Global)
.AddFiles("/Pages/Identity/Shared/change-password-modal.js");
});
}
}
}

6
modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/en.json

@ -22,6 +22,10 @@
"NewRole": "New role",
"RoleName": "Role name",
"CreationTime": "Creation time",
"Permissions": "Permissions"
"Permissions": "Permissions",
"DisplayName:CurrentPassword": "Current password",
"DisplayName:NewPassword": "New password",
"DisplayName:NewPasswordConfirm": "Confirm new password",
"PasswordChangedMessage": "Your password has been changed successfully."
}
}

6
modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/tr.json

@ -22,6 +22,10 @@
"NewRole": "Yeni rol",
"RoleName": "Rol adı",
"CreationTime": "Oluşturma zamanı",
"Permissions": "İzinler"
"Permissions": "İzinler",
"DisplayName:CurrentPassword": "Mevcut şifre",
"DisplayName:NewPassword": "Yeni şifre",
"DisplayName:NewPasswordConfirm": "Yeni şifre (tekrar)",
"PasswordChangedMessage": "Şifreniz başarıyla değiştirildi."
}
}

20
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/ChangePasswordModal.cshtml

@ -0,0 +1,20 @@
@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<IdentityResource> L
@{
Layout = null;
}
<abp-dynamic-form abp-model="@Model.ChangePasswordInfoModel" asp-page="/Identity/Shared/ChangePasswordModal">
<abp-modal>
<abp-modal-header title="@L["ChangePassword"].Value"></abp-modal-header>
<abp-modal-body>
<abp-form-content />
</abp-modal-body>
<abp-modal-footer buttons="@(AbpModalButtons.Cancel|AbpModalButtons.Save)"></abp-modal-footer>
</abp-modal>
</abp-dynamic-form>

61
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/ChangePasswordModal.cshtml.cs

@ -0,0 +1,61 @@
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 IIdentityUserAppService _userAppService;
private readonly IStringLocalizer<IdentityResource> _localizer;
public ChangePasswordModal(IIdentityUserAppService userAppService,
IStringLocalizer<IdentityResource> localizer)
{
_userAppService = userAppService;
_localizer = localizer;
}
public async Task<IActionResult> OnPostAsync()
{
ValidateModel();
if (ChangePasswordInfoModel.NewPassword != ChangePasswordInfoModel.NewPasswordConfirm)
{
throw new UserFriendlyException(_localizer.GetString("Identity.PasswordConfirmationFailed").Value);
}
await _userAppService.ChangePasswordAsync(ChangePasswordInfoModel.CurrentPassword,
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; }
}
}

18
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/change-password-modal.js

@ -0,0 +1,18 @@
(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);

1
modules/identity/src/Volo.Abp.Identity.Web/Volo.Abp.Identity.Web.csproj

@ -37,6 +37,7 @@
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc.UI.Bootstrap\Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.csproj" />
</ItemGroup>
</Project>

Loading…
Cancel
Save