Commit a9bea75e authored by nickchen's avatar nickchen 🎨

fix: 登入時有機率404 & 沒有部門時會出錯

parent 1ad88099
...@@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Authentication; ...@@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Newtonsoft.Json; using Newtonsoft.Json;
...@@ -190,6 +191,7 @@ namespace backstage.Controllers ...@@ -190,6 +191,7 @@ namespace backstage.Controllers
#endregion #endregion
} }
#region 寫入TOKEN #region 寫入TOKEN
int LoginExpireMinute = Convert.ToInt32(_config["LoginExpireMinute"]); int LoginExpireMinute = Convert.ToInt32(_config["LoginExpireMinute"]);
...@@ -212,20 +214,22 @@ namespace backstage.Controllers ...@@ -212,20 +214,22 @@ namespace backstage.Controllers
//將 ClaimsIdentity 設定給 ClaimsPrincipal (持有者) //將 ClaimsIdentity 設定給 ClaimsPrincipal (持有者)
ClaimsPrincipal principal = new ClaimsPrincipal(userClaims); ClaimsPrincipal principal = new ClaimsPrincipal(userClaims);
//登入動作 //登入動作
try try
{ {
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, new AuthenticationProperties() await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, new AuthenticationProperties()
{ {
//是否可以被刷新 //是否可以被刷新
AllowRefresh = true, AllowRefresh = true,
// 設置了一個 1 天 有效期的持久化 cookie // 設置了一個 1 天 有效期的持久化 cookie
IsPersistent = true, //IsPersistent = false,瀏覽器關閉即刻登出 IsPersistent = true, //IsPersistent = false,瀏覽器關閉即刻登出
//用戶頁面停留太久,逾期時間,在此設定的話會覆蓋Startup.cs裡的逾期設定 //用戶頁面停留太久,逾期時間,在此設定的話會覆蓋Startup.cs裡的逾期設定
ExpiresUtc = DateTime.Now.AddMinutes(LoginExpireMinute), ExpiresUtc = DateTime.Now.AddMinutes(LoginExpireMinute),
}); });
return RedirectToAction("Index", "Home");
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -234,7 +238,7 @@ namespace backstage.Controllers ...@@ -234,7 +238,7 @@ namespace backstage.Controllers
#endregion #endregion
return RedirectToAction("Index", "Home");
} }
else if (u.r == 65796) else if (u.r == 65796)
{ {
...@@ -1107,8 +1111,14 @@ namespace backstage.Controllers ...@@ -1107,8 +1111,14 @@ namespace backstage.Controllers
{ {
return View(DepartmentsResponse); return View(DepartmentsResponse);
}*/ }*/
var merchants = DepartmentsResponse.merchants.Where(x => x.enabled == 1).ToList(); var merchants = new List<Department>();
if(DepartmentsResponse.merchants != null)
{
merchants = DepartmentsResponse.merchants?.Where(x => x.enabled == 1).ToList();
}
return View(merchants); return View(merchants);
} }
......
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
} }
<div id="msgDiv"></div> <div id="msgDiv"></div>
<!-- <h6 class="font-weight-light">基本資料</h6> --> <!-- <h6 class="font-weight-light">基本資料</h6> -->
<form class="pt-3" method="post" asp-action="login" asp-route-ReturnUrl=@Context.Request.Query["ReturnUrl"]> <form id="LoginForm" class="pt-3" method="post" asp-action="login" asp-route-ReturnUrl=@Context.Request.Query["ReturnUrl"]>
<div id="errorMsg" asp-validation-summary="All" class="text-danger"></div> <div id="errorMsg" asp-validation-summary="All" class="text-danger"></div>
<div class="form-group"> <div class="form-group">
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
<span asp-validation-for="pwd" class="text-danger"></span> <span asp-validation-for="pwd" class="text-danger"></span>
</div> </div>
<div class="mt-3"> <div class="mt-3">
<button type="submit" class="btn btn-block btn-gradient-primary btn-lg font-weight-medium">@Localizer["Login"]</button> <button id="LoginSubmit" type="submit" class="btn btn-block btn-gradient-primary btn-lg font-weight-medium">@Localizer["Login"]</button>
</div> </div>
@*<div class="my-2 d-flex justify-content-between align-items-center"> @*<div class="my-2 d-flex justify-content-between align-items-center">
<div class="form-check"> <div class="form-check">
...@@ -127,4 +127,9 @@ ...@@ -127,4 +127,9 @@
if (msg != '') { if (msg != '') {
showAlert(IsSuccess, msg); showAlert(IsSuccess, msg);
} }
$('#LoginSubmit').on('click', function(){
$('#LoginForm').submit();
this.disabled = true;
});
</script> </script>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment