Make it easier to update root user credentials and patch bug.
This commit is contained in:
@@ -219,6 +219,13 @@ namespace CarCareTracker.Controllers
|
|||||||
var userName = User.Identity.Name;
|
var userName = User.Identity.Name;
|
||||||
return PartialView("_AccountModal", new UserData() { EmailAddress = emailAddress, UserName = userName });
|
return PartialView("_AccountModal", new UserData() { EmailAddress = emailAddress, UserName = userName });
|
||||||
}
|
}
|
||||||
|
[Authorize(Roles = nameof(UserData.IsRootUser))]
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetRootAccountInformationModal()
|
||||||
|
{
|
||||||
|
var userName = User.Identity.Name;
|
||||||
|
return PartialView("_RootAccountModal", new UserData() { UserName = userName });
|
||||||
|
}
|
||||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
public IActionResult Error()
|
public IActionResult Error()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ namespace CarCareTracker.Controllers
|
|||||||
var result = _loginLogic.ResetPasswordByUser(credentials);
|
var result = _loginLogic.ResetPasswordByUser(credentials);
|
||||||
return Json(result);
|
return Json(result);
|
||||||
}
|
}
|
||||||
[Authorize] //User must already be logged in to do this.
|
[Authorize(Roles = nameof(UserData.IsRootUser))] //User must already be logged in as root user to do this.
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult CreateLoginCreds(LoginModel credentials)
|
public IActionResult CreateLoginCreds(LoginModel credentials)
|
||||||
{
|
{
|
||||||
@@ -235,7 +235,7 @@ namespace CarCareTracker.Controllers
|
|||||||
}
|
}
|
||||||
return Json(false);
|
return Json(false);
|
||||||
}
|
}
|
||||||
[Authorize]
|
[Authorize(Roles = nameof(UserData.IsRootUser))]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult DestroyLoginCreds()
|
public IActionResult DestroyLoginCreds()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,7 +41,12 @@
|
|||||||
<a class="dropdown-item" href="/Admin"><span class="display-3 ms-2"><i class="bi bi-people me-2"></i>@translator.Translate(userLanguage,"Admin Panel")</span></a>
|
<a class="dropdown-item" href="/Admin"><span class="display-3 ms-2"><i class="bi bi-people me-2"></i>@translator.Translate(userLanguage,"Admin Panel")</span></a>
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
@if (!User.IsInRole(nameof(UserData.IsRootUser)))
|
@if (User.IsInRole(nameof(UserData.IsRootUser)))
|
||||||
|
{
|
||||||
|
<li>
|
||||||
|
<button class="nav-link" onclick="showRootAccountInformationModal()"><span class="display-3 ms-2"><i class="bi bi-person-gear me-2"></i>@translator.Translate(userLanguage, "Profile")</span></button>
|
||||||
|
</li>
|
||||||
|
} else
|
||||||
{
|
{
|
||||||
<li>
|
<li>
|
||||||
<button class="nav-link" onclick="showAccountInformationModal()"><span class="display-3 ms-2"><i class="bi bi-person-gear me-2"></i>@translator.Translate(userLanguage, "Profile")</span></button>
|
<button class="nav-link" onclick="showAccountInformationModal()"><span class="display-3 ms-2"><i class="bi bi-person-gear me-2"></i>@translator.Translate(userLanguage, "Profile")</span></button>
|
||||||
@@ -90,7 +95,12 @@
|
|||||||
<a class="dropdown-item" href="/Admin"><i class="bi bi-people me-2"></i>@translator.Translate(userLanguage,"Admin Panel")</a>
|
<a class="dropdown-item" href="/Admin"><i class="bi bi-people me-2"></i>@translator.Translate(userLanguage,"Admin Panel")</a>
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
@if (!User.IsInRole(nameof(UserData.IsRootUser)))
|
@if (User.IsInRole(nameof(UserData.IsRootUser)))
|
||||||
|
{
|
||||||
|
<li>
|
||||||
|
<button class="dropdown-item" onclick="showRootAccountInformationModal()"><i class="bi bi-person-gear me-2"></i>@translator.Translate(userLanguage, "Profile")</button>
|
||||||
|
</li>
|
||||||
|
} else
|
||||||
{
|
{
|
||||||
<li>
|
<li>
|
||||||
<button class="dropdown-item" onclick="showAccountInformationModal()"><i class="bi bi-person-gear me-2"></i>@translator.Translate(userLanguage, "Profile")</button>
|
<button class="dropdown-item" onclick="showAccountInformationModal()"><i class="bi bi-person-gear me-2"></i>@translator.Translate(userLanguage, "Profile")</button>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
var userLanguage = userConfig.UserLanguage;
|
var userLanguage = userConfig.UserLanguage;
|
||||||
}
|
}
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title" id="addVehicleModalLabel">@translator.Translate(userLanguage, "Update Profile")</h5>
|
<h5 class="modal-title" id="updateAccountModalLabel">@translator.Translate(userLanguage, "Update Profile")</h5>
|
||||||
<button type="button" class="btn-close" onclick="hideAccountInformationModal()" aria-label="Close"></button>
|
<button type="button" class="btn-close" onclick="hideAccountInformationModal()" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
|||||||
26
Views/Home/_RootAccountModal.cshtml
Normal file
26
Views/Home/_RootAccountModal.cshtml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
@using CarCareTracker.Helper
|
||||||
|
@inject IConfigHelper config
|
||||||
|
@inject ITranslationHelper translator
|
||||||
|
@model UserData
|
||||||
|
@{
|
||||||
|
var userConfig = config.GetUserConfig(User);
|
||||||
|
var userLanguage = userConfig.UserLanguage;
|
||||||
|
}
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="updateRootAccountModalLabel">@translator.Translate(userLanguage, "Update Profile")</h5>
|
||||||
|
<button type="button" class="btn-close" onclick="hideAccountInformationModal()" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form class="form-inline">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="inputUsername">@translator.Translate(userLanguage, "Username")</label>
|
||||||
|
<input type="text" id="inputUsername" class="form-control" placeholder="@translator.Translate(userLanguage, "Account Username")" value="@Model.UserName">
|
||||||
|
<label for="inputPassword">@translator.Translate(userLanguage, "Password")</label>
|
||||||
|
<input type="password" id="inputPassword" class="form-control" placeholder="@translator.Translate(userLanguage, "Password")" value="">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" onclick="hideAccountInformationModal()">@translator.Translate(userLanguage, "Cancel")</button>
|
||||||
|
<button type="button" onclick="validateAndSaveRootUserAccount()" class="btn btn-primary">@translator.Translate(userLanguage, "Update")</button>
|
||||||
|
</div>
|
||||||
@@ -341,6 +341,47 @@ function showAccountInformationModal() {
|
|||||||
$('#accountInformationModal').modal('show');
|
$('#accountInformationModal').modal('show');
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showRootAccountInformationModal() {
|
||||||
|
$.get('/Home/GetRootAccountInformationModal', function (data) {
|
||||||
|
$('#accountInformationModalContent').html(data);
|
||||||
|
$('#accountInformationModal').modal('show');
|
||||||
|
})
|
||||||
|
}
|
||||||
|
function validateAndSaveRootUserAccount() {
|
||||||
|
var hasError = false;
|
||||||
|
if ($('#inputUsername').val().trim() == '') {
|
||||||
|
$('#inputUsername').addClass("is-invalid");
|
||||||
|
hasError = true;
|
||||||
|
} else {
|
||||||
|
$('#inputUsername').removeClass("is-invalid");
|
||||||
|
}
|
||||||
|
if ($('#inputPassword').val().trim() == '') {
|
||||||
|
$('#inputPassword').addClass("is-invalid");
|
||||||
|
hasError = true;
|
||||||
|
} else {
|
||||||
|
$('#inputPassword').removeClass("is-invalid");
|
||||||
|
}
|
||||||
|
if (hasError) {
|
||||||
|
errorToast("Please check the form data");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var userAccountInfo = {
|
||||||
|
userName: $('#inputUsername').val(),
|
||||||
|
password: $('#inputPassword').val()
|
||||||
|
}
|
||||||
|
$.post('/Login/CreateLoginCreds', { credentials: userAccountInfo }, function (data) {
|
||||||
|
if (data) {
|
||||||
|
//hide modal
|
||||||
|
hideAccountInformationModal();
|
||||||
|
successToast('Root Account Updated');
|
||||||
|
performLogOut();
|
||||||
|
} else {
|
||||||
|
errorToast(data.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function hideAccountInformationModal() {
|
function hideAccountInformationModal() {
|
||||||
$('#accountInformationModal').modal('hide');
|
$('#accountInformationModal').modal('hide');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user