public abstract FindUsersByName ( string nameToMatch, int pageIndex, int pageSize, int &totalRecords ) : System.Web.Security.MembershipUserCollection | ||
nameToMatch | string | |
pageIndex | int | |
pageSize | int | |
totalRecords | int | |
리턴 | System.Web.Security.MembershipUserCollection |
internal bool ValidateUniqueLogin(MemberSave contentItem, MembershipProvider membershipProvider, HttpActionContext actionContext) { if (contentItem == null) throw new ArgumentNullException("contentItem"); if (membershipProvider == null) throw new ArgumentNullException("membershipProvider"); int totalRecs; var existingByName = membershipProvider.FindUsersByName(contentItem.Username.Trim(), 0, int.MaxValue, out totalRecs); switch (contentItem.Action) { case ContentSaveAction.Save: //ok, we're updating the member, we need to check if they are changing their login and if so, does it exist already ? if (contentItem.PersistedContent.Username.InvariantEquals(contentItem.Username.Trim()) == false) { //they are changing their login name if (existingByName.Cast<MembershipUser>().Select(x => x.UserName) .Any(x => x == contentItem.Username.Trim())) { //the user cannot use this login return false; } } break; case ContentSaveAction.SaveNew: //check if the user's login already exists if (existingByName.Cast<MembershipUser>().Select(x => x.UserName) .Any(x => x == contentItem.Username.Trim())) { //the user cannot use this login return false; } break; default: //we don't support this for members throw new HttpResponseException(HttpStatusCode.NotFound); } return true; }
protected void SaveButton_Click(object sender, EventArgs e) { Errors.Items.Clear(); string serverType = ServerTypeDrop.SelectedValue; DbServer serverTypeParsed; if (!Enum.TryParse <DbServer>(serverType, out serverTypeParsed)) { Errors.Items.Add("Please, choose the type of database engine you wish to use."); return; } // initial testing of the database connection before we attempt to create the main schema IBaseDriver drv = null; switch (serverTypeParsed) { case DbServer.MySql: drv = new BaseDriverMySql(SystemConnstringTextBox.Text); break; case DbServer.MsSql: drv = new BaseDriverMsSql(SystemConnstringTextBox.Text); break; } try { drv.TestConnection(); drv.TestDatabaseIsEmpty(); } catch (Exception ex) { Errors.Items.Add(ex.Message); return; } if (UsernameTextBox.Text == "") { Errors.Items.Add("Please, insert the initial user's name"); return; } if (PasswordTextBox.Text.Length < 7) { Errors.Items.Add("The password must be at least 7 characters long."); return; } if (PasswordTextBox.Text != RetypePasswordTextBox.Text) { Errors.Items.Add("The passwords do not match."); return; } try { System.Net.Mail.MailAddress address = new System.Net.Mail.MailAddress(MailTextBox.Text); } catch (FormatException fe) { Errors.Items.Add(fe.Message); return; } // run the schema dump script switch (serverTypeParsed) { case DbServer.MySql: MySql.Data.MySqlClient.MySqlConnection connection = new MySql.Data.MySqlClient.MySqlConnection(SystemConnstringTextBox.Text); try { MySql.Data.MySqlClient.MySqlScript script = new MySql.Data.MySqlClient.MySqlScript(connection); string scriptText = File.ReadAllText(HttpContext.Current.Server.MapPath(CC.MYSQL_SCHEMA_FILE_PATH)); script.Query = scriptText; script.Query = scriptText; connection.Open(); script.Execute(); connection.Clone(); } catch (Exception esql1) { Errors.Items.Add(esql1.Message); connection.Close(); return; } break; case DbServer.MsSql: SqlConnection conn = new SqlConnection(SystemConnstringTextBox.Text); try { string query = File.ReadAllText(HttpContext.Current.Server.MapPath(CC.MSSQL_SCHEMA_FILE_PATH)); Microsoft.SqlServer.Management.Smo.Server sqlServer = new Server(new ServerConnection(conn)); conn.Open(); sqlServer.ConnectionContext.ExecuteNonQuery(query); conn.Close(); SqlMembershipProvider mssqlProvider = new SqlMembershipProvider(); } catch (Exception esql2) { Errors.Items.Add(esql2.Message); conn.Close(); return; } break; } var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~"); var section = (ConnectionStringsSection)configuration.GetSection("connectionStrings"); System.Web.Security.MembershipProvider membership = null; string username = UsernameTextBox.Text; string password = PasswordTextBox.Text; string mail = MailTextBox.Text; MembershipCreateStatus status; // rewrite the connection in the database and reload the connstring section, also set the defaultProvidder for the membership tag switch (serverTypeParsed) { case DbServer.MySql: section.ConnectionStrings["MySqlServer"].ConnectionString = SystemConnstringTextBox.Text; configuration.AppSettings.Settings["ServerType"].Value = "MySql"; configuration.Save(); SetDefaultMembershipProvider("MySqlMembershipProvider"); // remove the readonly attribute of the connection string variable of the connfiguration var settingsMy = ConfigurationManager.ConnectionStrings["MsSqlServer"]; var fiMy = typeof(ConfigurationElement).GetField("_bReadOnly", BindingFlags.Instance | BindingFlags.NonPublic); fiMy.SetValue(settingsMy, false); settingsMy.ConnectionString = SystemConnstringTextBox.Text; membership = Membership.Providers["MySqlMembershipProvider"]; membership.CreateUser(username, password, mail, "Dummy question", "Dummy answer", true, 1, out status); break; case DbServer.MsSql: section.ConnectionStrings["MsSqlServer"].ConnectionString = SystemConnstringTextBox.Text; configuration.AppSettings.Settings["ServerType"].Value = "MsSql"; configuration.Save(); SetDefaultMembershipProvider("MsSqlMembershipProvider"); // remove the readonly attribute of the connection string variable of the connfiguration var settings = ConfigurationManager.ConnectionStrings["MsSqlServer"]; var fi = typeof(ConfigurationElement).GetField("_bReadOnly", BindingFlags.Instance | BindingFlags.NonPublic); fi.SetValue(settings, false); settings.ConnectionString = SystemConnstringTextBox.Text; membership = Membership.Providers["MsSqlMembershipProvider"]; // generate a ProviderUserKey Random rand = new Random(); Guid key = new Guid(rand.Next(), 2, 3, new byte[] { 10, 20, 30, 40, 50, 60, 70, 80 }); ((SqlMembershipProvider)membership).CreateUser(username, password, mail, "Dummy question", "Dummy answer", true, key, out status); break; } int totalUsers; MembershipUser user = membership.FindUsersByName(username, 0, 1, out totalUsers)[username]; SystemDriver sysDriver = new SystemDriver(drv); sysDriver.SetUserRights((user.ProviderUserKey), null, 11110); // Set FirstRun to false. This cannot be done by the first configuration object - it wil // not like the configuration file since it has been modified by SetDefaultMembershipProvider // in the meantime. var config2 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~"); config2.AppSettings.Settings["FirstRun"].Value = "False"; System.Web.Configuration.WebConfigurationManager.AppSettings["FirstRun"] = "False"; config2.Save(); Errors.Items.Add("Done."); Response.RedirectToRoute("DefaultRoute"); }
public List <TransportMembershipUser> FindUsersByName(string applicationName, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) { _Provider.ApplicationName = _ApplicationName; return(BuildUserList(_Provider.FindUsersByName(usernameToMatch, pageIndex, pageSize, out totalRecords))); }
public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) { return(NonOpenIdMembershiProvider.FindUsersByName(usernameToMatch, pageIndex, pageSize, out totalRecords)); }