Copied from here: https://github.com/ASP-NET-MVC/aspnetwebstack/blob/master/src/WebMatrix.WebData/SimpleMembershipProvider.cs Apache License copyright 2.0 blah blah... to support more database engine. This is one horribly big file. Somebody should be smacked with a large trout. Half way through I feel like a coding monkey, the rest of the CMS feel like it's not even this big. GRRRRR!!!!
Inheritance: WebMatrix.WebData.ExtendedMembershipProvider
Beispiel #1
0
        /// <summary>
        /// Initializes the membership provider.
        /// </summary>
        /// <param name="simpleMembership">The simple membership.</param>
        /// <param name="connectionStringName">Name of the connection string.</param>
        /// <param name="userTableName">Name of the user table.</param>
        /// <param name="userIdColumn">The user id column.</param>
        /// <param name="userNameColumn">The user name column.</param>
        /// <param name="createTables">if set to <c>true</c> [create tables].</param>
        /// <exception cref="System.InvalidOperationException">Initialize membership provider already called.</exception>
        internal static void InitializeMembershipProvider(PhunSimpleMembershipProvider simpleMembership, string connectionStringName, string userTableName, string userIdColumn, string userNameColumn, bool createTables)
        {
            if (simpleMembership.InitializeCalled)
            {
                throw new InvalidOperationException("Initialize membership provider already called.");
            }

            simpleMembership.ConnectionStringName = connectionStringName;
            simpleMembership.UserIdColumn = userIdColumn;
            simpleMembership.UserNameColumn = userNameColumn;
            simpleMembership.UserTableName = userTableName;
            if (createTables)
            {
                simpleMembership.CreateTablesIfNeeded();
            }
            else
            {
                // We want to validate the user table if we aren't creating them
                simpleMembership.ValidateUserTable();
            }
            simpleMembership.InitializeCalled = true;
        }
Beispiel #2
0
 /// <summary>
 /// Creates the default simple membership provider.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="currentDefault">The current default.</param>
 /// <returns></returns>
 private static PhunSimpleMembershipProvider CreateDefaultSimpleMembershipProvider(string name, MembershipProvider currentDefault)
 {
     var membership = new PhunSimpleMembershipProvider(previousProvider: currentDefault);
     var config = new NameValueCollection();
     membership.Initialize(name, config);
     return membership;
 }
        /// <summary>
        /// Gets the user ids from names.
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="usernames">The usernames.</param>
        /// <returns>List of user ids.</returns>
        private List<int> GetUserIdsFromNames(DapperContext db, string[] usernames)
        {
            var userIds = new List<int>(usernames.Length);
            foreach (string username in usernames)
            {
                var provider = new PhunSimpleMembershipProvider();

                var id = provider.GetUserId(db, this.UserTableName, this.UserNameColumn, this.UserIdColumn, username);
                if (id == -1)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "No user found '{0}'.", username));
                }

                userIds.Add(id);
            }

            return userIds;
        }