重构代码:更新个人中心保存按钮逻辑,防止Administrators组成员更改密码

This commit is contained in:
Argo-MacBookPro 2018-08-10 18:01:26 +08:00
parent 9b08145ef8
commit f206a7a439
3 changed files with 12 additions and 14 deletions

View File

@ -33,16 +33,13 @@ namespace Bootstrap.Admin.Controllers.Api
[HttpPut]
public bool Put([FromBody]User value)
{
if (User.IsInRole("Administrators")) return false;
var ret = false;
if (value.UserStatus == 3)
{
return UserHelper.SaveUserCssByName(value.UserName, value.Css);
}
if (value.UserStatus == 9)
{
// vlaidate userName
return BootstrapUser.RetrieveUserByUserName(value.UserName) == null && !UserHelper.RetrieveNewUsers().Any(u => u.UserName == value.UserName);
}
var ret = false;
if (value.UserName.Equals(User.Identity.Name, System.StringComparison.OrdinalIgnoreCase))
{
if (value.UserStatus == 1)

View File

@ -44,8 +44,8 @@
</div>
</div>
</form>
<div class="modal-footer">
<button id="btnSaveDisplayName" data-method="user" class="btn btn-secondary" type="button" disabled data-admin="@User.IsInRole("Administrators")"><i class="fa fa-save"></i><span>保存</span></button>
<div class="modal-footer d-none" data-admin="@User.IsInRole("Administrators")">
<button id="btnSaveDisplayName" data-method="user" class="btn btn-secondary" type="button"><i class="fa fa-save"></i><span>保存</span></button>
</div>
</div>
</div>
@ -54,7 +54,7 @@
<div class="card-body" data-toggle="LgbValidate" data-valid-button="#btnSavePassword">
<form class="form-inline">
<div class="form-row">
<div class="form-group">
<div class="form-group col">
<label class="control-label" for="currentPassword">原密码: </label>
<input type="password" class="form-control" id="currentPassword" placeholder="原密码50字以内" maxlength="50" data-valid="true" />
</div>
@ -70,8 +70,8 @@
</div>
</div>
</form>
<div class="modal-footer">
<button id="btnSavePassword" data-method="password" class="btn btn-secondary" type="button" disabled data-admin="@User.IsInRole("Administrators")"><i class="fa fa-save"></i><span>保存</span></button>
<div class="modal-footer d-none" data-admin="@User.IsInRole("Administrators")">
<button id="btnSavePassword" data-method="password" class="btn btn-secondary" type="button"><i class="fa fa-save"></i><span>保存</span></button>
</div>
</div>
</div>
@ -99,8 +99,8 @@
</div>
</div>
</form>
<div class="modal-footer">
<button id="btnSaveCss" data-method="css" class="btn btn-secondary" type="button" disabled data-admin="@User.IsInRole("Administrators")"><i class="fa fa-save"></i><span>保存</span></button>
<div class="modal-footer d-none" data-admin="@User.IsInRole("Administrators")">
<button id="btnSaveCss" data-method="css" class="btn btn-secondary" type="button"><i class="fa fa-save"></i><span>保存</span></button>
</div>
</div>
</div>

View File

@ -38,6 +38,7 @@
$('button[data-method]').on('click', function (e) {
var $this = $(this);
if ($this.parent().attr("data-admin") === "True") return false;
var data = bsa.dataEntity.get();
switch ($this.attr('data-method')) {
case 'password':
@ -61,5 +62,5 @@
break;
}
});
$('button[data-admin="False"]').removeAttr('disabled');
$('button[data-admin="False"]').removeClass('d-none');
});