diff --git a/SolarPower/Controllers/UserController.cs b/SolarPower/Controllers/UserController.cs index d45e22d..2c3d0bf 100644 --- a/SolarPower/Controllers/UserController.cs +++ b/SolarPower/Controllers/UserController.cs @@ -28,6 +28,7 @@ namespace SolarPower.Controllers private readonly IRoleRepository roleRepository; private string logoPath = "/upload/company_logo/"; private string logoSaveAsPath = ""; + private string defPasswd = "000000"; public UserController(IUserRepository userRepository, ISendEmailService sendEmailService, @@ -694,7 +695,53 @@ namespace SolarPower.Controllers return apiResult; } + [HttpPost] + public async Task> DefaultPassword(PostUser post) + { + User user = null; + ApiResult apiResult = new ApiResult(); + 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 properties = new List() + { + "Password", + "UpdatedBy", + "Id" + }; + + await userRepository.UpdatePassword(update, properties); + var website_url = await powerStationRepository.GetOneVariableByName("WebSiteUrl"); + + var sendSubject = "密碼更改成功"; + var sendContent = $@"您的新密碼為: { defPasswd} +
立即前往:{website_url}"; + + List recipientEmails = new List() + { + user.Email + }; + + sendEmailService.Send(recipientEmails, sendSubject, sendContent); + apiResult.Code = "0000"; + apiResult.Msg = "變更成功"; + } + else + { + apiResult.Code = "9999"; + apiResult.Msg = "使用者不存在"; + } + return apiResult; + } } } diff --git a/SolarPower/Views/User/Index.cshtml b/SolarPower/Views/User/Index.cshtml index acc0edd..f6edadd 100644 --- a/SolarPower/Views/User/Index.cshtml +++ b/SolarPower/Views/User/Index.cshtml @@ -574,6 +574,11 @@ function AddUser() { selected_id = 0; $("#user-modal .modal-title").html("人員基本資料 - 新增"); + + //新增使用者不出現 預設密碼----------------------- + var i = document.getElementById("btnDefPasswd"); + i.style.display = "none"; + //------------------------------------------------ $("#user-form").trigger("reset"); $("#user_companyId_modal").val($("#select_user_company_userManager_tab").val()); $("#user_account_modal").prop("disabled", false); @@ -611,6 +616,11 @@ $("#user-modal .modal-title").html("人員基本資料 - 編輯"); + //修改使用者出現 預設密碼----------------------------- + var i = document.getElementById("btnDefPasswd"); + i.style.display = "block"; + //---------------------------------------------------- + selected_id = $(this).parents('tr').attr('data-id'); //取得單一使用者管理員 @@ -745,6 +755,42 @@ } //#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 刪除使用者 $('#user_table').on("click", "button.del-btn", function () { selected_id = $(this).parents('tr').attr('data-id'); diff --git a/SolarPower/Views/User/_UserManager.cshtml b/SolarPower/Views/User/_UserManager.cshtml index 42dbf5c..9e3d7c3 100644 --- a/SolarPower/Views/User/_UserManager.cshtml +++ b/SolarPower/Views/User/_UserManager.cshtml @@ -117,6 +117,7 @@