Browse Source

feat(account): Optimize the login page

- Fixed the issue of invalid callback url for some pages
- Disable qrcode login on mobile devices
pull/1382/head
colin 3 months ago
parent
commit
95b4e3312e
  1. 2
      aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/ChangePassword.cshtml
  2. 2
      aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/ChangePassword.cshtml.cs
  3. 2
      aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/EmailConfirm.cshtml
  4. 25
      aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/Login.cshtml
  5. 19
      aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/Login.cshtml.cs
  6. 2
      aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/Register.cshtml
  7. 3
      aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/Register.cshtml.cs
  8. 2
      aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/SendEmailConfirm.cshtml

2
aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/ChangePassword.cshtml

@ -12,6 +12,8 @@
<div class="card-body p-5">
<h4>@L["ChangePassword"]</h4>
<form id="ChangePasswordForm" method="post">
<input asp-for="ReturnUrl" />
<input asp-for="ReturnUrlHash" />
<div class="mb-3">
@if (!Model.HideOldPasswordInput)
{

2
aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/ChangePassword.cshtml.cs

@ -54,9 +54,11 @@ public class ChangePasswordModel : AccountPageModel
[BindProperty]
public ChangePasswordInputModel Input { get; set; }
[HiddenInput]
[BindProperty(SupportsGet = true)]
public string ReturnUrl { get; set; }
[HiddenInput]
[BindProperty(SupportsGet = true)]
public string ReturnUrlHash { get; set; }

2
aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/EmailConfirm.cshtml

@ -8,6 +8,8 @@
<div class="card-body p-5">
<h4>@L["EmailConfirm"]</h4>
<form method="post">
<input asp-for="ReturnUrl" />
<input asp-for="ReturnUrlHash" />
<abp-input asp-for="UserId"/>
<abp-input asp-for="ConfirmToken"/>
<a abp-button="Secondary" asp-page="./Login">@L["Cancel"]</a>

25
aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/Login.cshtml

@ -104,17 +104,20 @@
</div>
</form>
</abp-tab>
<abp-tab title="@L["ScanQrCodeLogin"].Value" active="Model.LoginType == LoginType.QrCode" header-name="QrCodeLogin">
<form method="post" class="mt-4" asp-page-handler="QrCodeLogin" id="QrCodeForm">
<input asp-for="QrCodeLoginInput.ReturnUrl" />
<input asp-for="QrCodeLoginInput.ReturnUrlHash" />
<input asp-for="QrCodeLoginInput.Key" id="QrCodeKey" />
<div class="gap-2" style="display: flex; flex-direction: column; justify-content: center; align-items: center;">
<div id="QrCode"></div>
<div id="QrCodeStatus"></div>
</div>
</form>
</abp-tab>
@if (Model.QrCodeLoginInput.IsEnabled)
{
<abp-tab title="@L["ScanQrCodeLogin"].Value" active="Model.LoginType == LoginType.QrCode" header-name="QrCodeLogin">
<form method="post" class="mt-4" asp-page-handler="QrCodeLogin" id="QrCodeForm">
<input asp-for="QrCodeLoginInput.ReturnUrl" />
<input asp-for="QrCodeLoginInput.ReturnUrlHash" />
<input asp-for="QrCodeLoginInput.Key" id="QrCodeKey" />
<div class="gap-2" style="display: flex; flex-direction: column; justify-content: center; align-items: center;">
<div id="QrCode"></div>
<div id="QrCodeStatus"></div>
</div>
</form>
</abp-tab>
}
</abp-tabs>
}

19
aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/Login.cshtml.cs

@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using MyCSharp.HttpUserAgentParser.Providers;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
@ -65,6 +66,7 @@ public class LoginModel : AccountPageModel
protected IIdentityUserRepository UserRepository => LazyServiceProvider.LazyGetRequiredService<IIdentityUserRepository>();
protected IQrCodeLoginProvider QrCodeLoginProvider => LazyServiceProvider.LazyGetRequiredService<IQrCodeLoginProvider>();
protected IHttpUserAgentParserProvider HttpUserAgentParserProvider => LazyServiceProvider.LazyGetRequiredService<IHttpUserAgentParserProvider>();
protected IExternalProviderService ExternalProviderService { get; }
protected IAuthenticationSchemeProvider SchemeProvider { get; }
@ -103,6 +105,8 @@ public class LoginModel : AccountPageModel
ReturnUrlHash = ReturnUrlHash,
};
AllowQrCodeLoginIfNotMobileDevice();
ExternalProviders = await GetExternalProviders();
EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin);
@ -596,6 +600,18 @@ public class LoginModel : AccountPageModel
Alerts.Danger(L["InvalidUserNameOrPassword"]);
return Task.FromResult<IActionResult>(Page());
}
protected virtual void AllowQrCodeLoginIfNotMobileDevice()
{
if (HttpContext?.Request?.Headers?.UserAgent.IsNullOrEmpty() == false)
{
var userAgentInfo = HttpUserAgentParserProvider.Parse(HttpContext.Request.Headers.UserAgent);
if (userAgentInfo.MobileDeviceType.IsNullOrWhiteSpace())
{
QrCodeLoginInput.IsEnabled = true;
}
}
}
}
public abstract class LoginInputModel
@ -642,6 +658,9 @@ public class QrCodeLoginInputModel : LoginInputModel
{
[HiddenInput]
public string Key { get; set; }
[HiddenInput]
public bool IsEnabled { get; set; }
}
public enum LoginType

2
aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/Register.cshtml

@ -8,6 +8,8 @@
<div class="card-body p-5">
<h4>@L["Register"]</h4>
<form method="post" class="mt-4">
<input asp-for="ReturnUrl" />
<input asp-for="ReturnUrlHash" />
@if (Model.EnableLocalRegister || Model.IsExternalLogin)
{
<abp-input asp-for="Input.UserName" auto-focus="true" />

3
aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/Register.cshtml.cs

@ -29,10 +29,11 @@ namespace LINGYUN.Abp.Account.Web.Pages.Account;
public class RegisterModel : AccountPageModel
{
[HiddenInput]
[BindProperty(SupportsGet = true)]
public string ReturnUrl { get; set; }
[HiddenInput]
[BindProperty(SupportsGet = true)]
public string ReturnUrlHash { get; set; }

2
aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/SendEmailConfirm.cshtml

@ -8,6 +8,8 @@
<div class="card-body p-5">
<h4>@L["EmailConfirm"]</h4>
<form method="post">
<input asp-for="ReturnUrl" />
<input asp-for="ReturnUrlHash" />
<abp-input asp-for="Email" readonly="true" />
<a abp-button="Secondary" asp-page="./Login">@L["Cancel"]</a>
<abp-button type="submit" button-type="Primary" text="@L["ClickToValidation"].Value"/>

Loading…
Cancel
Save