From ae79a7cd7adac2826ce08ecf960746e5c7a1779b Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 14 Nov 2014 18:26:01 +1100 Subject: [PATCH] Completes: U4-5810 Remove umbraco.providers assembly and classes - old membership providers --- src/Umbraco.Tests/Umbraco.Tests.csproj | 4 - src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 4 - .../Editors/AuthenticationController.cs | 11 - .../Models/Mapping/MemberModelMapper.cs | 2 +- src/Umbraco.Web/Security/WebSecurity.cs | 9 - src/Umbraco.Web/Umbraco.Web.csproj | 4 - .../umbraco/users/EditUser.aspx.cs | 6 - .../Properties/AssemblyInfo.cs | 21 - src/umbraco.providers/SecUtility.cs | 230 ---- .../UsersMembershipProvider.cs | 545 --------- src/umbraco.providers/UsersMembershipUser.cs | 95 -- src/umbraco.providers/UsersRoleProvider.cs | 197 ---- src/umbraco.providers/app.config | 19 - src/umbraco.providers/members/Helper.cs | 43 - .../members/MembershipEventHandler.cs | 37 - .../members/UmbracoMembershipProvider.cs | 1014 ----------------- .../members/UmbracoProfileProvider.cs | 187 --- .../members/UmbracoRoleProvider.cs | 289 ----- .../umbraco.providers.csproj | 144 --- src/umbraco.sln | 6 - 20 files changed, 1 insertion(+), 2866 deletions(-) delete mode 100644 src/umbraco.providers/Properties/AssemblyInfo.cs delete mode 100644 src/umbraco.providers/SecUtility.cs delete mode 100644 src/umbraco.providers/UsersMembershipProvider.cs delete mode 100644 src/umbraco.providers/UsersMembershipUser.cs delete mode 100644 src/umbraco.providers/UsersRoleProvider.cs delete mode 100644 src/umbraco.providers/app.config delete mode 100644 src/umbraco.providers/members/Helper.cs delete mode 100644 src/umbraco.providers/members/MembershipEventHandler.cs delete mode 100644 src/umbraco.providers/members/UmbracoMembershipProvider.cs delete mode 100644 src/umbraco.providers/members/UmbracoProfileProvider.cs delete mode 100644 src/umbraco.providers/members/UmbracoRoleProvider.cs delete mode 100644 src/umbraco.providers/umbraco.providers.csproj diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 1a29975872..6f05ff70af 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -602,10 +602,6 @@ {511F6D8D-7717-440A-9A57-A507E9A8B27F} umbraco.interfaces - - {d7636876-0756-43cb-a192-138c6f0d5e42} - umbraco.providers - {651E1350-91B6-44B7-BD60-7207006D7003} Umbraco.Web diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 81d16a1405..7778fd1d33 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -289,10 +289,6 @@ {651E1350-91B6-44B7-BD60-7207006D7003} Umbraco.Web - - {D7636876-0756-43CB-A192-138C6F0D5E42} - umbraco.providers - ..\packages\UrlRewritingNet.UrlRewriter.2.0.60829.1\lib\UrlRewritingNet.UrlRewriter.dll diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index 00498f7e61..99703e8eeb 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -1,26 +1,15 @@ using System; -using System.Collections.Generic; using System.Net; using System.Net.Http; -using System.Text; -using System.Web; -using System.Web.Helpers; using System.Web.Http; -using System.Web.Http.Controllers; -using System.Web.Security; using AutoMapper; -using Umbraco.Core; -using Umbraco.Core.Configuration; -using Umbraco.Core.Models.Membership; using Umbraco.Web.Models; using Umbraco.Web.Models.ContentEditing; -using Umbraco.Web.Models.Mapping; using Umbraco.Web.Mvc; using Umbraco.Core.Security; using Umbraco.Web.Security; using Umbraco.Web.WebApi; using Umbraco.Web.WebApi.Filters; -using umbraco.providers; namespace Umbraco.Web.Editors { diff --git a/src/Umbraco.Web/Models/Mapping/MemberModelMapper.cs b/src/Umbraco.Web/Models/Mapping/MemberModelMapper.cs index a1b544228a..2296efb9ab 100644 --- a/src/Umbraco.Web/Models/Mapping/MemberModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/MemberModelMapper.cs @@ -219,7 +219,7 @@ namespace Umbraco.Web.Models.Mapping }); //check if there's an approval field - var provider = membersProvider as global::umbraco.providers.members.UmbracoMembershipProvider; + var provider = membersProvider as IUmbracoMemberTypeMembershipProvider; if (member.HasIdentity == false && provider != null) { var approvedField = provider.ApprovedPropertyTypeAlias; diff --git a/src/Umbraco.Web/Security/WebSecurity.cs b/src/Umbraco.Web/Security/WebSecurity.cs index fbf30a002e..b8595115cc 100644 --- a/src/Umbraco.Web/Security/WebSecurity.cs +++ b/src/Umbraco.Web/Security/WebSecurity.cs @@ -1,24 +1,15 @@ using System; using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web; using System.Web.Security; -using Newtonsoft.Json.Linq; using Umbraco.Core; -using Umbraco.Core.Cache; -using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Models.Membership; using Umbraco.Core.Security; -using Umbraco.Web.Models; -using Umbraco.Web.Models.ContentEditing; using umbraco; -using umbraco.DataLayer; using umbraco.businesslogic.Exceptions; -using umbraco.providers; using GlobalSettings = Umbraco.Core.Configuration.GlobalSettings; -using Member = umbraco.cms.businesslogic.member.Member; using User = umbraco.BusinessLogic.User; namespace Umbraco.Web.Security diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 48235aa4ac..8ec870be6e 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -253,10 +253,6 @@ {511F6D8D-7717-440A-9A57-A507E9A8B27F} {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - {D7636876-0756-43CB-A192-138C6F0D5E42} - umbraco.providers - False ..\packages\UrlRewritingNet.UrlRewriter.2.0.60829.1\lib\UrlRewritingNet.UrlRewriter.dll diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs index 33877a082f..6e131dd57c 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs @@ -9,22 +9,16 @@ using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Xml; -using Umbraco.Core.Configuration; using Umbraco.Core.Logging; -using Umbraco.Core.Security; using Umbraco.Web; -using Umbraco.Web.Models; using Umbraco.Web.Security; using umbraco.BasePages; using umbraco.BusinessLogic; -using umbraco.businesslogic.Exceptions; -using umbraco.cms.businesslogic.media; using umbraco.cms.businesslogic.propertytype; using umbraco.cms.businesslogic.web; using umbraco.controls; using umbraco.presentation.channels.businesslogic; using umbraco.uicontrols; -using umbraco.providers; using umbraco.cms.presentation.Trees; using Umbraco.Core.IO; using Umbraco.Core; diff --git a/src/umbraco.providers/Properties/AssemblyInfo.cs b/src/umbraco.providers/Properties/AssemblyInfo.cs deleted file mode 100644 index 479c21fab9..0000000000 --- a/src/umbraco.providers/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("umbraco.providers")] -[assembly: AssemblyDescription("Core assembly containing umbraco specific membership providers")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyProduct("Umbraco CMS")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("5b071553-1474-44a0-9cad-52b3f3255639")] - -[assembly: InternalsVisibleTo("Umbraco.Tests")] \ No newline at end of file diff --git a/src/umbraco.providers/SecUtility.cs b/src/umbraco.providers/SecUtility.cs deleted file mode 100644 index 572d8fbc12..0000000000 --- a/src/umbraco.providers/SecUtility.cs +++ /dev/null @@ -1,230 +0,0 @@ -using System; -using System.Collections.Specialized; -using System.Collections; -using System.Globalization; -using System.Web.Hosting; -using System.Configuration.Provider; - -namespace umbraco.providers -{ - /// - /// Security Helper Methods - /// - [ObsoleteAttribute("This clas is obsolete and wil be removed along with the legacy Membership Provider.", false)] - internal class SecUtility - { - /// - /// Gets the boolean value. - /// - /// The config. - /// Name of the value. - /// if set to true [default value]. - /// - internal static bool GetBooleanValue(NameValueCollection config, string valueName, bool defaultValue) - { - bool flag; - string str = config[valueName]; - if (str == null) - return defaultValue; - - if (!bool.TryParse(str, out flag)) - { - throw new ProviderException("Value must be boolean."); - } - return flag; - } - - /// - /// Checks the array parameter. - /// - /// The param. - /// if set to true [check for null]. - /// if set to true [check if empty]. - /// if set to true [check for commas]. - /// Size of the max. - /// Name of the param. - internal static void CheckArrayParameter(ref string[] param, bool checkForNull, bool checkIfEmpty, bool checkForCommas, int maxSize, string paramName) - { - if (param == null) - { - throw new ArgumentNullException(paramName); - } - if (param.Length < 1) - { - throw new ArgumentException("Parameter array empty."); - } - Hashtable hashtable = new Hashtable(param.Length); - for (int i = param.Length - 1; i >= 0; i--) - { - CheckParameter(ref param[i], checkForNull, checkIfEmpty, checkForCommas, maxSize, paramName + "[ " + i.ToString(CultureInfo.InvariantCulture) + " ]"); - if (hashtable.Contains(param[i])) - { - throw new ArgumentException("Parameter duplicate array element"); - } - hashtable.Add(param[i], param[i]); - } - } - - /// - /// Checks the parameter. - /// - /// The param. - /// if set to true [check for null]. - /// if set to true [check if empty]. - /// if set to true [check for commas]. - /// Size of the max. - /// Name of the param. - internal static void CheckParameter(ref string param, bool checkForNull, bool checkIfEmpty, bool checkForCommas, int maxSize, string paramName) - { - if (param == null) - { - if (checkForNull) - { - throw new ArgumentNullException(paramName); - } - } - else - { - param = param.Trim(); - if (checkIfEmpty && (param.Length < 1)) - { - throw new ProviderException("Parameter can not be empty."); - } - if ((maxSize > 0) && (param.Length > maxSize)) - { - throw new ProviderException("Parameter too long."); - } - if (checkForCommas && param.Contains(",")) - { - throw new ProviderException("Parameter cannot contain comman."); - } - } - } - - /// - /// Checks the password parameter. - /// - /// The param. - /// Size of the max. - /// Name of the param. - internal static void CheckPasswordParameter(ref string param, int maxSize, string paramName) - { - if (param == null) - { - throw new ArgumentNullException(paramName); - } - if (param.Length < 1) - { - throw new ProviderException("Parameter can not be empty"); - } - if ((maxSize > 0) && (param.Length > maxSize)) - { - throw new ProviderException("Parameter too long"); - } - } - - /// - /// Gets the name of the default app. - /// - /// - internal static string GetDefaultAppName() - { - try - { - string applicationVirtualPath = HostingEnvironment.ApplicationVirtualPath; - if (string.IsNullOrEmpty(applicationVirtualPath)) - { - return "/"; - } - return applicationVirtualPath; - } - catch - { - return "/"; - } - } - - /// - /// Gets the int value. - /// - /// The config. - /// Name of the value. - /// The default value. - /// if set to true [zero allowed]. - /// The max value allowed. - /// - internal static int GetIntValue(NameValueCollection config, string valueName, int defaultValue, bool zeroAllowed, int maxValueAllowed) - { - int num; - string s = config[valueName]; - if (s == null) - { - return defaultValue; - } - if (!int.TryParse(s, out num)) - { - if (zeroAllowed) - { - throw new ProviderException("Value must be non negative integer"); - } - throw new ProviderException("Value must be positive integer"); - } - if (zeroAllowed && (num < 0)) - { - throw new ProviderException("Value must be non negativeinteger"); - } - if (!zeroAllowed && (num <= 0)) - { - throw new ProviderException("Value must be positive integer"); - } - if ((maxValueAllowed > 0) && (num > maxValueAllowed)) - { - throw new ProviderException("Value too big"); - } - return num; - } - - /// - /// Validates the parameter. - /// - /// The param. - /// if set to true [check for null]. - /// if set to true [check if empty]. - /// if set to true [check for commas]. - /// Size of the max. - /// - internal static bool ValidateParameter(ref string param, bool checkForNull, bool checkIfEmpty, bool checkForCommas, int maxSize) - { - if (param == null) - { - return !checkForNull; - } - param = param.Trim(); - return (((!checkIfEmpty || (param.Length >= 1)) && ((maxSize <= 0) || (param.Length <= maxSize))) && (!checkForCommas || !param.Contains(","))); - } - - - /// - /// Validates the password parameter. - /// - /// The param. - /// Size of the max. - /// - internal static bool ValidatePasswordParameter(ref string param, int maxSize) - { - if (param == null) - { - return false; - } - if (param.Length < 1) - { - return false; - } - if ((maxSize > 0) && (param.Length > maxSize)) - { - return false; - } - return true; - } - } -} diff --git a/src/umbraco.providers/UsersMembershipProvider.cs b/src/umbraco.providers/UsersMembershipProvider.cs deleted file mode 100644 index df190a8ac0..0000000000 --- a/src/umbraco.providers/UsersMembershipProvider.cs +++ /dev/null @@ -1,545 +0,0 @@ -#region namespace -using System; -using System.Collections.Generic; -using System.Web.Security; -using System.Configuration; -using Umbraco.Core; -using Umbraco.Core.Security; -using umbraco.BusinessLogic; -using System.Web.Util; -using System.Configuration.Provider; -using System.Linq; -#endregion - -namespace umbraco.providers -{ - /// - /// Custom Membership Provider for Umbraco Users (User authentication for Umbraco Backend CMS) - /// - [Obsolete("This has been superceded by Umbraco.Web.Security.Providers.UsersMembershipProvider")] - public class UsersMembershipProvider : MembershipProviderBase, IUsersMembershipProvider - { - - /// - /// Override to maintain backwards compatibility with 0 required non-alphanumeric chars - /// - public override int DefaultMinNonAlphanumericChars - { - get { return 0; } - } - - /// - /// Override to maintain backwards compatibility with only 4 required length - /// - public override int DefaultMinPasswordLength - { - get { return 4; } - } - - /// - /// Override to maintain backwards compatibility - /// - public override bool DefaultUseLegacyEncoding - { - get { return true; } - } - - /// - /// For backwards compatibility, this provider supports this option - /// - public override bool AllowManuallyChangingPassword - { - get { return true; } - } - - public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) - { - if (config == null) throw new ArgumentNullException("config"); - if (string.IsNullOrEmpty(name)) name = UmbracoSettings.DefaultBackofficeProvider; - - base.Initialize(name, config); - } - - #region Methods - - /// - /// Processes a request to update the password for a membership user. - /// - /// The user to update the password for. - /// The current password for the specified user. - /// The new password for the specified user. - /// - /// true if the password was updated successfully; otherwise, false. - /// - protected override bool PerformChangePassword(string username, string oldPassword, string newPassword) - { - //NOTE: due to backwards compatibilty reasons (and UX reasons), this provider doesn't care about the old password and - // allows simply setting the password manually so we don't really care about the old password. - // This is allowed based on the overridden AllowManuallyChangingPassword option. - - var user = new User(username); - //encrypt/hash the new one - string salt; - var encodedPassword = EncryptOrHashNewPassword(newPassword, out salt); - - //Yes, it's true, this actually makes a db call to set the password - user.Password = FormatPasswordForStorage(encodedPassword, salt); - //call this just for fun. - user.Save(); - - return true; - } - - /// - /// Processes a request to update the password question and answer for a membership user. - /// - /// The user to change the password question and answer for. - /// The password for the specified user. - /// The new password question for the specified user. - /// The new password answer for the specified user. - /// - /// true if the password question and answer are updated successfully; otherwise, false. - /// - protected override bool PerformChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer) - { - throw new NotImplementedException(); - } - - /// - /// Adds a new membership user to the data source. - /// - /// The user name for the new user. - /// The password for the new user. - /// The e-mail address for the new user. - /// The password question for the new user. - /// The password answer for the new user - /// Whether or not the new user is approved to be validated. - /// The unique identifier from the membership data source for the user. - /// A enumeration value indicating whether the user was created successfully. - /// - /// A object populated with the information for the newly created user. - /// - protected override MembershipUser PerformCreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) - { - - // TODO: Does umbraco allow duplicate emails?? - //if (RequiresUniqueEmail && !string.IsNullOrEmpty(GetUserNameByEmail(email))) - //{ - // status = MembershipCreateStatus.DuplicateEmail; - // return null; - //} - - var u = GetUser(username, false) as UsersMembershipUser; - if (u == null) - { - try - { - // Get the usertype of the current user - var ut = UserType.GetUserType(1); - if (BasePages.UmbracoEnsuredPage.CurrentUser != null) - { - ut = BasePages.UmbracoEnsuredPage.CurrentUser.UserType; - } - - //ensure the password is encrypted/hashed - string salt; - var encodedPass = EncryptOrHashNewPassword(password, out salt); - - User.MakeNew(username, username, FormatPasswordForStorage(encodedPass, salt), email, ut); - - status = MembershipCreateStatus.Success; - } - catch (Exception) - { - status = MembershipCreateStatus.ProviderError; - } - return GetUser(username, false); - } - - status = MembershipCreateStatus.DuplicateUserName; - return null; - } - - /// - /// Removes a user from the membership data source. - /// - /// The name of the user to delete. - /// true to delete data related to the user from the database; false to leave data related to the user in the database. - /// - /// true if the user was successfully deleted; otherwise, false. - /// - public override bool DeleteUser(string username, bool deleteAllRelatedData) - { - try - { - User user = new User(username); - user.delete(); - } - catch (Exception) - { - return false; - } - return true; - } - - /// - /// Gets a collection of membership users where the e-mail address contains the specified e-mail address to match. - /// - /// The e-mail address to search for. - /// The index of the page of results to return. pageIndex is zero-based. - /// The size of the page of results to return. - /// The total number of matched users. - /// - /// A collection that contains a page of pageSize objects beginning at the page specified by pageIndex. - /// - public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords) - { - var counter = 0; - var startIndex = pageSize * pageIndex; - var endIndex = startIndex + pageSize - 1; - var usersList = new MembershipUserCollection(); - var usersArray = User.getAllByEmail(emailToMatch); - totalRecords = usersArray.Length; - - foreach (var user in usersArray) - { - if (counter >= startIndex) - usersList.Add(ConvertToMembershipUser(user)); - if (counter >= endIndex) break; - counter++; - } - return usersList; - } - - /// - /// Gets a collection of membership users where the user name contains the specified user name to match. - /// - /// The user name to search for. - /// The index of the page of results to return. pageIndex is zero-based. - /// The size of the page of results to return. - /// The total number of matched users. - /// - /// A collection that contains a page of pageSize objects beginning at the page specified by pageIndex. - /// - public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) - { - var counter = 0; - var startIndex = pageSize * pageIndex; - var endIndex = startIndex + pageSize - 1; - var usersList = new MembershipUserCollection(); - var usersArray = User.GetAllByLoginName(usernameToMatch, true).ToArray(); - totalRecords = usersArray.Length; - - foreach (var user in usersArray) - { - if (counter >= startIndex) - usersList.Add(ConvertToMembershipUser(user)); - if (counter >= endIndex) break; - counter++; - } - return usersList; - } - - /// - /// Gets a collection of all the users in the data source in pages of data. - /// - /// The index of the page of results to return. pageIndex is zero-based. - /// The size of the page of results to return. - /// The total number of matched users. - /// - /// A collection that contains a page of pageSize objects beginning at the page specified by pageIndex. - /// - public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) - { - var counter = 0; - var startIndex = pageSize * pageIndex; - var endIndex = startIndex + pageSize - 1; - var usersList = new MembershipUserCollection(); - var usersArray = User.getAll(); - totalRecords = usersArray.Length; - - foreach (User user in usersArray) - { - if (counter >= startIndex) - usersList.Add(ConvertToMembershipUser(user)); - if (counter >= endIndex) break; - counter++; - } - return usersList; - } - - /// - /// Gets the number of users currently accessing the application. - /// - /// - /// The number of users currently accessing the application. - /// - public override int GetNumberOfUsersOnline() - { - var fromDate = DateTime.Now.AddMinutes(-Membership.UserIsOnlineTimeWindow); - return Log.Instance.GetLogItems(LogTypes.Login, fromDate).Count; - } - - /// - /// Gets the password for the specified user name from the data source. This is - for security - not - /// supported for Umbraco Users and an exception will be thrown - /// - /// The user to retrieve the password for. - /// The password answer for the user. - /// - /// The password for the specified user name. - /// - protected override string PerformGetPassword(string username, string answer) - { - var found = User.GetAllByLoginName(username, false).ToArray(); - if (found == null || found.Any() == false) - { - throw new MembershipPasswordException("The supplied user is not found"); - } - - // check if user is locked out - if (found.First().NoConsole) - { - throw new MembershipPasswordException("The supplied user is locked out"); - } - - if (RequiresQuestionAndAnswer) - { - throw new NotImplementedException("Question/answer is not supported with this membership provider"); - } - - var decodedPassword = DecryptPassword(found.First().GetPassword()); - - return decodedPassword; - } - - /// - /// Gets information from the data source for a user. Provides an option to update the last-activity date/time stamp for the user. - /// - /// The name of the user to get information for. - /// true to update the last-activity date/time stamp for the user; false to return user information without updating the last-activity date/time stamp for the user. - /// - /// A object populated with the specified user's information from the data source. - /// - public override MembershipUser GetUser(string username, bool userIsOnline) - { - var userId = User.getUserId(username); - if (userId == -1) - { - return null; - } - - try - { - var user = new User(userId); - - //We need to log this since it's the only way we can determine the number of users online - Log.Add(LogTypes.Login, user, -1, "User " + username + " has logged in"); - - return (userId != -1) ? ConvertToMembershipUser(user) : null; - } - catch (Exception) - { - return null; - } - } - - /// - /// Gets information from the data source for a user based on the unique identifier for the membership user. Provides an option to update the last-activity date/time stamp for the user. - /// - /// The unique identifier for the membership user to get information for. - /// true to update the last-activity date/time stamp for the user; false to return user information without updating the last-activity date/time stamp for the user. - /// - /// A object populated with the specified user's information from the data source. - /// - public override MembershipUser GetUser(object providerUserKey, bool userIsOnline) - { - var user = new User(Convert.ToInt32(providerUserKey)); - //We need to log this since it's the only way we can determine the number of users online - Log.Add(LogTypes.Login, user, -1, "User " + user.LoginName + " has logged in"); - return ConvertToMembershipUser(user); - } - - /// - /// Gets the user name associated with the specified e-mail address. - /// - /// The e-mail address to search for. - /// - /// The user name associated with the specified e-mail address. If no match is found, return null. - /// - public override string GetUserNameByEmail(string email) - { - var found = User.getAllByEmail(email.Trim().ToLower(), true); - if (found == null || found.Any() == false) - { - return null; - } - return found.First().LoginName; - } - - /// - /// Resets a user's password to a new, automatically generated password. - /// - /// The user to reset the password for. - /// The password answer for the specified user. - /// The new password for the specified user. - protected override string PerformResetPassword(string username, string answer, string generatedPassword) - { - //TODO: This should be here - but how do we update failure count in this provider?? - //if (answer == null && RequiresQuestionAndAnswer) - //{ - // UpdateFailureCount(username, "passwordAnswer"); - - // throw new ProviderException("Password answer required for password reset."); - //} - - var found = User.GetAllByLoginName(username, false).ToArray(); - if (found == null || found.Any() == false) - throw new MembershipPasswordException("The supplied user is not found"); - - var user = found.First(); - - //Yes, it's true, this actually makes a db call to set the password - string salt; - var encPass = EncryptOrHashNewPassword(generatedPassword, out salt); - user.Password = FormatPasswordForStorage(encPass, salt); - //call this just for fun. - user.Save(); - - return generatedPassword; - } - - /// - /// Clears a lock so that the membership user can be validated. - /// - /// The membership user to clear the lock status for. - /// - /// true if the membership user was successfully unlocked; otherwise, false. - /// - public override bool UnlockUser(string userName) - { - try - { - var user = new User(userName) - { - NoConsole = false - }; - user.Save(); - } - catch (Exception) - { - return false; - } - return true; - } - - /// - /// Updates information about a user in the data source. - /// - /// A object that represents the user to update and the updated information for the user. - public override void UpdateUser(MembershipUser user) - { - var found = User.GetAllByLoginName(user.UserName, false).ToArray(); - if (found == null || found.Any() == false) - { - throw new ProviderException("The supplied user is not found"); - } - - var m = found.First(); - if (RequiresUniqueEmail && user.Email.Trim().IsNullOrWhiteSpace() == false) - { - var byEmail = User.getAllByEmail(user.Email, true); - if (byEmail.Count(x => x.Id != m.Id) > 0) - { - throw new ProviderException(string.Format("A member with the email '{0}' already exists", user.Email)); - } - } - - var typedUser = user as UsersMembershipUser; - if (typedUser == null) - { - // update approve status - // update lock status - // TODO: Update last lockout time - // TODO: update comment - User.Update(m.Id, user.Email, user.IsApproved == false, user.IsLockedOut); - } - else - { - //This keeps compatibility - even though this logic to update name and user type should not exist here - User.Update(m.Id, typedUser.FullName.Trim(), typedUser.UserName, typedUser.Email, user.IsApproved == false, user.IsLockedOut, typedUser.UserType); - } - - m.Save(); - } - - /// - /// Verifies that the specified user name and password exist in the data source. - /// - /// The name of the user to validate. - /// The password for the specified user. - /// - /// true if the specified username and password are valid; otherwise, false. - /// - public override bool ValidateUser(string username, string password) - { - var userId = User.getUserId(username); - if (userId != -1) - { - var user = User.GetUser(userId); - if (user != null) - { - if (user.Disabled) - { - return false; - } - - return CheckPassword(password, user.Password); - } - } - return false; - } - #endregion - - #region Helper Methods - - - /// - /// Encodes the password. - /// - /// The password. - /// The encoded password. - [Obsolete("Do not use this, it is the legacy way to encode a password")] - public string EncodePassword(string password) - { - return base.LegacyEncodePassword(password); - } - - /// - /// Unencode password. - /// - /// The encoded password. - /// The unencoded password. - [Obsolete("Do not use this, it is the legacy way to decode a password")] - public string UnEncodePassword(string encodedPassword) - { - return LegacyUnEncodePassword(encodedPassword); - } - - /// - /// Converts to membership user. - /// - /// The user. - /// - private UsersMembershipUser ConvertToMembershipUser(User user) - { - if (user == null) return null; - return new UsersMembershipUser(base.Name, user.LoginName, user.Id, user.Email, - string.Empty, string.Empty, true, user.Disabled, - DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, - DateTime.Now, user.Name, user.Language, user.UserType); - } - - #endregion - } -} diff --git a/src/umbraco.providers/UsersMembershipUser.cs b/src/umbraco.providers/UsersMembershipUser.cs deleted file mode 100644 index dd406662dc..0000000000 --- a/src/umbraco.providers/UsersMembershipUser.cs +++ /dev/null @@ -1,95 +0,0 @@ -#region namespace -using System; -using System.Collections.Generic; -using System.Text; -using System.Web.Security; -using umbraco.BusinessLogic; -using System.Data; -#endregion - -namespace umbraco.providers -{ - /// - /// Wrapper for the umbraco.BusinessLogic.User class. - /// - [Obsolete("This class is used by the legacy user's membership provider which is also obsolete, this shouldn't be referenced directly in code, the standard .Net MembershipUser base class object should be referenced instead.")] - public class UsersMembershipUser : MembershipUser - { - #region Fields and Properties - private string _FullName; - - /// - /// Gets or sets the full name. - /// - /// The full name. - public string FullName - { - get { return _FullName; } - set { _FullName = value; } - } - private string _Language; - - /// - /// Gets or sets the language. - /// - /// The language. - public string Language - { - get { return _Language; } - set { _Language = value; } - } - private UserType _UserType; - - /// - /// Gets or sets the type of the user. - /// - /// The type of the user. - public UserType UserType - { - get { return _UserType; } - set { _UserType = value; } - } - #endregion - - #region Constructors - /// - /// Initializes a new instance of the class. - /// - protected UsersMembershipUser() - { - - } - - /// - /// Initializes a new instance of the class. - /// - /// Name of the provider. - /// The name. - /// The provider user key. - /// The email. - /// The password question. - /// The comment. - /// if set to true [is approved]. - /// if set to true [is locked out]. - /// The creation date. - /// The last login date. - /// The last activity date. - /// The last password changed date. - /// The last lockout date. - /// The full name. - /// The language. - /// Type of the user. - public UsersMembershipUser(string providerName, string name, object providerUserKey, string email, - string passwordQuestion, string comment, bool isApproved, bool isLockedOut, - DateTime creationDate, DateTime lastLoginDate, DateTime lastActivityDate, DateTime lastPasswordChangedDate, - DateTime lastLockoutDate, string fullName, string language, UserType userType ) - : base( providerName, name, providerUserKey, email, passwordQuestion, comment, isApproved, isLockedOut, - creationDate, lastLoginDate, lastActivityDate, lastPasswordChangedDate, lastLockoutDate) - { - _FullName = fullName; - _UserType = userType; - _Language = language; - } - #endregion - } -} diff --git a/src/umbraco.providers/UsersRoleProvider.cs b/src/umbraco.providers/UsersRoleProvider.cs deleted file mode 100644 index e18dc0c7a1..0000000000 --- a/src/umbraco.providers/UsersRoleProvider.cs +++ /dev/null @@ -1,197 +0,0 @@ -#region namespace -using System; -using System.Collections.Generic; -using System.Text; -using System.Configuration.Provider; -using System.Web.Security; -using System.Collections.Specialized; -#endregion - -namespace umbraco.providers -{ - /// - /// Custom Roles Provider for Umbraco - /// - [Obsolete("This is not used and no methods are implemented, it will be removed in future versions")] - public class UsersRoleProvider : RoleProvider - { - #region - private string _applicationName; - #endregion - - #region Properties - /// - /// Gets or sets the name of the application to store and retrieve role information for. - /// - /// - /// The name of the application to store and retrieve role information for. - public override string ApplicationName - { - get - { - return _applicationName; - } - set - { - if (string.IsNullOrEmpty(value)) - throw new ProviderException("ApplicationName cannot be empty."); - - if (value.Length > 0x100) - throw new ProviderException("Provider application name too long."); - - _applicationName = value; - } - } - #endregion - - #region Initialization Method - /// - /// Initializes the provider. - /// - /// The friendly name of the provider. - /// A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider. - /// The name of the provider is null. - /// An attempt is made to call - /// on a provider - /// after the provider has already been initialized. - /// The name of the provider has a length of zero. - public override void Initialize(string name, NameValueCollection config) - { - // Initialize values from web.config - if (config == null) throw new ArgumentNullException("config"); - - if (name == null || name.Length == 0) name = "UmbracoRoleProvider"; - - if (String.IsNullOrEmpty(config["description"])) - { - config.Remove("description"); - config.Add("description", "Umbraco Role provider"); - } - - // Initialize the abstract base class. - base.Initialize(name, config); - - this._applicationName = config["applicationName"]; - if (string.IsNullOrEmpty(this._applicationName)) - this._applicationName = SecUtility.GetDefaultAppName(); - } - #endregion - - #region Methods - /// - /// Adds the specified user names to the specified roles for the configured applicationName. - /// - /// A string array of user names to be added to the specified roles. - /// A string array of the role names to add the specified user names to. - public override void AddUsersToRoles(string[] usernames, string[] roleNames) - { - throw new Exception("The method or operation is not implemented."); - } - - /// - /// Adds a new role to the data source for the configured applicationName. - /// - /// The name of the role to create. - public override void CreateRole(string roleName) - { - throw new Exception("The method or operation is not implemented."); - } - - /// - /// Removes a role from the data source for the configured applicationName. - /// - /// The name of the role to delete. - /// If true, throw an exception if roleName has one or more members and do not delete roleName. - /// - /// true if the role was successfully deleted; otherwise, false. - /// - public override bool DeleteRole(string roleName, bool throwOnPopulatedRole) - { - throw new Exception("The method or operation is not implemented."); - } - - /// - /// Gets an array of user names in a role where the user name contains the specified user name to match. - /// - /// The role to search in. - /// The user name to search for. - /// - /// A string array containing the names of all the users where the user name matches usernameToMatch and the user is a member of the specified role. - /// - public override string[] FindUsersInRole(string roleName, string usernameToMatch) - { - throw new Exception("The method or operation is not implemented."); - } - - /// - /// Gets a list of all the roles for the configured applicationName. - /// - /// - /// A string array containing the names of all the roles stored in the data source for the configured applicationName. - /// - public override string[] GetAllRoles() - { - throw new Exception("The method or operation is not implemented."); - } - - /// - /// Gets a list of the roles that a specified user is in for the configured applicationName. - /// - /// The user to return a list of roles for. - /// - /// A string array containing the names of all the roles that the specified user is in for the configured applicationName. - /// - public override string[] GetRolesForUser(string username) - { - throw new Exception("The method or operation is not implemented."); - } - - /// - /// Gets a list of users in the specified role for the configured applicationName. - /// - /// The name of the role to get the list of users for. - /// - /// A string array containing the names of all the users who are members of the specified role for the configured applicationName. - /// - public override string[] GetUsersInRole(string roleName) - { - throw new Exception("The method or operation is not implemented."); - } - - /// - /// Gets a value indicating whether the specified user is in the specified role for the configured applicationName. - /// - /// The user name to search for. - /// The role to search in. - /// - /// true if the specified user is in the specified role for the configured applicationName; otherwise, false. - /// - public override bool IsUserInRole(string username, string roleName) - { - throw new Exception("The method or operation is not implemented."); - } - - /// - /// Removes the specified user names from the specified roles for the configured applicationName. - /// - /// A string array of user names to be removed from the specified roles. - /// A string array of role names to remove the specified user names from. - public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) - { - throw new Exception("The method or operation is not implemented."); - } - - /// - /// Gets a value indicating whether the specified role name already exists in the role data source for the configured applicationName. - /// - /// The name of the role to search for in the data source. - /// - /// true if the role name already exists in the data source for the configured applicationName; otherwise, false. - /// - public override bool RoleExists(string roleName) - { - throw new Exception("The method or operation is not implemented."); - } - #endregion - } -} diff --git a/src/umbraco.providers/app.config b/src/umbraco.providers/app.config deleted file mode 100644 index 3a3e923d5b..0000000000 --- a/src/umbraco.providers/app.config +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/umbraco.providers/members/Helper.cs b/src/umbraco.providers/members/Helper.cs deleted file mode 100644 index 0218b74985..0000000000 --- a/src/umbraco.providers/members/Helper.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using umbraco.cms.businesslogic.member; - -namespace umbraco.providers.members -{ - public class Helper - { - public static bool GuidPseudoTryParse(string guidToTest) - { - Guid memberUniqueId; - try - { - memberUniqueId = new Guid(guidToTest); - } - catch (FormatException) - { - memberUniqueId = Guid.Empty; - return false; - } - - return true; - } - - public static Member GetMemberByUsernameOrGuid(string userNameOrGuid) - { - Member m = null; - - // test if username is a GUID (then it comes from member core login) - if (GuidPseudoTryParse(userNameOrGuid)) - { - m = new Member(new Guid(userNameOrGuid)); - } - else - { - m = Member.GetMemberFromLoginName(userNameOrGuid); - } - - return m; - } - } -} diff --git a/src/umbraco.providers/members/MembershipEventHandler.cs b/src/umbraco.providers/members/MembershipEventHandler.cs deleted file mode 100644 index e5137d7813..0000000000 --- a/src/umbraco.providers/members/MembershipEventHandler.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Web.Security; -using Umbraco.Core; -using umbraco.cms.businesslogic; -using umbraco.cms.businesslogic.member; -using Umbraco.Core.Security; - -namespace umbraco.providers.members -{ - /// - /// Adds some event handling - /// - public class MembershipEventHandler : ApplicationEventHandler - { - protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) - { - Member.New += Member_New; - } - - void Member_New(Member sender, NewEventArgs e) - { - //This is a bit of a hack to ensure that the member is approved when created since many people will be using - // this old api to create members on the front-end and they need to be approved - which is based on whether or not - // the Umbraco membership provider is configured. - var provider = MembershipProviderExtensions.GetMembersMembershipProvider() as UmbracoMembershipProvider; - if (provider != null) - { - var approvedField = provider.ApprovedPropertyTypeAlias; - var property = sender.getProperty(approvedField); - if (property != null) - { - property.Value = 1; - sender.Save(); - } - } - } - } -} \ No newline at end of file diff --git a/src/umbraco.providers/members/UmbracoMembershipProvider.cs b/src/umbraco.providers/members/UmbracoMembershipProvider.cs deleted file mode 100644 index a1ddd50260..0000000000 --- a/src/umbraco.providers/members/UmbracoMembershipProvider.cs +++ /dev/null @@ -1,1014 +0,0 @@ -#region namespace -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Web.Security; -using System.Configuration; -using Umbraco.Core; -using Umbraco.Core.Logging; -using Umbraco.Core.Models; -using Umbraco.Core.Models.Membership; -using Umbraco.Core.Persistence.Querying; -using Umbraco.Core.Security; -using Umbraco.Core.Services; -using System.Security.Cryptography; -using System.Web.Util; -using System.Collections.Specialized; -using System.Configuration.Provider; -using System.Security; -using System.Security.Permissions; -using System.Runtime.CompilerServices; -using Member = umbraco.cms.businesslogic.member.Member; -using MemberType = umbraco.cms.businesslogic.member.MemberType; -using User = umbraco.BusinessLogic.User; - -#endregion - -namespace umbraco.providers.members -{ - /// - /// Custom Membership Provider for Umbraco Members (User authentication for Frontend applications NOT umbraco CMS) - /// - [Obsolete("This has been superceded by Umbraco.Web.Security.Providers.MembersMembershipProvider")] - public class UmbracoMembershipProvider : UmbracoMembershipProviderBase, IUmbracoMemberTypeMembershipProvider - { - public UmbracoMembershipProvider() - - { - LockPropertyTypeAlias = Constants.Conventions.Member.IsLockedOut; - LastLockedOutPropertyTypeAlias = Constants.Conventions.Member.LastLockoutDate; - FailedPasswordAttemptsPropertyTypeAlias = Constants.Conventions.Member.FailedPasswordAttempts; - ApprovedPropertyTypeAlias = Constants.Conventions.Member.IsApproved; - CommentPropertyTypeAlias = Constants.Conventions.Member.Comments; - LastLoginPropertyTypeAlias = Constants.Conventions.Member.LastLoginDate; - LastPasswordChangedPropertyTypeAlias = Constants.Conventions.Member.LastPasswordChangeDate; - PasswordRetrievalQuestionPropertyTypeAlias = Constants.Conventions.Member.PasswordQuestion; - PasswordRetrievalAnswerPropertyTypeAlias = Constants.Conventions.Member.PasswordAnswer; - } - - #region Fields - - private string _defaultMemberTypeAlias = "Member"; - private string _providerName = Member.UmbracoMemberProviderName; - private volatile bool _hasDefaultMember = false; - private static readonly object Locker = new object(); - - #endregion - - public string LockPropertyTypeAlias { get; protected set; } - public string LastLockedOutPropertyTypeAlias { get; protected set; } - public string FailedPasswordAttemptsPropertyTypeAlias { get; protected set; } - public string ApprovedPropertyTypeAlias { get; protected set; } - public string CommentPropertyTypeAlias { get; protected set; } - public string LastLoginPropertyTypeAlias { get; protected set; } - public string LastPasswordChangedPropertyTypeAlias { get; protected set; } - public string PasswordRetrievalQuestionPropertyTypeAlias { get; protected set; } - public string PasswordRetrievalAnswerPropertyTypeAlias { get; protected set; } - - /// - /// Override to maintain backwards compatibility with 0 required non-alphanumeric chars - /// - public override int DefaultMinNonAlphanumericChars - { - get { return 0; } - } - - /// - /// Override to maintain backwards compatibility with only 4 required length - /// - public override int DefaultMinPasswordLength - { - get { return 4; } - } - - /// - /// Override to maintain backwards compatibility - /// - public override bool DefaultUseLegacyEncoding - { - get { return true; } - } - - /// - /// For backwards compatibility, this provider supports this option - /// - public override bool AllowManuallyChangingPassword - { - get { return true; } - } - - #region Initialization Method - /// - /// Initializes the provider. - /// - /// The friendly name of the provider. - /// A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider. - /// The name of the provider is null. - /// An attempt is made to call - /// on a provider after the provider - /// has already been initialized. - /// The name of the provider has a length of zero. - public override void Initialize(string name, NameValueCollection config) - { - // Intialize values from web.config - if (config == null) throw new ArgumentNullException("config"); - - if (string.IsNullOrEmpty(name)) name = Constants.Conventions.Member.UmbracoMemberProviderName; - - base.Initialize(name, config); - - _providerName = name; - - // test for membertype (if not specified, choose the first member type available) - if (config["defaultMemberTypeAlias"] != null) - { - _defaultMemberTypeAlias = config["defaultMemberTypeAlias"]; - if (_defaultMemberTypeAlias.IsNullOrWhiteSpace()) - { - throw new ProviderException("No default user type alias is specified in the web.config string. Please add a 'defaultUserTypeAlias' to the add element in the provider declaration in web.config"); - } - _hasDefaultMember = true; - } - - // test for approve status - if (config["umbracoApprovePropertyTypeAlias"] != null) - { - ApprovedPropertyTypeAlias = config["umbracoApprovePropertyTypeAlias"]; - } - // test for lock attempts - if (config["umbracoLockPropertyTypeAlias"] != null) - { - LockPropertyTypeAlias = config["umbracoLockPropertyTypeAlias"]; - } - if (config["umbracoLastLockedPropertyTypeAlias"] != null) - { - LastLockedOutPropertyTypeAlias = config["umbracoLastLockedPropertyTypeAlias"]; - } - if (config["umbracoLastPasswordChangedPropertyTypeAlias"] != null) - { - LastPasswordChangedPropertyTypeAlias = config["umbracoLastPasswordChangedPropertyTypeAlias"]; - } - if (config["umbracoFailedPasswordAttemptsPropertyTypeAlias"] != null) - { - FailedPasswordAttemptsPropertyTypeAlias = config["umbracoFailedPasswordAttemptsPropertyTypeAlias"]; - } - // comment property - if (config["umbracoCommentPropertyTypeAlias"] != null) - { - CommentPropertyTypeAlias = config["umbracoCommentPropertyTypeAlias"]; - } - // last login date - if (config["umbracoLastLoginPropertyTypeAlias"] != null) - { - LastLoginPropertyTypeAlias = config["umbracoLastLoginPropertyTypeAlias"]; - } - // password retrieval - if (config["umbracoPasswordRetrievalQuestionPropertyTypeAlias"] != null) - { - PasswordRetrievalQuestionPropertyTypeAlias = config["umbracoPasswordRetrievalQuestionPropertyTypeAlias"]; - } - if (config["umbracoPasswordRetrievalAnswerPropertyTypeAlias"] != null) - { - PasswordRetrievalAnswerPropertyTypeAlias = config["umbracoPasswordRetrievalAnswerPropertyTypeAlias"]; - } - - } - #endregion - - #region Methods - - /// - /// Processes a request to update the password for a membership user. - /// - /// The user to update the password for. - /// This property is ignore for this provider - /// The new password for the specified user. - /// - /// true if the password was updated successfully; otherwise, false. - /// - protected override bool PerformChangePassword(string username, string oldPassword, string newPassword) - { - //NOTE: due to backwards compatibilty reasons, this provider doesn't care about the old password and - // allows simply setting the password manually so we don't really care about the old password. - // This is allowed based on the overridden AllowManuallyChangingPassword option. - - // in order to support updating passwords from the umbraco core, we can't validate the old password - var m = Member.GetMemberFromLoginName(username); - if (m == null) return false; - - string salt; - var encodedPassword = EncryptOrHashNewPassword(newPassword, out salt); - m.ChangePassword( - FormatPasswordForStorage(encodedPassword, salt)); - - UpdateMemberProperty(m, LastPasswordChangedPropertyTypeAlias, DateTime.Now); - - m.Save(); - - return true; - } - - /// - /// Processes a request to update the password question and answer for a membership user. - /// - /// The user to change the password question and answer for. - /// The password for the specified user. - /// The new password question for the specified user. - /// The new password answer for the specified user. - /// - /// true if the password question and answer are updated successfully; otherwise, false. - /// - protected override bool PerformChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer) - { - if (string.IsNullOrEmpty(PasswordRetrievalQuestionPropertyTypeAlias) || string.IsNullOrEmpty(PasswordRetrievalAnswerPropertyTypeAlias)) - { - throw new NotSupportedException("Updating the password Question and Answer is not valid if the properties aren't set in the config file"); - } - - var m = Member.GetMemberFromLoginName(username); - if (m == null) - { - return false; - } - - UpdateMemberProperty(m, PasswordRetrievalQuestionPropertyTypeAlias, newPasswordQuestion); - UpdateMemberProperty(m, PasswordRetrievalAnswerPropertyTypeAlias, newPasswordAnswer); - m.Save(); - return true; - } - - public override string DefaultMemberTypeAlias - { - get - { - if (_hasDefaultMember == false) - { - lock (Locker) - { - if (_hasDefaultMember == false) - { - var types = MemberType.GetAll; - if (types.Length == 1) - _defaultMemberTypeAlias = types[0].Alias; - else - throw new ProviderException("No default MemberType alias is specified in the web.config string. Please add a 'defaultMemberTypeAlias' to the add element in the provider declaration in web.config"); - - _hasDefaultMember = true; - } - } - } - return _defaultMemberTypeAlias; - } - } - - /// - /// Adds a new membership user to the data source. - /// - /// - /// The user name for the new user. - /// The password for the new user. - /// The e-mail address for the new user. - /// The password question for the new user. - /// The password answer for the new user - /// Whether or not the new user is approved to be validated. - /// The unique identifier from the membership data source for the user. - /// A enumeration value indicating whether the user was created successfully. - /// - /// A object populated with the information for the newly created user. - /// - protected override MembershipUser PerformCreateUser(string memberTypeAlias, string username, string password, string email, string passwordQuestion, - string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) - { - if (Member.GetMemberFromLoginName(username) != null) - { - status = MembershipCreateStatus.DuplicateUserName; - LogHelper.Warn("Cannot create member as username already exists: " + username); - return null; - } - - if (Member.GetMemberFromEmail(email) != null && RequiresUniqueEmail) - { - status = MembershipCreateStatus.DuplicateEmail; - LogHelper.Warn( - "Cannot create member as a member with the same email address exists: " + email); - return null; - } - - var memberType = MemberType.GetByAlias(memberTypeAlias); - if (memberType == null) - { - throw new InvalidOperationException("Could not find a member type with alias " + memberTypeAlias + ". Ensure your membership provider configuration is up to date and that the default member type exists."); - } - - var m = Member.MakeNew(username, email, memberType, User.GetUser(0)); - - string salt; - var encodedPassword = EncryptOrHashNewPassword(password, out salt); - - //set the password on the member - m.ChangePassword(FormatPasswordForStorage(encodedPassword, salt)); - - // custom fields - if (string.IsNullOrEmpty(PasswordRetrievalQuestionPropertyTypeAlias) == false) - { - UpdateMemberProperty(m, PasswordRetrievalQuestionPropertyTypeAlias, passwordQuestion); - } - - if (string.IsNullOrEmpty(PasswordRetrievalAnswerPropertyTypeAlias) == false) - { - UpdateMemberProperty(m, PasswordRetrievalAnswerPropertyTypeAlias, passwordAnswer); - } - - if (string.IsNullOrEmpty(ApprovedPropertyTypeAlias) == false) - { - UpdateMemberProperty(m, ApprovedPropertyTypeAlias, isApproved ? 1 : 0); - } - - if (string.IsNullOrEmpty(LastLoginPropertyTypeAlias) == false) - { - UpdateMemberProperty(m, LastLoginPropertyTypeAlias, DateTime.Now); - } - - if (string.IsNullOrEmpty(LastPasswordChangedPropertyTypeAlias) == false) - { - UpdateMemberProperty(m, LastPasswordChangedPropertyTypeAlias, DateTime.Now); - } - - var mUser = ConvertToMembershipUser(m); - - // save - m.Save(); - - status = MembershipCreateStatus.Success; - - return mUser; - } - - - /// - /// Removes a user from the membership data source. - /// - /// The name of the user to delete. - /// - /// TODO: This setting currently has no effect - /// - /// - /// true if the user was successfully deleted; otherwise, false. - /// - public override bool DeleteUser(string username, bool deleteAllRelatedData) - { - var m = Member.GetMemberFromLoginName(username); - if (m == null) return false; - m.delete(); - return true; - } - - /// - /// Gets a collection of membership users where the e-mail address contains the specified e-mail address to match. - /// - /// The e-mail address to search for. - /// The index of the page of results to return. pageIndex is zero-based. - /// The size of the page of results to return. - /// The total number of matched users. - /// - /// A collection that contains a page of pageSize objects beginning at the page specified by pageIndex. - /// - public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords) - { - var byEmail = ApplicationContext.Current.Services.MemberService.FindByEmail(emailToMatch, pageIndex, pageSize, out totalRecords, StringPropertyMatchType.Wildcard).ToArray(); - - var collection = new MembershipUserCollection(); - foreach (var m in byEmail) - { - collection.Add(ConvertToMembershipUser(m)); - } - return collection; - } - - /// - /// Gets a collection of membership users where the user name contains the specified user name to match. - /// - /// The user name to search for. - /// The index of the page of results to return. pageIndex is zero-based. - /// The size of the page of results to return. - /// The total number of matched users. - /// - /// A collection that contains a page of pageSize objects beginning at the page specified by pageIndex. - /// - public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) - { - var byEmail = ApplicationContext.Current.Services.MemberService.FindByUsername(usernameToMatch, pageIndex, pageSize, out totalRecords, StringPropertyMatchType.Wildcard).ToArray(); - - var collection = new MembershipUserCollection(); - foreach (var m in byEmail) - { - collection.Add(ConvertToMembershipUser(m)); - } - return collection; - } - - /// - /// Gets a collection of all the users in the data source in pages of data. - /// - /// The index of the page of results to return. pageIndex is zero-based. - /// The size of the page of results to return. - /// The total number of matched users. - /// - /// A collection that contains a page of pageSize objects beginning at the page specified by pageIndex. - /// - public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) - { - var membersList = new MembershipUserCollection(); - - var pagedMembers = ApplicationContext.Current.Services.MemberService.GetAll(pageIndex, pageSize, out totalRecords); - - foreach (var m in pagedMembers) - { - membersList.Add(ConvertToMembershipUser(m)); - } - return membersList; - } - - /// - /// Gets the number of users currently accessing the application. - /// - /// - /// The number of users currently accessing the application. - /// - public override int GetNumberOfUsersOnline() - { - return ApplicationContext.Current.Services.MemberService.GetCount(MemberCountType.Online); - } - - /// - /// Gets the password for the specified user name from the data source. - /// - /// The user to retrieve the password for. - /// The password answer for the user. - /// - /// The password for the specified user name. - /// - protected override string PerformGetPassword(string username, string answer) - { - var m = Member.GetMemberFromLoginName(username); - if (m == null) - { - throw new MembershipPasswordException("The supplied user is not found"); - } - - // check if user is locked out - if (string.IsNullOrEmpty(LockPropertyTypeAlias) == false) - { - var isLockedOut = false; - bool.TryParse(GetMemberProperty(m, LockPropertyTypeAlias, true), out isLockedOut); - if (isLockedOut) - { - throw new MembershipPasswordException("The supplied user is locked out"); - } - } - - if (RequiresQuestionAndAnswer) - { - // check if password answer property alias is set - if (string.IsNullOrEmpty(PasswordRetrievalAnswerPropertyTypeAlias) == false) - { - // match password answer - if (GetMemberProperty(m, PasswordRetrievalAnswerPropertyTypeAlias, false) != answer) - { - throw new MembershipPasswordException("Incorrect password answer"); - } - } - else - { - throw new ProviderException("Password retrieval answer property alias is not set! To automatically support password question/answers you'll need to add references to the membertype properties in the 'Member' element in web.config by adding their aliases to the 'umbracoPasswordRetrievalQuestionPropertyTypeAlias' and 'umbracoPasswordRetrievalAnswerPropertyTypeAlias' attributes"); - } - } - - var decodedPassword = DecryptPassword(m.GetPassword()); - - return decodedPassword; - } - - /// - /// Gets information from the data source for a user. Provides an option to update the last-activity date/time stamp for the user. - /// - /// The name of the user to get information for. - /// true to update the last-activity date/time stamp for the user; false to return user information without updating the last-activity date/time stamp for the user. - /// - /// A object populated with the specified user's information from the data source. - /// - public override MembershipUser GetUser(string username, bool userIsOnline) - { - if (string.IsNullOrEmpty(username)) - return null; - var m = Member.GetMemberFromLoginName(username); - - if (m == null) - { - return null; - } - - if (userIsOnline && LastLoginPropertyTypeAlias.IsNullOrWhiteSpace() == false) - { - UpdateMemberProperty(m, LastLoginPropertyTypeAlias, DateTime.Now); - - //don't raise events for this! It just sets the member dates, if we do raise events this will - // cause all distributed cache to execute - which will clear out some caches we don't want. - // http://issues.umbraco.org/issue/U4-3451 - m.Save(false); - } - - return ConvertToMembershipUser(m); - } - - /// - /// Gets information from the data source for a user based on the unique identifier for the membership user. Provides an option to update the last-activity date/time stamp for the user. - /// - /// The unique identifier for the membership user to get information for. - /// true to update the last-activity date/time stamp for the user; false to return user information without updating the last-activity date/time stamp for the user. - /// - /// A object populated with the specified user's information from the data source. - /// - public override MembershipUser GetUser(object providerUserKey, bool userIsOnline) - { - var asGuid = providerUserKey.TryConvertTo(); - if (asGuid.Success) - { - var m = new Member(asGuid.Result); - if (userIsOnline && LastLoginPropertyTypeAlias.IsNullOrWhiteSpace() == false) - { - UpdateMemberProperty(m, LastLoginPropertyTypeAlias, DateTime.Now); - //don't raise events for this! It just sets the member dates, if we do raise events this will - // cause all distributed cache to execute - which will clear out some caches we don't want. - // http://issues.umbraco.org/issue/U4-3451 - m.Save(false); - } - return ConvertToMembershipUser(m); - } - var asInt = providerUserKey.TryConvertTo(); - if (asInt.Success) - { - var m = new Member(asInt.Result); - if (userIsOnline && LastLoginPropertyTypeAlias.IsNullOrWhiteSpace() == false) - { - UpdateMemberProperty(m, LastLoginPropertyTypeAlias, DateTime.Now); - //don't raise events for this! It just sets the member dates, if we do raise events this will - // cause all distributed cache to execute - which will clear out some caches we don't want. - // http://issues.umbraco.org/issue/U4-3451 - m.Save(false); - } - return ConvertToMembershipUser(m); - } - - throw new InvalidOperationException("The " + GetType() + " provider only supports GUID or Int as a providerUserKey"); - - } - - - /// - /// Gets the user name associated with the specified e-mail address. - /// - /// The e-mail address to search for. - /// - /// The user name associated with the specified e-mail address. If no match is found, return null. - /// - public override string GetUserNameByEmail(string email) - { - var m = Member.GetMemberFromEmail(email); - return m == null ? null : m.LoginName; - } - - /// - /// Resets a user's password to a new, automatically generated password. - /// - /// The user to reset the password for. - /// The password answer for the specified user (not used with Umbraco). - /// - /// The new password for the specified user. - protected override string PerformResetPassword(string username, string answer, string generatedPassword) - { - //TODO: This should be here - but how do we update failure count in this provider?? - //if (answer == null && RequiresQuestionAndAnswer) - //{ - // UpdateFailureCount(username, "passwordAnswer"); - - // throw new ProviderException("Password answer required for password reset."); - //} - - var m = Member.GetMemberFromLoginName(username); - if (m == null) - { - throw new ProviderException("The supplied user is not found"); - } - - // check if user is locked out - if (string.IsNullOrEmpty(LockPropertyTypeAlias) == false) - { - var isLockedOut = false; - bool.TryParse(GetMemberProperty(m, LockPropertyTypeAlias, true), out isLockedOut); - if (isLockedOut) - { - throw new ProviderException("The member is locked out."); - } - } - - if (RequiresQuestionAndAnswer) - { - // check if password answer property alias is set - if (string.IsNullOrEmpty(PasswordRetrievalAnswerPropertyTypeAlias) == false) - { - // match password answer - if (GetMemberProperty(m, PasswordRetrievalAnswerPropertyTypeAlias, false) != answer) - { - throw new ProviderException("Incorrect password answer"); - } - } - else - { - throw new ProviderException("Password retrieval answer property alias is not set! To automatically support password question/answers you'll need to add references to the membertype properties in the 'Member' element in web.config by adding their aliases to the 'umbracoPasswordRetrievalQuestionPropertyTypeAlias' and 'umbracoPasswordRetrievalAnswerPropertyTypeAlias' attributes"); - } - } - - string salt; - var encodedPassword = EncryptOrHashNewPassword(generatedPassword, out salt); - //set the password on the member - m.ChangePassword(FormatPasswordForStorage(encodedPassword, salt)); - - if (string.IsNullOrEmpty(LastPasswordChangedPropertyTypeAlias) == false) - { - UpdateMemberProperty(m, LastPasswordChangedPropertyTypeAlias, DateTime.Now); - } - - m.Save(); - - return generatedPassword; - } - - /// - /// Clears a lock so that the membership user can be validated. - /// - /// The membership user to clear the lock status for. - /// - /// true if the membership user was successfully unlocked; otherwise, false. - /// - public override bool UnlockUser(string userName) - { - if (string.IsNullOrEmpty(LockPropertyTypeAlias) == false) - { - var m = Member.GetMemberFromLoginName(userName); - if (m != null) - { - UpdateMemberProperty(m, LockPropertyTypeAlias, 0); - if (string.IsNullOrEmpty(FailedPasswordAttemptsPropertyTypeAlias) == false) - { - UpdateMemberProperty(m, FailedPasswordAttemptsPropertyTypeAlias, 0); - } - m.Save(); - return true; - } - throw new ProviderException(string.Format("No member with the username '{0}' found", userName)); - } - throw new ProviderException("To enable lock/unlocking, you need to add a 'bool' property on your membertype and add the alias of the property in the 'umbracoLockPropertyTypeAlias' attribute of the membership element in the web.config."); - } - - /// - /// Updates e-mail and potentially approved status, lock status and comment on a user. - /// - /// A object that represents the user to update and the updated information for the user. - public override void UpdateUser(MembershipUser user) - { - var m = Member.GetMemberFromLoginName(user.UserName); - - if (m == null) - { - throw new ProviderException(string.Format("No member with the username '{0}' found", user.UserName)); - } - - m.Email = user.Email; - - // if supported, update approve status - UpdateMemberProperty(m, ApprovedPropertyTypeAlias, user.IsApproved ? 1 : 0); - - // if supported, update lock status - UpdateMemberProperty(m, LockPropertyTypeAlias, user.IsLockedOut ? 1 : 0); - if (user.IsLockedOut) - { - UpdateMemberProperty(m, LastLockedOutPropertyTypeAlias, DateTime.Now); - } - - // if supported, update comment - UpdateMemberProperty(m, CommentPropertyTypeAlias, user.Comment); - - m.Save(); - } - - /// - /// Verifies that the specified user name and password exist in the data source. - /// - /// The name of the user to validate. - /// The password for the specified user. - /// - /// true if the specified username and password are valid; otherwise, false. - /// - public override bool ValidateUser(string username, string password) - { - var m = Member.GetMemberFromLoginName(username); - if (m == null) return false; - var authenticated = CheckPassword(password, m.GetPassword()); - - if (authenticated) - { - // check for lock status. If locked, then set the member property to null - if (string.IsNullOrEmpty(LockPropertyTypeAlias) == false) - { - string lockedStatus = GetMemberProperty(m, LockPropertyTypeAlias, true); - if (string.IsNullOrEmpty(lockedStatus) == false) - { - var isLocked = false; - if (bool.TryParse(lockedStatus, out isLocked)) - { - if (isLocked) - { - LogHelper.Info("Cannot validate member " + username + " because they are currently locked out"); - return false; - } - } - } - } - - //check for approve status. If not approved, then set the member property to null - if (CheckApproveStatus(m) == false) - { - LogHelper.Info("Cannot validate member " + username + " because they are not approved"); - return false; - } - - // maybe update login date - if (string.IsNullOrEmpty(LastLoginPropertyTypeAlias) == false) - { - UpdateMemberProperty(m, LastLoginPropertyTypeAlias, DateTime.Now); - } - - // maybe reset password attempts - if (string.IsNullOrEmpty(FailedPasswordAttemptsPropertyTypeAlias) == false) - { - UpdateMemberProperty(m, FailedPasswordAttemptsPropertyTypeAlias, 0); - } - - // persist data - - //don't raise events for this! It just sets the member dates, if we do raise events this will - // cause all distributed cache to execute - which will clear out some caches we don't want. - // http://issues.umbraco.org/issue/U4-3451 - m.Save(false); - - return true; - } - - - // update fail rate if it's approved - if (string.IsNullOrEmpty(LockPropertyTypeAlias) == false - && string.IsNullOrEmpty(FailedPasswordAttemptsPropertyTypeAlias) == false) - { - if (CheckApproveStatus(m)) - { - var failedAttempts = 0; - int.TryParse(GetMemberProperty(m, FailedPasswordAttemptsPropertyTypeAlias, false), out failedAttempts); - failedAttempts = failedAttempts + 1; - UpdateMemberProperty(m, FailedPasswordAttemptsPropertyTypeAlias, failedAttempts); - - // lock user? - if (failedAttempts >= MaxInvalidPasswordAttempts) - { - UpdateMemberProperty(m, LockPropertyTypeAlias, 1); - UpdateMemberProperty(m, LastLockedOutPropertyTypeAlias, DateTime.Now); - LogHelper.Info("Member " + username + " is now locked out, max invalid password attempts exceeded"); - } - - //don't raise events for this! It just sets the member dates, if we do raise events this will - // cause all distributed cache to execute - which will clear out some caches we don't want. - // http://issues.umbraco.org/issue/U4-3451 - m.Save(false); - } - - } - - return false; - } - - private static void UpdateMemberProperty(Member m, string propertyTypeAlias, object propertyValue) - { - if (string.IsNullOrEmpty(propertyTypeAlias) == false) - { - if (m.getProperty(propertyTypeAlias) != null) - { - m.getProperty(propertyTypeAlias).Value = propertyValue; - } - } - } - - private static string GetMemberProperty(Member m, string propertyTypeAlias, bool isBool) - { - if (string.IsNullOrEmpty(propertyTypeAlias) == false) - { - if (m.getProperty(propertyTypeAlias) != null && - m.getProperty(propertyTypeAlias).Value != null) - { - if (isBool) - { - // Umbraco stored true as 1, which means it can be bool.tryParse'd - return m.getProperty(propertyTypeAlias).Value.ToString().Replace("1", "true").Replace("0", "false"); - } - return m.getProperty(propertyTypeAlias).Value.ToString(); - } - } - - return null; - } - - private static string GetMemberProperty(IMember m, string propertyTypeAlias, bool isBool) - { - if (string.IsNullOrEmpty(propertyTypeAlias) == false) - { - if (m.Properties.Contains(propertyTypeAlias) && - m.Properties[propertyTypeAlias] != null && - m.Properties[propertyTypeAlias].Value != null) - { - if (isBool) - { - // Umbraco stored true as 1, which means it can be bool.tryParse'd - return m.Properties[propertyTypeAlias].Value.ToString().Replace("1", "true").Replace("0", "false"); - } - return m.Properties[propertyTypeAlias].Value.ToString(); - } - } - - return null; - } - - private bool CheckApproveStatus(Member m) - { - var isApproved = false; - if (string.IsNullOrEmpty(ApprovedPropertyTypeAlias) == false) - { - if (m != null) - { - var approveStatus = GetMemberProperty(m, ApprovedPropertyTypeAlias, true); - if (string.IsNullOrEmpty(approveStatus) == false) - { - //try parsing as bool first (just in case) - if (bool.TryParse(approveStatus, out isApproved) == false) - { - int intStatus; - //if that fails, try parsing as int (since its normally stored as 0 or 1) - if (int.TryParse(approveStatus, out intStatus)) - { - isApproved = intStatus != 0; - } - } - } - else - { - //There is no property so we shouldn't use the approve status - isApproved = true; - } - } - } - else { - // if we don't use approve statuses - isApproved = true; - } - return isApproved; - } - #endregion - - #region Helper Methods - - /// - /// Encodes the password. - /// - /// The password. - /// The encoded password. - [Obsolete("Do not use this, it is the legacy way to encode a password - use the base class EncryptOrHashExistingPassword instead")] - public string EncodePassword(string password) - { - return LegacyEncodePassword(password); - } - - /// - /// Unencode password. - /// - /// The encoded password. - /// The unencoded password. - [Obsolete("Do not use this, it is the legacy way to decode a password - use the base class DecodePassword instead")] - public string UnEncodePassword(string encodedPassword) - { - return LegacyUnEncodePassword(encodedPassword); - } - - /// - /// Converts to membership user. - /// - /// The m. - /// - private MembershipUser ConvertToMembershipUser(Member m) - { - if (m == null) return null; - - var lastLogin = DateTime.Now; - var lastLocked = DateTime.MinValue; - var isApproved = true; - var isLocked = false; - var comment = ""; - var passwordQuestion = ""; - - // last login - if (string.IsNullOrEmpty(LastLoginPropertyTypeAlias) == false) - { - DateTime.TryParse(GetMemberProperty(m, LastLoginPropertyTypeAlias, false), out lastLogin); - } - // approved - if (string.IsNullOrEmpty(ApprovedPropertyTypeAlias) == false) - { - bool.TryParse(GetMemberProperty(m, ApprovedPropertyTypeAlias, true), out isApproved); - } - // locked - if (string.IsNullOrEmpty(LockPropertyTypeAlias) == false) - { - bool.TryParse(GetMemberProperty(m, LockPropertyTypeAlias, true), out isLocked); - } - // last locked - if (string.IsNullOrEmpty(LastLockedOutPropertyTypeAlias) == false) - { - DateTime.TryParse(GetMemberProperty(m, LastLockedOutPropertyTypeAlias, false), out lastLocked); - } - // comment - if (string.IsNullOrEmpty(CommentPropertyTypeAlias) == false) - { - comment = GetMemberProperty(m, CommentPropertyTypeAlias, false); - } - // password question - if (string.IsNullOrEmpty(PasswordRetrievalQuestionPropertyTypeAlias) == false) - { - passwordQuestion = GetMemberProperty(m, PasswordRetrievalQuestionPropertyTypeAlias, false); - } - - return new MembershipUser(_providerName, m.LoginName, m.Id, m.Email, passwordQuestion, comment, isApproved, isLocked, m.CreateDateTime, lastLogin, - DateTime.Now, DateTime.Now, lastLocked); - } - - /// - /// Converts to membership user. - /// - /// The m. - /// - private MembershipUser ConvertToMembershipUser(IMember m) - { - if (m == null) return null; - - var lastLogin = DateTime.Now; - var lastLocked = DateTime.MinValue; - var isApproved = true; - var isLocked = false; - var comment = ""; - var passwordQuestion = ""; - - // last login - if (string.IsNullOrEmpty(LastLoginPropertyTypeAlias) == false) - { - DateTime.TryParse(GetMemberProperty(m, LastLoginPropertyTypeAlias, false), out lastLogin); - } - // approved - if (string.IsNullOrEmpty(ApprovedPropertyTypeAlias) == false) - { - bool.TryParse(GetMemberProperty(m, ApprovedPropertyTypeAlias, true), out isApproved); - } - // locked - if (string.IsNullOrEmpty(LockPropertyTypeAlias) == false) - { - bool.TryParse(GetMemberProperty(m, LockPropertyTypeAlias, true), out isLocked); - } - // last locked - if (string.IsNullOrEmpty(LastLockedOutPropertyTypeAlias) == false) - { - DateTime.TryParse(GetMemberProperty(m, LastLockedOutPropertyTypeAlias, false), out lastLocked); - } - // comment - if (string.IsNullOrEmpty(CommentPropertyTypeAlias) == false) - { - comment = GetMemberProperty(m, CommentPropertyTypeAlias, false); - } - // password question - if (string.IsNullOrEmpty(PasswordRetrievalQuestionPropertyTypeAlias) == false) - { - passwordQuestion = GetMemberProperty(m, PasswordRetrievalQuestionPropertyTypeAlias, false); - } - - return new MembershipUser(_providerName, m.Username, m.Id, m.Email, passwordQuestion, comment, isApproved, isLocked, m.CreateDate, lastLogin, - DateTime.Now, DateTime.Now, lastLocked); - } - - #endregion - } -} diff --git a/src/umbraco.providers/members/UmbracoProfileProvider.cs b/src/umbraco.providers/members/UmbracoProfileProvider.cs deleted file mode 100644 index 4d1ac06ea3..0000000000 --- a/src/umbraco.providers/members/UmbracoProfileProvider.cs +++ /dev/null @@ -1,187 +0,0 @@ -#region namespace -using System; -using System.Collections.Generic; -using System.Text; -using System.Web.Security; -using System.Configuration; -using umbraco.BusinessLogic; -using System.Security.Cryptography; -using System.Web.Util; -using System.Collections.Specialized; -using System.Configuration.Provider; -using umbraco.cms.businesslogic; -using umbraco.cms.businesslogic.member; -using System.Collections; -using System.Web.Profile; -#endregion - -namespace umbraco.providers.members -{ - public class UmbracoProfileProvider : ProfileProvider - { - - private string _applicationName = ""; - - public override string ApplicationName - { - get - { - return _applicationName; - } - set - { - _applicationName = value; - } - } - public override string Description - { - get - { - return "Profile Provider for umbraco member profile data"; - } - } - public override string Name - { - get - { - return base.Name; - } - } - public override void Initialize(string name, NameValueCollection config) - { - - if (config == null) - throw new ArgumentNullException("Null configuration parameters"); - - if (String.IsNullOrEmpty(name)) - name = "UmbracoProfileProvider"; - - base.Initialize(name, config); - - _applicationName = config["applicationName"]; - if (String.IsNullOrEmpty(_applicationName)) - _applicationName = System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath; - config.Remove("applicationName"); - - // if the config element contains unused parameters we should throw an exception - if (config.Count > 0) - { - var attrib = config.GetKey(0); - if (string.IsNullOrEmpty(attrib) == false) - { - throw new ProviderException(String.Format("Unrecognized attribute: {0}", attrib)); - } - - } - - - } - - public override int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate) - { - throw new NotSupportedException(); - } - - public override int DeleteProfiles(string[] usernames) - { - throw new NotSupportedException(); - } - - public override int DeleteProfiles(ProfileInfoCollection profiles) - { - throw new NotSupportedException(); - } - - public override ProfileInfoCollection FindInactiveProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords) - { - throw new NotSupportedException(); - } - - public override ProfileInfoCollection FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) - { - throw new NotSupportedException(); - } - - public override ProfileInfoCollection GetAllInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords) - { - throw new NotSupportedException(); - } - public override ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords) - { - throw new NotSupportedException(); - } - public override int GetNumberOfInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate) - { - throw new NotSupportedException(); - } - /// - /// Returns the collection of settings property values for the current umbraco member. - /// - /// A describing the current application use. - /// A containing the settings property group whose values are to be retrieved. - /// - /// A containing the values for the specified settings property group. - /// - public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) - { - var settings = new SettingsPropertyValueCollection(); - - if (collection.Count == 0) - return settings; - - foreach (SettingsProperty property in collection) - { - var pv = new SettingsPropertyValue(property); - settings.Add(pv); - } - - // get the current user - var username = (string)context["UserName"]; - var m = Member.GetMemberFromLoginName(username); - if (m == null) - throw new ProviderException(String.Format("No member with username '{0}' exists", username)); - - foreach (SettingsPropertyValue spv in settings) - { - if (m.getProperty(spv.Name) != null) - { - spv.Deserialized = true; - spv.PropertyValue = m.getProperty(spv.Name).Value; - } - } - - return settings; - - } - - /// - /// Sets the values of the specified group of property settings for the current umbraco member. - /// - /// A describing the current application usage. - /// A representing the group of property settings to set. - public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection) - { - - var username = (string)context["UserName"]; - var authenticated = (bool)context["IsAuthenticated"]; - - if (string.IsNullOrEmpty(username) || collection.Count == 0) - return; - - var m = Member.GetMemberFromLoginName(username); - if (m == null) - throw new ProviderException(String.Format("No member with username '{0}' exists", username)); - - - foreach (SettingsPropertyValue spv in collection) - { - if (authenticated == false && (bool)spv.Property.Attributes["AllowAnonymous"] == false) - continue; - - if (m.getProperty(spv.Name) != null) - m.getProperty(spv.Name).Value = spv.PropertyValue; - } - m.Save(); - } - } -} diff --git a/src/umbraco.providers/members/UmbracoRoleProvider.cs b/src/umbraco.providers/members/UmbracoRoleProvider.cs deleted file mode 100644 index f87f960a79..0000000000 --- a/src/umbraco.providers/members/UmbracoRoleProvider.cs +++ /dev/null @@ -1,289 +0,0 @@ -#region namespace -using System; -using System.Collections.Generic; -using System.Text; -using System.Web.Security; -using System.Configuration; -using umbraco.BusinessLogic; -using System.Security.Cryptography; -using System.Web.Util; -using System.Collections.Specialized; -using System.Configuration.Provider; -using umbraco.cms.businesslogic; -using umbraco.cms.businesslogic.member; -using System.Collections; -#endregion - -namespace umbraco.providers.members -{ - /// - /// A role provider for members - /// - [Obsolete("This has been superceded by Umbraco.Web.Security.Providers.MembersRoleProvider")] - public class UmbracoRoleProvider : RoleProvider - { - - #region - private string _applicationName = Member.UmbracoRoleProviderName; - #endregion - - #region Properties - /// - /// Gets or sets the name of the application to store and retrieve role information for. - /// - /// - /// The name of the application to store and retrieve role information for. - public override string ApplicationName - { - get - { - return _applicationName; - } - set - { - if (string.IsNullOrEmpty(value)) - throw new ProviderException("ApplicationName cannot be empty."); - - if (value.Length > 0x100) - throw new ProviderException("Provider application name too long."); - - _applicationName = value; - } - } - #endregion - - #region Initialization Method - /// - /// Initializes the provider. - /// - /// The friendly name of the provider. - /// A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider. - /// The name of the provider is null. - /// An attempt is made to call - /// on a provider - /// after the provider has already been initialized. - /// The name of the provider has a length of zero. - public override void Initialize(string name, NameValueCollection config) - { - // Initialize values from web.config - if (config == null) throw new ArgumentNullException("config"); - - if (name == null || name.Length == 0) name = "UmbracoMemberRoleProvider"; - - if (String.IsNullOrEmpty(config["description"])) - { - config.Remove("description"); - config.Add("description", "Umbraco Member Role provider"); - } - - // Initialize the abstract base class. - base.Initialize(name, config); - - this._applicationName = config["applicationName"]; - if (string.IsNullOrEmpty(this._applicationName)) - this._applicationName = SecUtility.GetDefaultAppName(); - } - #endregion - - #region Methods - /// - /// Adds the specified user names to the specified roles for the configured applicationName. - /// - /// A string array of user names to be added to the specified roles. - /// A string array of the role names to add the specified user names to. - public override void AddUsersToRoles(string[] usernames, string[] roleNames) - { - ArrayList roles = new ArrayList(); - foreach (string role in roleNames) - try - { - roles.Add(MemberGroup.GetByName(role).Id); - } - catch - { - throw new ProviderException(String.Format("No role with name '{0}' exists", role)); - } - foreach (string username in usernames) - { - Member m = Member.GetMemberFromLoginName(username); - foreach (int roleId in roles) - m.AddGroup(roleId); - } - } - - /// - /// Adds a new role to the data source for the configured applicationName. - /// - /// The name of the role to create. - public override void CreateRole(string roleName) - { - MemberGroup.MakeNew(roleName, User.GetUser(0)); - } - - /// - /// Removes a role from the data source for the configured applicationName. - /// - /// The name of the role to delete. - /// If true, throw an exception if roleName has one or more members and do not delete roleName. - /// - /// true if the role was successfully deleted; otherwise, false. - /// - public override bool DeleteRole(string roleName, bool throwOnPopulatedRole) - { - MemberGroup group = MemberGroup.GetByName(roleName); - if (group == null) - throw new ProviderException(String.Format("No role with name '{0}' exists", roleName)); - else if (throwOnPopulatedRole && group.GetMembersAsIds().Length > 0) - throw new ProviderException(String.Format("Can't delete role '{0}', there are members assigned to the role", roleName)); - else - { - foreach (Member m in group.GetMembers()) - m.RemoveGroup(group.Id); - group.delete(); - return true; - } - } - - /// - /// Gets an array of user names in a role where the user name contains the specified user name to match. - /// - /// The role to search in. - /// The user name to search for. - /// - /// A string array containing the names of all the users where the user name matches usernameToMatch and the user is a member of the specified role. - /// - public override string[] FindUsersInRole(string roleName, string usernameToMatch) - { - ArrayList members = new ArrayList(); - MemberGroup group = MemberGroup.GetByName(roleName); - if (group == null) - throw new ProviderException(String.Format("No role with name '{0}' exists", roleName)); - else - { - foreach (Member m in group.GetMembers(usernameToMatch)) - members.Add(m.LoginName); - return (string[])members.ToArray(typeof(string)); - } - } - - /// - /// Gets a list of all the roles for the configured applicationName. - /// - /// - /// A string array containing the names of all the roles stored in the data source for the configured applicationName. - /// - public override string[] GetAllRoles() - { - ArrayList roles = new ArrayList(); - foreach (MemberGroup mg in MemberGroup.GetAll) - roles.Add(mg.Text); - return (string[])roles.ToArray(typeof(string)); - } - - /// - /// Gets a list of the roles that a specified user is in for the configured applicationName. - /// - /// The user to return a list of roles for. - /// - /// A string array containing the names of all the roles that the specified user is in for the configured applicationName. - /// - public override string[] GetRolesForUser(string username) - { - ArrayList roles = new ArrayList(); - Member m = Member.GetMemberFromLoginName(username); - if (m != null) - { - IDictionaryEnumerator ide = m.Groups.GetEnumerator(); - while (ide.MoveNext()) - roles.Add(((MemberGroup)ide.Value).Text); - return (string[])roles.ToArray(typeof(string)); - } - else - throw new ProviderException(String.Format("No member with username '{0}' exists", username)); - } - - /// - /// Gets a list of users in the specified role for the configured applicationName. - /// - /// The name of the role to get the list of users for. - /// - /// A string array containing the names of all the users who are members of the specified role for the configured applicationName. - /// - public override string[] GetUsersInRole(string roleName) - { - ArrayList members = new ArrayList(); - MemberGroup group = MemberGroup.GetByName(roleName); - if (group == null) - throw new ProviderException(String.Format("No role with name '{0}' exists", roleName)); - else - { - foreach (Member m in group.GetMembers()) - members.Add(m.LoginName); - return (string[])members.ToArray(typeof(string)); - } - } - - /// - /// Gets a value indicating whether the specified user is in the specified role for the configured applicationName. - /// - /// The user name to search for. - /// The role to search in. - /// - /// true if the specified user is in the specified role for the configured applicationName; otherwise, false. - /// - public override bool IsUserInRole(string username, string roleName) - { - Member m = Member.GetMemberFromLoginName(username); - if (m == null) - throw new ProviderException(String.Format("No user with name '{0}' exists", username)); - else - { - MemberGroup mg = MemberGroup.GetByName(roleName); - if (mg == null) - throw new ProviderException(String.Format("No Membergroup with name '{0}' exists", roleName)); - else - return mg.HasMember(m.Id); - } - } - - /// - /// Removes the specified user names from the specified roles for the configured applicationName. - /// - /// A string array of user names to be removed from the specified roles. - /// A string array of role names to remove the specified user names from. - public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) - { - ArrayList roles = new ArrayList(); - foreach (string role in roleNames) - try - { - roles.Add(MemberGroup.GetByName(role).Id); - } - catch - { - throw new ProviderException(String.Format("No role with name '{0}' exists", role)); - } - foreach (string username in usernames) - { - Member m = Member.GetMemberFromLoginName(username); - foreach (int roleId in roles) - m.RemoveGroup(roleId); - } - } - - /// - /// Gets a value indicating whether the specified role name already exists in the role data source for the configured applicationName. - /// - /// The name of the role to search for in the data source. - /// - /// true if the role name already exists in the data source for the configured applicationName; otherwise, false. - /// - public override bool RoleExists(string roleName) - { - MemberGroup mg = MemberGroup.GetByName(roleName); - return mg != null; - } - #endregion - - } -} diff --git a/src/umbraco.providers/umbraco.providers.csproj b/src/umbraco.providers/umbraco.providers.csproj deleted file mode 100644 index 102e9098da..0000000000 --- a/src/umbraco.providers/umbraco.providers.csproj +++ /dev/null @@ -1,144 +0,0 @@ - - - - Debug - AnyCPU - 9.0.21022 - 2.0 - {D7636876-0756-43CB-A192-138C6F0D5E42} - Library - Properties - umbraco.providers - umbraco.providers - - - - - - - - - - - 3.5 - - - v4.5 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AllRules.ruleset - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - bin\Release\umbraco.providers.xml - AllRules.ruleset - false - - - - - - 3.5 - - - - - - - - - Properties\SolutionInfo.cs - - - - - - - - - - - - - - - {E469A9CE-1BEC-423F-AC44-713CD72457EA} - umbraco.businesslogic - - - {ccd75ec3-63db-4184-b49d-51c1dd337230} - umbraco.cms - - - {31785bc3-256c-4613-b2f5-a1b0bdded8c1} - Umbraco.Core - - - {C7CB79F0-1C97-4B33-BFA7-00731B579AE2} - umbraco.datalayer - - - {511F6D8D-7717-440A-9A57-A507E9A8B27F} - umbraco.interfaces - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - - - - - - - - \ No newline at end of file diff --git a/src/umbraco.sln b/src/umbraco.sln index f2be7a0d71..0428ae7362 100644 --- a/src/umbraco.sln +++ b/src/umbraco.sln @@ -65,8 +65,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "umbraco.cms", "umbraco.cms\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "umbraco.interfaces", "umbraco.interfaces\umbraco.interfaces.csproj", "{511F6D8D-7717-440A-9A57-A507E9A8B27F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "umbraco.providers", "umbraco.providers\umbraco.providers.csproj", "{D7636876-0756-43CB-A192-138C6F0D5E42}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "umbraco.datalayer", "umbraco.datalayer\umbraco.datalayer.csproj", "{C7CB79F0-1C97-4B33-BFA7-00731B579AE2}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "umbraco.controls", "umbraco.controls\umbraco.controls.csproj", "{6EDD2061-82F2-461B-BB6E-879245A832DE}" @@ -128,10 +126,6 @@ Global {511F6D8D-7717-440A-9A57-A507E9A8B27F}.Debug|Any CPU.Build.0 = Debug|Any CPU {511F6D8D-7717-440A-9A57-A507E9A8B27F}.Release|Any CPU.ActiveCfg = Release|Any CPU {511F6D8D-7717-440A-9A57-A507E9A8B27F}.Release|Any CPU.Build.0 = Release|Any CPU - {D7636876-0756-43CB-A192-138C6F0D5E42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D7636876-0756-43CB-A192-138C6F0D5E42}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D7636876-0756-43CB-A192-138C6F0D5E42}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D7636876-0756-43CB-A192-138C6F0D5E42}.Release|Any CPU.Build.0 = Release|Any CPU {C7CB79F0-1C97-4B33-BFA7-00731B579AE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C7CB79F0-1C97-4B33-BFA7-00731B579AE2}.Debug|Any CPU.Build.0 = Debug|Any CPU {C7CB79F0-1C97-4B33-BFA7-00731B579AE2}.Release|Any CPU.ActiveCfg = Release|Any CPU