Skip to content

Commit 64298c3

Browse files
authored
Merge pull request #508 from iyilm4z/ft-mvc-change-password-page
Change Password Page Added for MVC
2 parents 94d391f + 26f7857 commit 64298c3

File tree

6 files changed

+128
-0
lines changed

6 files changed

+128
-0
lines changed

aspnet-core/src/AbpCompanyName.AbpProjectName.Application/Users/IUserAppService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ public interface IUserAppService : IAsyncCrudAppService<UserDto, long, PagedUser
1111
Task<ListResultDto<RoleDto>> GetRoles();
1212

1313
Task ChangeLanguage(ChangeUserLanguageDto input);
14+
15+
Task<bool> ChangePassword(ChangePasswordDto input);
1416
}
1517
}

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/Controllers/UsersController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,10 @@ public async Task<ActionResult> EditModal(long userId)
4040
};
4141
return PartialView("_EditModal", model);
4242
}
43+
44+
public ActionResult ChangePassword()
45+
{
46+
return View();
47+
}
4348
}
4449
}

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/Views/Shared/Components/RightNavbarUserArea/Default.cshtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<img class="user-image img-circle elevation-2" src="~/libs/admin-lte/dist/img/avatar5.png" alt="User Image">
55
</a>
66
<div class="dropdown-menu dropdown-menu-right">
7+
<a class="dropdown-item" asp-controller="Users" asp-action="ChangePassword">
8+
<i class="fas fa-user-edit"></i> @L("UpdatePassword")
9+
</a>
710
<a class="dropdown-item" asp-controller="Account" asp-action="Logout">
811
<i class="fas fa-sign-out-alt"></i> @L("Logout")
912
</a>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
@using Abp.Authorization.Users
2+
@{
3+
ViewBag.Title = L("UpdatePassword");
4+
}
5+
@section scripts
6+
{
7+
<environment names="Development">
8+
<script src="~/view-resources/Views/Users/ChangePassword.js" asp-append-version="true"></script>
9+
</environment>
10+
11+
<environment names="Staging,Production">
12+
<script src="~/view-resources/Views/Users/ChangePassword.min.js" asp-append-version="true"></script>
13+
</environment>
14+
}
15+
<section class="content-header">
16+
<div class="container-fluid">
17+
<div class="row">
18+
<div class="col-sm-6">
19+
<h1>@L("UpdatePassword")</h1>
20+
</div>
21+
</div>
22+
</div>
23+
</section>
24+
<section class="content">
25+
<div class="container-fluid">
26+
<div class="row">
27+
<div class="col-12">
28+
<form id="ChangePassword" autocomplete="off" class="form-horizontal">
29+
<div class="card">
30+
<div class="card-body">
31+
<div class="form-group row required">
32+
<label class="col-md-3 col-form-label">@L("CurrentPassword")</label>
33+
<div class="col-md-9">
34+
<input type="password" class="form-control" name="CurrentPassword" id="CurrentPassword" required maxlength="@AbpUserBase.MaxPlainPasswordLength">
35+
</div>
36+
</div>
37+
<div class="form-group row required">
38+
<label class="col-md-3 col-form-label">@L("Password")</label>
39+
<div class="col-md-9">
40+
<input type="password" class="form-control" name="NewPassword" id="NewPassword" required maxlength="@AbpUserBase.MaxPlainPasswordLength">
41+
</div>
42+
</div>
43+
<div class="form-group row required">
44+
<label class="col-md-3 col-form-label">@L("ConfirmPassword")</label>
45+
<div class="col-md-9">
46+
<input type="password" class="form-control" name="ConfirmNewPassword" id="ConfirmNewPassword" required maxlength="@AbpUserBase.MaxPlainPasswordLength">
47+
</div>
48+
</div>
49+
</div>
50+
<div class="card-footer">
51+
<button type="submit" class="btn btn-primary save-button">@L("Save")</button>
52+
</div>
53+
</div>
54+
</form>
55+
</div>
56+
</div>
57+
</div>
58+
</section>

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/bundleconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@
101101
"wwwroot/view-resources/Views/Users/Index.js"
102102
]
103103
},
104+
{
105+
"outputFileName": "wwwroot/view-resources/Views/Users/ChangePassword.min.js",
106+
"inputFiles": [
107+
"wwwroot/view-resources/Views/Users/ChangePassword.js"
108+
]
109+
},
104110
{
105111
"outputFileName": "wwwroot/view-resources/Views/Roles/Index.min.js",
106112
"inputFiles": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
(function ($) {
2+
var _userService = abp.services.app.user,
3+
l = abp.localization.getSource('AbpProjectName'),
4+
_$form = $('#ChangePassword');
5+
6+
$.validator.addMethod("regex", function (value, element, regexpr) {
7+
return regexpr.test(value);
8+
}, l("PasswordsMustBeAtLeast8CharactersContainLowercaseUppercaseNumber"));
9+
10+
_$form.validate({
11+
rules: {
12+
NewPassword: {
13+
regex: /(?=^.{8,}$)(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s)[0-9a-zA-Z!@#$%^&*()]*$/
14+
},
15+
ConfirmNewPassword: {
16+
equalTo: "#NewPassword"
17+
}
18+
},
19+
messages: {
20+
ConfirmNewPassword: {
21+
equalTo: l("PasswordsDoNotMatch")
22+
}
23+
}
24+
});
25+
26+
function save() {
27+
if (!_$form.valid()) {
28+
return;
29+
}
30+
31+
var changePasswordDto = _$form.serializeFormToObject();
32+
33+
abp.ui.setBusy(_$form);
34+
var skipClearBusy = false;
35+
_userService.changePassword(changePasswordDto).done(success => {
36+
if (success) {
37+
skipClearBusy = true;
38+
abp.notify.info(l('SavedSuccessfully'));
39+
setTimeout(() => {
40+
window.location.href = "/";
41+
}, 1200);
42+
}
43+
}).always(function () {
44+
if (!skipClearBusy) {
45+
abp.ui.clearBusy(_$form);
46+
}
47+
});
48+
}
49+
50+
_$form.submit(function (e) {
51+
e.preventDefault();
52+
save();
53+
});
54+
})(jQuery);

0 commit comments

Comments
 (0)