From 6f60a91f4cd72b437d9018476b9e3b5bd0bbee87 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Thu, 1 May 2025 23:32:37 -0400 Subject: [PATCH] add new Register Url and Profile Url options to User Management / Settings --- Oqtane.Client/Modules/Admin/Users/Index.razor | 57 +++++++++++-------- .../Resources/Modules/Admin/Users/Index.resx | 14 ++++- .../Themes/Controls/Theme/UserProfile.razor | 27 +++++++-- 3 files changed, 69 insertions(+), 29 deletions(-) diff --git a/Oqtane.Client/Modules/Admin/Users/Index.razor b/Oqtane.Client/Modules/Admin/Users/Index.razor index a73350f0..d3eb9bc7 100644 --- a/Oqtane.Client/Modules/Admin/Users/Index.razor +++ b/Oqtane.Client/Modules/Admin/Users/Index.razor @@ -59,29 +59,23 @@ else + @if (_allowregistration == "true") + { +
+ +
+ +
+
+ } +
+ +
+ +
+
@if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) { - @if (_providertype != "") - { -
- -
- -
-
- } - else - { -
- -
- -
-
- }
@@ -432,6 +426,15 @@ else
+
+ +
+ +
+
} } @@ -485,7 +488,8 @@ else private List users; private string _allowregistration; - private string _allowsitelogin; + private string _registerurl; + private string _profileurl; private string _twofactor; private string _cookiename; private string _cookieexpiration; @@ -533,6 +537,7 @@ else private string _createusers; private string _verifyusers; private string _allowhostrole; + private string _allowsitelogin; private string _secret; private string _secrettype = "password"; @@ -553,7 +558,8 @@ else var settings = await SettingService.GetSiteSettingsAsync(PageState.Site.SiteId); _allowregistration = PageState.Site.AllowRegistration.ToString().ToLower(); - _allowsitelogin = SettingService.GetSetting(settings, "LoginOptions:AllowSiteLogin", "true"); + _registerurl = SettingService.GetSetting(settings, "LoginOptions:RegisterUrl", ""); + _profileurl = SettingService.GetSetting(settings, "LoginOptions:ProfileUrl", ""); if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) { @@ -616,6 +622,7 @@ else _createusers = SettingService.GetSetting(settings, "ExternalLogin:CreateUsers", "true"); _verifyusers = SettingService.GetSetting(settings, "ExternalLogin:VerifyUsers", "true"); _allowhostrole = SettingService.GetSetting(settings, "ExternalLogin:AllowHostRole", "false"); + _allowsitelogin = SettingService.GetSetting(settings, "LoginOptions:AllowSiteLogin", "true"); } private async Task LoadUsersAsync(bool load) @@ -673,10 +680,11 @@ else await SiteService.UpdateSiteAsync(site); var settings = await SettingService.GetSiteSettingsAsync(site.SiteId); - settings = SettingService.SetSetting(settings, "LoginOptions:AllowSiteLogin", _allowsitelogin, false); if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) { + settings = SettingService.SetSetting(settings, "LoginOptions:RegisterUrl", _registerurl, false); + settings = SettingService.SetSetting(settings, "LoginOptions:ProfileUrl", _profileurl, false); settings = SettingService.SetSetting(settings, "LoginOptions:TwoFactor", _twofactor, false); settings = SettingService.SetSetting(settings, "LoginOptions:CookieName", _cookiename, true); settings = SettingService.SetSetting(settings, "LoginOptions:CookieExpiration", _cookieexpiration, true); @@ -720,6 +728,7 @@ else settings = SettingService.SetSetting(settings, "ExternalLogin:CreateUsers", _createusers, true); settings = SettingService.SetSetting(settings, "ExternalLogin:VerifyUsers", _verifyusers, true); settings = SettingService.SetSetting(settings, "ExternalLogin:AllowHostRole", _allowhostrole, true); + settings = SettingService.SetSetting(settings, "LoginOptions:AllowSiteLogin", _allowsitelogin, false); settings = SettingService.SetSetting(settings, "JwtOptions:Secret", _secret, true); settings = SettingService.SetSetting(settings, "JwtOptions:Issuer", _issuer, true); diff --git a/Oqtane.Client/Resources/Modules/Admin/Users/Index.resx b/Oqtane.Client/Resources/Modules/Admin/Users/Index.resx index a0a7c1f4..c48ec4fa 100644 --- a/Oqtane.Client/Resources/Modules/Admin/Users/Index.resx +++ b/Oqtane.Client/Resources/Modules/Admin/Users/Index.resx @@ -132,6 +132,18 @@ Allow Registration? + + Optionally provide a custom registration url + + + Register Url: + + + Optionally provide a custom user profile url + + + Profile Url: + Error Saving Settings @@ -208,7 +220,7 @@ Do you want to allow users to sign in using a username and password that is managed locally on this site? Note that you should only disable this option if you have already sucessfully configured an external login provider, or else you may lock yourself out of the site. - Allow Login? + Allow Local Login? The authority url or issuer url associated with the identity provider diff --git a/Oqtane.Client/Themes/Controls/Theme/UserProfile.razor b/Oqtane.Client/Themes/Controls/Theme/UserProfile.razor index d408b2ae..e99eada5 100644 --- a/Oqtane.Client/Themes/Controls/Theme/UserProfile.razor +++ b/Oqtane.Client/Themes/Controls/Theme/UserProfile.razor @@ -1,6 +1,7 @@ @namespace Oqtane.Themes.Controls @using System.Net @inherits ThemeControlBase +@inject ISettingService SettingService @inject IStringLocalizer Localizer @inject NavigationManager NavigationManager @@ -51,20 +52,38 @@ if (!string.IsNullOrEmpty(RegisterUrl)) { - _registerurl = RegisterUrl + "?returnurl=" + (RegisterUrl.Contains("://") ? WebUtility.UrlEncode(PageState.Route.RootUrl) + _returnurl : _returnurl); + _registerurl = RegisterUrl; + _registerurl += (!_registerurl.Contains("?") ? "?" : "&") + "returnurl=" + (_registerurl.Contains("://") ? WebUtility.UrlEncode(PageState.Route.RootUrl) + _returnurl : _returnurl); } else { - _registerurl = NavigateUrl("register", "returnurl=" + _returnurl); + if (!string.IsNullOrEmpty(SettingService.GetSetting(PageState.Site.Settings, "LoginOptions:RegisterUrl", ""))) + { + _registerurl = SettingService.GetSetting(PageState.Site.Settings, "LoginOptions:RegisterUrl", ""); + _registerurl += (!_registerurl.Contains("?") ? "?" : "&") + "returnurl=" + (_registerurl.Contains("://") ? WebUtility.UrlEncode(PageState.Route.RootUrl) + _returnurl : _returnurl); + } + else + { + _registerurl = NavigateUrl("register", "returnurl=" + _returnurl); + } } if (!string.IsNullOrEmpty(ProfileUrl)) { - _profileurl = ProfileUrl + "?returnurl=" + (ProfileUrl.Contains("://") ? WebUtility.UrlEncode(PageState.Route.RootUrl) + _returnurl : _returnurl); + _profileurl = ProfileUrl; + _profileurl += (!_profileurl.Contains("?") ? "?" : "&") + "returnurl=" + (_profileurl.Contains("://") ? WebUtility.UrlEncode(PageState.Route.RootUrl) + _returnurl : _returnurl); } else { - _profileurl = NavigateUrl("profile", "returnurl=" + _returnurl); + if (!string.IsNullOrEmpty(SettingService.GetSetting(PageState.Site.Settings, "LoginOptions:ProfileUrl", ""))) + { + _profileurl = SettingService.GetSetting(PageState.Site.Settings, "LoginOptions:ProfileUrl", ""); + _profileurl += (!_profileurl.Contains("?") ? "?" : "&") + "returnurl=" + (_profileurl.Contains("://") ? WebUtility.UrlEncode(PageState.Route.RootUrl) + _returnurl : _returnurl); + } + else + { + _profileurl = NavigateUrl("profile", "returnurl=" + _returnurl); + } } } }