feat: 后台应用通过当前请求拼接前台地址
This commit is contained in:
parent
1a896cf994
commit
10e5b1d26c
|
@ -1,29 +1,32 @@
|
||||||
using BootstrapAdmin.Web.Services;
|
using BootstrapAdmin.Web.Services;
|
||||||
|
|
||||||
namespace BootstrapAdmin.Web
|
namespace BootstrapAdmin.Web;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public partial class App
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class App
|
public string? Title { get; set; }
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
[NotNull]
|
||||||
|
private BootstrapAppContext? AppContext { get; set; }
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
[NotNull]
|
||||||
|
private NavigationManager? NavigationManager { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
/// <summary>
|
base.OnInitialized();
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public string? Title { get; set; }
|
|
||||||
|
|
||||||
[Inject]
|
AppContext.BaseUri = NavigationManager.ToAbsoluteUri(NavigationManager.BaseUri);
|
||||||
[NotNull]
|
|
||||||
private BootstrapAppContext? AppContext { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
protected override void OnInitialized()
|
|
||||||
{
|
|
||||||
base.OnInitialized();
|
|
||||||
|
|
||||||
//Title = DictHelper.RetrieveWebTitle(AppContext.AppId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -1,5 +1,4 @@
|
||||||
using BootstrapAdmin.Web.Core;
|
using BootstrapAdmin.Web.Core;
|
||||||
using BootstrapAdmin.Web.Services;
|
|
||||||
using Microsoft.JSInterop;
|
using Microsoft.JSInterop;
|
||||||
|
|
||||||
namespace BootstrapAdmin.Web.Components;
|
namespace BootstrapAdmin.Web.Components;
|
||||||
|
@ -75,7 +74,6 @@ public partial class AdminLogin : IDisposable
|
||||||
base.OnInitialized();
|
base.OnInitialized();
|
||||||
|
|
||||||
Title = DictsService.GetWebTitle();
|
Title = DictsService.GetWebTitle();
|
||||||
|
|
||||||
PostUrl = QueryHelper.AddQueryString("/Account/Login", new Dictionary<string, string?>
|
PostUrl = QueryHelper.AddQueryString("/Account/Login", new Dictionary<string, string?>
|
||||||
{
|
{
|
||||||
["ReturnUrl"] = ReturnUrl,
|
["ReturnUrl"] = ReturnUrl,
|
||||||
|
|
|
@ -52,7 +52,9 @@ namespace BootstrapAdmin.Web.Controllers
|
||||||
period = dictService.GetCookieExpiresPeriod();
|
period = dictService.GetCookieExpiresPeriod();
|
||||||
}
|
}
|
||||||
|
|
||||||
return auth ? await SignInAsync(userName, LoginHelper.GetDefaultUrl(userName, returnUrl, appId, context.AppId, userService, dictService), persistent, period) : RedirectLogin(returnUrl);
|
context.UserName = userName;
|
||||||
|
context.BaseUri = new Uri($"{Request.Scheme}://{Request.Host}/");
|
||||||
|
return auth ? await SignInAsync(userName, LoginHelper.GetDefaultUrl(context, returnUrl, appId, userService, dictService), persistent, period) : RedirectLogin(returnUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IActionResult> SignInAsync(string userName, string returnUrl, bool persistent, int period = 0, string authenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme)
|
private async Task<IActionResult> SignInAsync(string userName, string returnUrl, bool persistent, int period = 0, string authenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme)
|
||||||
|
@ -139,7 +141,10 @@ namespace BootstrapAdmin.Web.Controllers
|
||||||
{
|
{
|
||||||
userService.TryCreateUserByPhone(phone, code, context.AppId, provider.Options.Roles);
|
userService.TryCreateUserByPhone(phone, code, context.AppId, provider.Options.Roles);
|
||||||
}
|
}
|
||||||
return auth ? await SignInAsync(phone, LoginHelper.GetDefaultUrl(phone, returnUrl, appId, context.AppId, userService, dictService), persistent, period, MobileSchema) : RedirectLogin(returnUrl);
|
|
||||||
|
context.UserName = phone;
|
||||||
|
context.BaseUri = new Uri(Request.Path.Value!);
|
||||||
|
return auth ? await SignInAsync(phone, LoginHelper.GetDefaultUrl(context, returnUrl, appId, userService, dictService), persistent, period, MobileSchema) : RedirectLogin(returnUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class Index : ComponentBase
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
// 查看是否自定义前台
|
// 查看是否自定义前台
|
||||||
Url = LoginHelper.GetDefaultUrl(Context.UserName, null, null, Context.AppId, UsersService, DictsService);
|
Url = LoginHelper.GetDefaultUrl(Context, null, null, UsersService, DictsService);
|
||||||
|
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
Navigation.NavigateTo(Url, true);
|
Navigation.NavigateTo(Url, true);
|
||||||
|
|
|
@ -24,6 +24,12 @@ namespace BootstrapAdmin.Web.Services
|
||||||
[NotNull]
|
[NotNull]
|
||||||
public string? DisplayName { get; internal set; }
|
public string? DisplayName { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获得/设置 应用程序基础地址 如 http://localhost:5210
|
||||||
|
/// </summary>
|
||||||
|
[NotNull]
|
||||||
|
public Uri? BaseUri { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using BootstrapAdmin.Web.Core;
|
using BootstrapAdmin.Web.Core;
|
||||||
|
using BootstrapAdmin.Web.Services;
|
||||||
|
|
||||||
namespace BootstrapAdmin.Web.Utils;
|
namespace BootstrapAdmin.Web.Utils;
|
||||||
|
|
||||||
|
@ -10,18 +11,21 @@ public static class LoginHelper
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="context"></param>
|
||||||
/// <param name="returnUrl"></param>
|
/// <param name="returnUrl"></param>
|
||||||
/// <param name="appId"></param>
|
/// <param name="appId"></param>
|
||||||
/// <param name="defaultAppId"></param>
|
|
||||||
/// <param name="userService"></param>
|
/// <param name="userService"></param>
|
||||||
/// <param name="dictService"></param>
|
/// <param name="dictService"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetDefaultUrl(string userName, string? returnUrl, string? appId, string defaultAppId, IUser userService, IDict dictService)
|
public static string GetDefaultUrl(BootstrapAppContext context, string? returnUrl, string? appId, IUser userService, IDict dictService)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(returnUrl))
|
if (string.IsNullOrEmpty(returnUrl))
|
||||||
{
|
{
|
||||||
// 查找 User 设置的默认应用
|
// 查找 User 设置的默认应用
|
||||||
|
var userName = context.UserName;
|
||||||
|
var defaultAppId = context.AppId;
|
||||||
|
var schema = context.BaseUri.Scheme;
|
||||||
|
var host = context.BaseUri.Host;
|
||||||
appId ??= userService.GetAppIdByUserName(userName) ?? defaultAppId;
|
appId ??= userService.GetAppIdByUserName(userName) ?? defaultAppId;
|
||||||
|
|
||||||
if (appId == defaultAppId && dictService.GetEnableDefaultApp())
|
if (appId == defaultAppId && dictService.GetEnableDefaultApp())
|
||||||
|
@ -32,7 +36,11 @@ public static class LoginHelper
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(appId))
|
if (!string.IsNullOrEmpty(appId))
|
||||||
{
|
{
|
||||||
returnUrl = dictService.GetHomeUrlByAppId(appId);
|
var appUrl = dictService.GetHomeUrlByAppId(appId);
|
||||||
|
if (!string.IsNullOrEmpty(appUrl))
|
||||||
|
{
|
||||||
|
returnUrl = string.Format(appUrl, schema, host);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue