帳號管理- 新增"密碼重置鈕",並發送email通知
This commit is contained in:
parent
69ebee1e4d
commit
ed78000e99
@ -28,6 +28,7 @@ namespace SolarPower.Controllers
|
|||||||
private readonly IRoleRepository roleRepository;
|
private readonly IRoleRepository roleRepository;
|
||||||
private string logoPath = "/upload/company_logo/";
|
private string logoPath = "/upload/company_logo/";
|
||||||
private string logoSaveAsPath = "";
|
private string logoSaveAsPath = "";
|
||||||
|
private string defPasswd = "000000";
|
||||||
|
|
||||||
public UserController(IUserRepository userRepository,
|
public UserController(IUserRepository userRepository,
|
||||||
ISendEmailService sendEmailService,
|
ISendEmailService sendEmailService,
|
||||||
@ -694,7 +695,53 @@ namespace SolarPower.Controllers
|
|||||||
return apiResult;
|
return apiResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ApiResult<string>> DefaultPassword(PostUser post)
|
||||||
|
{
|
||||||
|
User user = null;
|
||||||
|
ApiResult<string> apiResult = new ApiResult<string>();
|
||||||
|
user = await userRepository.GetOneAsync(post.Id);
|
||||||
|
if(user != null)
|
||||||
|
{
|
||||||
|
EDFunction edFunction = new EDFunction();
|
||||||
|
var newPassword = edFunction.GetSHA256Encryption(defPasswd);
|
||||||
|
UpdatePassword update = new UpdatePassword()
|
||||||
|
{
|
||||||
|
Password = newPassword,
|
||||||
|
UpdatedBy = myUser.Id,
|
||||||
|
Id = user.Id
|
||||||
|
};
|
||||||
|
|
||||||
|
List<string> properties = new List<string>()
|
||||||
|
{
|
||||||
|
"Password",
|
||||||
|
"UpdatedBy",
|
||||||
|
"Id"
|
||||||
|
};
|
||||||
|
|
||||||
|
await userRepository.UpdatePassword(update, properties);
|
||||||
|
var website_url = await powerStationRepository.GetOneVariableByName("WebSiteUrl");
|
||||||
|
|
||||||
|
var sendSubject = "密碼更改成功";
|
||||||
|
var sendContent = $@"您的新密碼為: { defPasswd}
|
||||||
|
<br>立即前往:<a href='{website_url}' target='_blank'>{website_url}</a>";
|
||||||
|
|
||||||
|
List<string> recipientEmails = new List<string>()
|
||||||
|
{
|
||||||
|
user.Email
|
||||||
|
};
|
||||||
|
|
||||||
|
sendEmailService.Send(recipientEmails, sendSubject, sendContent);
|
||||||
|
apiResult.Code = "0000";
|
||||||
|
apiResult.Msg = "變更成功";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
apiResult.Code = "9999";
|
||||||
|
apiResult.Msg = "使用者不存在";
|
||||||
|
}
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -574,6 +574,11 @@
|
|||||||
function AddUser() {
|
function AddUser() {
|
||||||
selected_id = 0;
|
selected_id = 0;
|
||||||
$("#user-modal .modal-title").html("人員基本資料 - 新增");
|
$("#user-modal .modal-title").html("人員基本資料 - 新增");
|
||||||
|
|
||||||
|
//新增使用者不出現 預設密碼-----------------------
|
||||||
|
var i = document.getElementById("btnDefPasswd");
|
||||||
|
i.style.display = "none";
|
||||||
|
//------------------------------------------------
|
||||||
$("#user-form").trigger("reset");
|
$("#user-form").trigger("reset");
|
||||||
$("#user_companyId_modal").val($("#select_user_company_userManager_tab").val());
|
$("#user_companyId_modal").val($("#select_user_company_userManager_tab").val());
|
||||||
$("#user_account_modal").prop("disabled", false);
|
$("#user_account_modal").prop("disabled", false);
|
||||||
@ -611,6 +616,11 @@
|
|||||||
|
|
||||||
$("#user-modal .modal-title").html("人員基本資料 - 編輯");
|
$("#user-modal .modal-title").html("人員基本資料 - 編輯");
|
||||||
|
|
||||||
|
//修改使用者出現 預設密碼-----------------------------
|
||||||
|
var i = document.getElementById("btnDefPasswd");
|
||||||
|
i.style.display = "block";
|
||||||
|
//----------------------------------------------------
|
||||||
|
|
||||||
selected_id = $(this).parents('tr').attr('data-id');
|
selected_id = $(this).parents('tr').attr('data-id');
|
||||||
|
|
||||||
//取得單一使用者管理員
|
//取得單一使用者管理員
|
||||||
@ -745,6 +755,42 @@
|
|||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
//#region 預設密碼
|
||||||
|
function DefaultPassword() {
|
||||||
|
if ($("#user-form").valid()) {
|
||||||
|
showLoading();
|
||||||
|
var url = "/User/DefaultPassword";
|
||||||
|
|
||||||
|
var formData = new FormData();
|
||||||
|
formData.append("Id", selected_id);
|
||||||
|
formData.append("CompanyId", $("#user_companyId_modal").val());
|
||||||
|
formData.append("Name", $("#user_name_modal").val());
|
||||||
|
formData.append("Email", $("#user_email_modal").val());
|
||||||
|
formData.append("Account", $("#user_account_modal").val());
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: url,
|
||||||
|
data: formData,
|
||||||
|
cache: false,
|
||||||
|
contentType: false,
|
||||||
|
processData: false,
|
||||||
|
success: function (rel) {
|
||||||
|
if (rel.code != "0000") {
|
||||||
|
hideLoading();
|
||||||
|
toast_error(rel.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast_ok(rel.msg);
|
||||||
|
$('#user-modal').modal('hide');
|
||||||
|
hideLoading();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//#endregion
|
||||||
|
|
||||||
//#region 刪除使用者
|
//#region 刪除使用者
|
||||||
$('#user_table').on("click", "button.del-btn", function () {
|
$('#user_table').on("click", "button.del-btn", function () {
|
||||||
selected_id = $(this).parents('tr').attr('data-id');
|
selected_id = $(this).parents('tr').attr('data-id');
|
||||||
|
|||||||
@ -117,6 +117,7 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-danger" id="btnDefPasswd" style=" float: left; display:none" onclick="DefaultPassword()">預設密碼</button>
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||||
<button type="button" class="btn btn-primary" onclick="SaveUser()">確定</button>
|
<button type="button" class="btn btn-primary" onclick="SaveUser()">確定</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user