From 087697ba7f3a21d9617c70265a87f756e53a77e6 Mon Sep 17 00:00:00 2001 From: vfedosevich Date: Mon, 20 Apr 2015 03:01:21 -0700 Subject: [PATCH] password reset fixes --- WebsitePanel/Database/update_db.sql | 10 ++++-- .../System/SystemSettings.cs | 22 ++++++++++++- .../ExchangeServerController.cs | 8 ++++- .../HostedSolution/OrganizationController.cs | 31 ++++++++++++++++--- .../Controllers/AccountController.cs | 12 ++++++- .../Models/AccountModel.cs | 2 ++ .../Views/Account/Login.cshtml | 6 +++- .../Views/Shared/_Layout.cshtml | 13 +++++--- .../SystemSettings.ascx.resx | 6 ++++ .../UserOrganization.ascx.resx | 3 ++ .../ExchangeServer/OrganizationHome.ascx | 8 ----- .../ExchangeServer/OrganizationHome.ascx.cs | 3 -- .../OrganizationHome.ascx.designer.cs | 18 ----------- .../OrganizationUserGeneralSettings.ascx.cs | 8 +++++ .../WebsitePanel/SystemSettings.ascx | 6 ++++ .../WebsitePanel/SystemSettings.ascx.cs | 3 ++ .../SystemSettings.ascx.designer.cs | 18 +++++++++++ .../UserControls/OrganizationMenuControl.cs | 2 ++ 18 files changed, 133 insertions(+), 46 deletions(-) diff --git a/WebsitePanel/Database/update_db.sql b/WebsitePanel/Database/update_db.sql index 0490afd7..9fa58a77 100644 --- a/WebsitePanel/Database/update_db.sql +++ b/WebsitePanel/Database/update_db.sql @@ -9850,7 +9850,7 @@ Hello #user.FirstName#, Your password expiration date is #user.PasswordExpirationDateTime#. You can reset your own password by visiting the following page:

-#passwordResetLink# +#passwordResetLink#

@@ -9963,7 +9963,7 @@ Hello #user.FirstName#, We received a request to reset the password for your account. If you made this request, click the link below. If you did not make this request, you can ignore this email.

-#passwordResetLink# +#passwordResetLink#

@@ -10139,10 +10139,12 @@ Set @ExchangeMailboxSetupLetterHtmlBody = N'E-mail: #Account.PrimaryEmailAddress# + Password Reset Url: - Click here + Click here +

DNS

@@ -10308,8 +10310,10 @@ The following user accounts have been created for you. Username: #Account.UserPrincipalName# E-mail: #Account.PrimaryEmailAddress# + Password Reset Url: #PswResetUrl# + ================================= DNS diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Base/System/SystemSettings.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Base/System/SystemSettings.cs index 89033a84..d3edc7ee 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Base/System/SystemSettings.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Base/System/SystemSettings.cs @@ -27,6 +27,7 @@ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using System; +using System.Linq; using System.Xml; using System.Collections.Generic; using System.Text; @@ -46,6 +47,7 @@ namespace WebsitePanel.EnterpriseServer public const string PACKAGE_DISPLAY_SETTINGS = "PackageDisplaySettings"; public const string RDS_SETTINGS = "RdsSettings"; public const string WEBDAV_PORTAL_SETTINGS = "WebdavPortalSettings"; + public const string WEBDAV_PASSWORD_RESET_ENABLED_KEY = "WebdavPasswordResetEnabled"; // key to access to wpi main & custom feed in wpi settings public const string WPI_MAIN_FEED_KEY = "WpiMainFeedUrl"; @@ -98,7 +100,25 @@ namespace WebsitePanel.EnterpriseServer } } - public int GetInt(string settingName) + public bool Contains(string settingName) + { + return Settings.AllKeys.Any(x => x.ToLowerInvariant() == (settingName ?? string.Empty).ToLowerInvariant()); + } + + public T GetValueOrDefault(string settingName, T defaultValue) + { + try + { + return (T)Convert.ChangeType(Settings[settingName], typeof(T)); + } + catch + { + } + + return defaultValue; + } + + public int GetInt(string settingName) { return Int32.Parse(Settings[settingName]); } diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/ExchangeServer/ExchangeServerController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/ExchangeServer/ExchangeServerController.cs index b6458e47..47a17473 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/ExchangeServer/ExchangeServerController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/ExchangeServer/ExchangeServerController.cs @@ -2613,10 +2613,16 @@ namespace WebsitePanel.EnterpriseServer // add account items["Account"] = account; - items["PswResetUrl"] = OrganizationController.GenerateUserPasswordResetLink(account.ItemId, account.AccountId); items["AccountDomain"] = account.PrimaryEmailAddress.Substring(account.PrimaryEmailAddress.IndexOf("@") + 1); items["DefaultDomain"] = org.DefaultDomain; + var passwordResetUrl = OrganizationController.GenerateUserPasswordResetLink(account.ItemId, account.AccountId); + if (!string.IsNullOrEmpty(passwordResetUrl)) + { + items["PswResetUrl"] = passwordResetUrl; + } + + if (!String.IsNullOrEmpty(account.SamAccountName)) { int idx = account.SamAccountName.IndexOf("\\"); diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/HostedSolution/OrganizationController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/HostedSolution/OrganizationController.cs index 404ce57d..15ca5e96 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/HostedSolution/OrganizationController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/HostedSolution/OrganizationController.cs @@ -1684,6 +1684,11 @@ namespace WebsitePanel.EnterpriseServer throw new Exception("Webdav portal system settings are not set"); } + if (!settings.GetValueOrDefault(SystemSettings.WEBDAV_PASSWORD_RESET_ENABLED_KEY, false) ||!settings.Contains("WebdavPortalUrl")) + { + return string.Empty; + } + var webdavPortalUrl = new Uri(settings["WebdavPortalUrl"]); var token = CreateAccessToken(itemId, accountId, AccessTokenTypes.PasswrodReset); @@ -1794,11 +1799,12 @@ namespace WebsitePanel.EnterpriseServer NumbersCount = Utils.ParseInt(parts[4], 0), SymbolsCount = Utils.ParseInt(parts[5], 0), AccountLockoutThreshold = Utils.ParseInt(parts[7], 0), - EnforcePasswordHistory = Utils.ParseInt(parts[8], 0), - AccountLockoutDuration = Utils.ParseInt(parts[9], 0), - ResetAccountLockoutCounterAfter = Utils.ParseInt(parts[10], 0), - LockoutSettingsEnabled = Utils.ParseBool(parts[11], false), - PasswordComplexityEnabled = Utils.ParseBool(parts[12], true), + + EnforcePasswordHistory = GetValueSafe(parts, 8, 0), + AccountLockoutDuration = GetValueSafe(parts, 9, 0), + ResetAccountLockoutCounterAfter = GetValueSafe(parts, 10, 0), + LockoutSettingsEnabled = GetValueSafe(parts, 11, false), + PasswordComplexityEnabled = GetValueSafe(parts, 11, true), }; @@ -1821,6 +1827,21 @@ namespace WebsitePanel.EnterpriseServer return passwordSettings; } + public static T GetValueSafe(string[] array, int index, T defaultValue) + { + if (array.Length > index) + { + if (string.IsNullOrEmpty(array[index])) + { + return defaultValue; + } + + return (T)Convert.ChangeType(array[index], typeof(T)); + } + + return defaultValue; + } + public static void UpdateOrganizationGeneralSettings(int itemId, OrganizationGeneralSettings settings) { TaskManager.StartTask("ORGANIZATION", "UPDATE_GENERAL_SETTINGS"); diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/AccountController.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/AccountController.cs index f326b353..654fd5d8 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/AccountController.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/AccountController.cs @@ -44,7 +44,17 @@ namespace WebsitePanel.WebDavPortal.Controllers return RedirectToRoute(FileSystemRouteNames.ShowContentPath, new { org = WspContext.User.OrganizationId }); } - return View(); + var model = new AccountModel(); + + var settings = WspContext.Services.System.GetSystemSettings(EnterpriseServer.SystemSettings.WEBDAV_PORTAL_SETTINGS); + + if (settings != null) + { + model.PasswordResetEnabled = settings.GetValueOrDefault(EnterpriseServer.SystemSettings.WEBDAV_PASSWORD_RESET_ENABLED_KEY, false); + + } + + return View(model); } [HttpPost] diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Models/AccountModel.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Models/AccountModel.cs index 3093f79c..57351755 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Models/AccountModel.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Models/AccountModel.cs @@ -17,5 +17,7 @@ namespace WebsitePanel.WebDavPortal.Models public string Password { get; set; } public string LdapError { get; set; } + + public bool PasswordResetEnabled { get; set; } } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/Account/Login.cshtml b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/Account/Login.cshtml index 65d23735..23aaf2f0 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/Account/Login.cshtml +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/Account/Login.cshtml @@ -9,6 +9,7 @@
+ @Html.HiddenFor(x=>x.PasswordResetEnabled)

Sign In

@@ -33,7 +34,10 @@
- @UI.ForgotYourPassword + @if (Model.PasswordResetEnabled) + { + @UI.ForgotYourPassword + }
diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/Shared/_Layout.cshtml b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/Shared/_Layout.cshtml index 17e01610..0a08f09f 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/Shared/_Layout.cshtml +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/Shared/_Layout.cshtml @@ -28,11 +28,14 @@