Skip to content

Commit

Permalink
Merge pull request #3270 from sbwalker/dev
Browse files Browse the repository at this point in the history
if site login is disabled redirect Login to external identity provider
  • Loading branch information
sbwalker authored Sep 20, 2023
2 parents 53d0202 + e0ebf70 commit 6967a5c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
14 changes: 4 additions & 10 deletions Oqtane.Client/Modules/Admin/Login/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@inherits ModuleBase
@inject NavigationManager NavigationManager
@inject IUserService UserService
@inject ISettingService SettingService
@inject IServiceProvider ServiceProvider
@inject IStringLocalizer<Index> Localizer
@inject IStringLocalizer<SharedResources> SharedLocalizer
Expand Down Expand Up @@ -94,15 +95,8 @@
{
_togglepassword = SharedLocalizer["ShowPassword"];

if (PageState.Site.Settings.ContainsKey("LoginOptions:AllowSiteLogin") && !string.IsNullOrEmpty(PageState.Site.Settings["LoginOptions:AllowSiteLogin"]))
{
_allowsitelogin = bool.Parse(PageState.Site.Settings["LoginOptions:AllowSiteLogin"]);
}

if (PageState.Site.Settings.ContainsKey("ExternalLogin:ProviderType") && !string.IsNullOrEmpty(PageState.Site.Settings["ExternalLogin:ProviderType"]))
{
_allowexternallogin = true;
}
_allowsitelogin = bool.Parse(SettingService.GetSetting(PageState.Site.Settings, "LoginOptions:AllowSiteLogin", "true"));
_allowexternallogin = (SettingService.GetSetting(PageState.Site.Settings, "ExternalLogin:ProviderType", "") != "") ? true : false;

if (PageState.QueryString.ContainsKey("returnurl"))
{
Expand Down Expand Up @@ -220,7 +214,7 @@
}
else
{
if ((PageState.Site.Settings.ContainsKey("LoginOptions:TwoFactor") && PageState.Site.Settings["LoginOptions:TwoFactor"] == "required") || user.TwoFactorRequired)
if (SettingService.GetSetting(PageState.Site.Settings, "LoginOptions:TwoFactor", "false") == "required" || user.TwoFactorRequired)
{
twofactor = true;
validated = false;
Expand Down
5 changes: 1 addition & 4 deletions Oqtane.Client/Modules/Admin/UserProfile/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,7 @@ else

_togglepassword = SharedLocalizer["ShowPassword"];

if (PageState.Site.Settings.ContainsKey("LoginOptions:TwoFactor") && !string.IsNullOrEmpty(PageState.Site.Settings["LoginOptions:TwoFactor"]))
{
allowtwofactor = (PageState.Site.Settings["LoginOptions:TwoFactor"] == "true");
}
allowtwofactor = (SettingService.GetSetting(PageState.Site.Settings, "LoginOptions:TwoFactor", "false") == "true");

if (PageState.User != null)
{
Expand Down
12 changes: 11 additions & 1 deletion Oqtane.Client/Themes/Controls/Theme/LoginBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,23 @@ public class LoginBase : ThemeControlBase
{
[Inject] public NavigationManager NavigationManager { get; set; }
[Inject] public IUserService UserService { get; set; }
[Inject] public ISettingService SettingService { get; set; }
[Inject] public IJSRuntime jsRuntime { get; set; }
[Inject] public IServiceProvider ServiceProvider { get; set; }

private bool _allowsitelogin = true;

protected void LoginUser()
{
Route route = new Route(PageState.Uri.AbsoluteUri, PageState.Alias.Path);
NavigationManager.NavigateTo(NavigateUrl("login", "?returnurl=" + WebUtility.UrlEncode(route.PathAndQuery)));
if (bool.Parse(SettingService.GetSetting(PageState.Site.Settings, "LoginOptions:AllowSiteLogin", "true")))
{
NavigationManager.NavigateTo(NavigateUrl("login", "?returnurl=" + WebUtility.UrlEncode(route.PathAndQuery)));
}
else
{
NavigationManager.NavigateTo(Utilities.TenantUrl(PageState.Alias, "/pages/external?returnurl=" + WebUtility.UrlEncode(route.PathAndQuery)), true);
}
}

protected async Task LogoutUser()
Expand Down

0 comments on commit 6967a5c

Please sign in to comment.