private void Page_PreRender() { MembershipUserCollection allUsers = Membership.GetAllUsers(); MembershipUserCollection filteredUsers = new MembershipUserCollection(); if (UserRoles.SelectedIndex > 0) { string[] usersInRole = Roles.GetUsersInRole(UserRoles.SelectedValue); foreach (MembershipUser user in allUsers) { foreach (string userInRole in usersInRole) { if (userInRole == user.UserName) { filteredUsers.Add(user); break; // Breaks out of the inner foreach loop to avoid unneeded checking. } } } } else { filteredUsers = allUsers; } Users.DataSource = filteredUsers; Users.DataBind(); }
FindByUserName_passes_partial_username_to_provider_and_converts_returned_collection_to_PagedListOfMembershipUser() { //arrange var users = new[] { new MembershipUser("AspNetSqlMembershipProvider", "TEST1", "", "", "", "", true, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now), new MembershipUser("AspNetSqlMembershipProvider", "TEST2", "", "", "", "", true, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now) }; var usercollection = new MembershipUserCollection(); var membership = new FakeMembershipProvider_FindByUserName { ReturnedUsers = usercollection, TotalRecords = 123, PageIndex = -1, PageSize = -1 }; var service = new AspNetMembershipProviderWrapper(membership); const int pageNumber = 3; const int size = 10; var username = new Random().Next().ToString(); //act var result = service.FindByUserName(username, pageNumber, size); //assert Assert.Equal(pageNumber - 1, membership.PageIndex); Assert.Equal(size, membership.PageSize); Assert.Equal(usercollection.Count, result.Count()); foreach (var user in result) Assert.Contains(user, users); }
protected void Page_Load(object sender, EventArgs e) { users = Membership.GetAllUsers(); if (IsPostBack) { } else { Msg.Text = ""; // Bind users to ListBox. UsersListBox.DataSource = users; UsersListBox.DataBind(); } // If a user is selected, show the properties for the selected user. if (UsersListBox.SelectedItem != null) { u = users[UsersListBox.SelectedItem.Value]; EmailLabel.Text = u.Email; IsOnlineLabel.Text = u.IsOnline.ToString(); LastLoginDateLabel.Text = u.LastLoginDate.ToString(); CreationDateLabel.Text = u.CreationDate.ToString(); LastActivityDateLabel.Text = u.LastActivityDate.ToString(); CanLoginLabel.Text = u.IsApproved.ToString(); } }
public void FindAll_passes_paging_info_to_provider_and_converts_returned_collection_to_PagedListOfMembershipUser() { //arrange var users = new[] { new MembershipUser("AspNetSqlMembershipProvider", "TEST1", "", "", "", "", true, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now), new MembershipUser("AspNetSqlMembershipProvider", "TEST2", "", "", "", "", true, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now) }; var usercollection = new MembershipUserCollection(); var membership = new FakeMembershipProvider_FindAll { ReturnedUsers = usercollection, TotalRecords = 123, PageIndex = -1, PageSize = -1 }; var service = new AspNetMembershipProviderWrapper(membership); const int index = 3; const int size = 10; //act var result = service.FindAll(index, size); //assert Assert.Equal(index, membership.PageIndex); Assert.Equal(size, membership.PageSize); Assert.Equal(usercollection.Count, result.Count()); foreach (var user in result) Assert.Contains(user, users); }
public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) { var res = new MembershipUserCollection(); totalRecords = 0; //not filled try { var ad = new ADAuthenticationHelper( this.domain, this.contextUsername, this.contextPassword); var users = ad.FindUsers(usernameToMatch); int counter = 0; int startIndex = pageSize * pageIndex; int endIndex = startIndex + pageSize - 1; foreach (var user in users) { if (counter >= startIndex) { MembershipUser u = GetUser(user, true); res.Add(u); } if (endIndex > 0) { if (counter >= endIndex) { break; } } counter++; } } catch (Exception ex) { throw new ProviderException("FindUsersByName() error in " + providerName, ex); } return res; }
/// <summary> /// Returns a collection of membership users for which the e-mail address field contains the specified e-mail address. /// </summary> /// <param name="emailToMatch">The e-mail address to search for.</param> /// <param name="pageIndex">The index of the page of results to return. pageIndex is zero-based.</param> /// <param name="pageSize">The size of the page of results to return.</param> /// <param name="totalRecords">The total number of matched users.</param> /// <returns> /// A <see cref="T:System.Web.Security.MembershipUserCollection"></see> that contains a page of pageSize<see cref="T:System.Web.Security.MembershipUser"></see> objects beginning at the page specified by pageIndex. /// </returns> /// <exception cref="T:System.ArgumentException">emailToMatch is longer than 256 characters.- or -pageIndex is less than zero.- or -pageSize is less than one.- or -pageIndex multiplied by pageSize plus pageSize minus one exceeds <see cref="F:System.Int32.MaxValue"></see>.</exception> public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords) { MembershipUserCollection collection = new MembershipUserCollection(); CustomMembershipUser newUser; foreach (MembershipUser oldUser in base.FindUsersByEmail(emailToMatch, pageIndex, pageSize, out totalRecords)) { ProfileBase profile = ProfileBase.Create(oldUser.UserName); string firstName = (string)profile.GetPropertyValue("FirstName"); string lastName = (string)profile.GetPropertyValue("LastName"); string displayName = (string)profile.GetPropertyValue("DisplayName"); newUser = new CustomMembershipUser(oldUser.ProviderName, oldUser.UserName, oldUser.ProviderUserKey, oldUser.Email, oldUser.PasswordQuestion, oldUser.Comment, oldUser.IsApproved, oldUser.IsLockedOut, oldUser.CreationDate, oldUser.LastLoginDate, oldUser.LastActivityDate, oldUser.LastPasswordChangedDate, oldUser.LastLockoutDate, displayName, firstName, lastName); collection.Add(newUser); } return collection; }
private void BindUsers(bool reloadAllUsers) { if (reloadAllUsers) allUsers = Membership.GetAllUsers(); MembershipUserCollection users = null; string searchText = ""; if (!string.IsNullOrEmpty(gvwUsers.Attributes["SearchText"])) searchText = gvwUsers.Attributes["SearchText"]; bool searchByEmail = false; if (!string.IsNullOrEmpty(gvwUsers.Attributes["SearchByEmail"])) searchByEmail = bool.Parse(gvwUsers.Attributes["SearchByEmail"]); if (searchText.Length > 0) { if (searchByEmail) users = Membership.FindUsersByEmail(searchText); else users = Membership.FindUsersByName(searchText); } else { users = allUsers; } gvwUsers.DataSource = users; gvwUsers.DataBind(); }
public ActionResult Index(string search) { MembershipUserCollection users = new MembershipUserCollection(); if (!string.IsNullOrEmpty(search)) users = Membership.FindUsersByName("%" + search + "%"); return View(users); }
public UserList(MembershipUserCollection users, int totalRecords) { this.TotalRecords = totalRecords; foreach(MembershipUser u in users) { this.Users.Add(new User(u)); } }
public virtual MembershipUserCollection GetMembershipUsers(string providerName) { MembershipUserCollection muc = new MembershipUserCollection(); foreach (User u in Children) { muc.Add(u.GetMembershipUser(providerName)); } return muc; }
private MembershipUserCollection GetHybridMembershipUserCollection(MembershipUserCollection membershipUserCollection) { if(membershipUserCollection == null) { return null; } var hybridMembershipUserCollection = new MembershipUserCollection(); foreach(System.Web.Security.MembershipUser membershipUser in membershipUserCollection) { hybridMembershipUserCollection.Add(GetHybridMembershipUser(membershipUser)); } return hybridMembershipUserCollection; }
public virtual MembershipUserCollection CreateCollection(IEnumerable<IEntry> entries) { var users = new MembershipUserCollection(); foreach(var result in entries) { var user = Create(result); if(user != null) { users.Add(user); } } return users; }
public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) { var col = new MembershipUserCollection(); foreach (MembershipUser user in base.GetAllUsers(pageIndex, pageSize, out totalRecords)) { col.Add(GetUser(user.UserName, false)); } return col; }
public MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) { var collection = new MembershipUserCollection(); foreach (User user in _userMgr.GetAllUsers()) { collection.Add(new COATMemebershipUser(user)); } totalRecords = collection.Count; return collection; }
public static MembershipUserCollection ToMembershipUserCollection(this IEnumerable<User> users) { MembershipUserCollection membershipUsers = new MembershipUserCollection(); foreach (User user in users) { membershipUsers.Add(user.ToMembershipUser()); } return membershipUsers; }
public void Count () { MembershipUserCollection muc = new MembershipUserCollection (); Assert.AreEqual (0, muc.Count, "0"); muc.Add (GetMember ("me")); Assert.AreEqual (1, muc.Count, "1"); muc.Add (GetMember ("me too")); Assert.AreEqual (2, muc.Count, "2"); muc.SetReadOnly (); Assert.AreEqual (2, muc.Count, "2b"); }
protected void Page_Load(object sender, EventArgs e) { _MyUsers = Membership.GetAllUsers(); GridView1.DataSource = _MyUsers; if (!IsPostBack) { GridView1.DataBind(); } CountLabel.Text = string.Format("There are: {0} users in your base!", _MyUsers.Count); }
public ActionResult Show() { MembershipUserCollection friendsList = new MembershipUserCollection(); var friends = friendshipRepo.ListAllFriendships((Guid)currentUser.ProviderUserKey); foreach (var f in friends) { MembershipUser theFriend = Membership.GetUser(f.FriendId); friendsList.Add(theFriend); } return View(friendsList); }
/// <summary> /// Return a MembershipUserCollection of currently online users /// </summary> /// <returns></returns> public static MembershipUserCollection GetOnlineUsers() { MembershipUserCollection members = System.Web.Security.Membership.GetAllUsers(); MembershipUserCollection onlineMembers = new MembershipUserCollection(); foreach (MembershipUser user in members) { if (user.IsOnline) onlineMembers.Add(user); } return onlineMembers; }
/// <summary> /// 在线用户 /// </summary> /// <returns></returns> public ActionResult OnlineUsers() { var allUsers = Membership.GetAllUsers(); var users=new MembershipUserCollection(); foreach (MembershipUser user in allUsers) { if (user.IsOnline) { users.Add(user); } } return View(users); }
private System.Web.Security.MembershipUserCollection BuildUserCollection(MembershipUser[] list) { if (list == null) { return(null); } System.Web.Security.MembershipUserCollection collection = new System.Web.Security.MembershipUserCollection(); foreach (MembershipUser user in list) { collection.Add(user); } return(collection); }
public virtual MembershipUserCollection GetMembershipUsers(string providerName, int startIndex, int maxResults, out int totalRecords) { totalRecords = 0; CountFilter cf = new CountFilter(startIndex, maxResults); MembershipUserCollection muc = new MembershipUserCollection(); foreach (User u in Children) { if (cf.Match(u)) muc.Add(u.GetMembershipUser(providerName)); totalRecords++; } return muc; }
protected void btn_register(object sender, EventArgs e) { try { //string() lbUserName = new string(); string userName; string passWord; string email; DataSet ds = new DataSet(); MembershipUserCollection ExistingUser = new MembershipUserCollection(); MembershipUserCollection ExistingUser11 = new MembershipUserCollection(); MembershipUserCollection getallusers = new MembershipUserCollection(); userName = tbUserName.Text.ToString().Trim(); passWord = tbPassword.Text.ToString().Trim(); email = tbEmail.Text.ToString().Trim(); lbErrorMessage.Visible = false; ExistingUser = Membership.FindUsersByEmail(email); if (ExistingUser.Count != 0) { lbErrorMessage.Text = "Email already exists"; lbErrorMessage.Visible = true; return; } ExistingUser11 = Membership.FindUsersByName(userName); if (ExistingUser11.Count != 0) { lbErrorMessage.Text = "User name already exists"; lbErrorMessage.Visible = true; return; } Membership.CreateUser(userName, passWord, email); Roles.AddUserToRole(userName, "User"); Response.Redirect("Welcome.aspx"); //todo should redirect at this point to a result page and tell them to click here to log in } catch(Exception ex) { lbErrorMessage.Text = "Xin lỗi chúng tôi không thể đăng kí bạn vào lúc này. Xin liên hệ admin tại [email protected] "; lbErrorMessage.Visible = true; return; } }
private void Page_PreRender() { MembershipUserCollection allUsers = Membership.GetAllUsers(); MembershipUserCollection filteredUsers = new MembershipUserCollection(); bool isLockedOut = true; foreach (MembershipUser user in allUsers) { if (user.IsLockedOut == isLockedOut) { filteredUsers.Add(user); } } Users.DataSource = filteredUsers; Users.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { Msg.Text = ""; if (!IsPostBack) { // Bind roles to ListBox. rolesArray = Roles.GetAllRoles(); RolesListBox.DataSource = rolesArray; RolesListBox.DataBind(); // Bind users to ListBox. users = Membership.GetAllUsers(); UsersListBox.DataSource = users; UsersListBox.DataBind(); } }
public static MembershipUserCollection FindUsersByPredicate(this Expression<Func<DataAccess.Login, bool>> predicate, int pageIndex, int pageSize, out int totalRecords) { MembershipUserCollection returnValue = new MembershipUserCollection(); totalRecords = 0; using (var db = new DataAccess.CSSDataContext()) { var logins = db.Logins.Where(predicate); totalRecords = logins.Count(); foreach (var login in logins.Skip(pageIndex * pageSize).Take(pageSize)) { returnValue.Add(MembershipUserUtility.CreateMembershipUserFromLogin(login)); } } return returnValue; }
public static MembershipUserCollection GetAllMembershipUsers(string PROVIDERNAME, int pageIndex, int pageSize, out int totalRecords) { DbEntities entities = new DbEntities(); MembershipUserCollection result = new MembershipUserCollection(); try { IQueryable<appusers> listaTotalUsuarios = from users in entities.appusers select users; foreach (appusers u in listaTotalUsuarios) { result.Add(u.GetMembershipUser(PROVIDERNAME)); } } catch (Exception e) { throw new Exception(string.Format("MSG:{0}\nINNER:{2}\nSTACK:{1}", e.Message, e.StackTrace, e.InnerException)); } totalRecords = result.Count; return result; }
/// <summary> /// Handles the Click event of the btnSearch control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void btnSearch_Click(object sender, EventArgs e) { try { if (!string.IsNullOrEmpty(txtSearchBy.Text.Trim())) { string text = txtSearchBy.Text.Trim(); text = text.Replace("*", "%"); text = text.Replace("?", "_"); if (ddlSearchBy.SelectedIndex == 0 /* userID */) { membershipUserCollection = Membership.FindUsersByName(text); } else { membershipUserCollection = Membership.FindUsersByEmail(text); } BindMembershipUserCollection(membershipUserCollection); hlShowAll.Visible = true; } } catch (Exception ex) { Logger.Error(typeof(userlist).Name + ".btnSearch_Click", ex); Master.MessageCenter.DisplayCriticalMessage(ex.Message); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string[] roles = System.Web.Security.Roles.GetAllRoles(); IsRoles.DataSource = roles; IsRoles.DataBind(); System.Web.Security.MembershipUserCollection users = System.Web.Security.Membership.GetAllUsers(); IstUsers.DataSource = users; IstUsers.DataBind(); } if (IsRoles.SelectedItem != null) { GetUsersInRole(); } }
private void Page_PreRender() { MembershipUserCollection allUsers = Membership.GetAllUsers(); MembershipUserCollection filteredUsers = new MembershipUserCollection(); bool isActive; if (active.SelectedValue == "Active") { isActive = true; } else { isActive = false; } foreach (MembershipUser user in allUsers) { if (user.IsApproved == isActive) { filteredUsers.Add(user); } } Users.DataSource = filteredUsers; Users.DataBind(); }
private System.Web.Security.MembershipUserCollection ToMembershipUserCollection(IEnumerable <Models.User> users) { var mUsers = users.Select(user => new System.Web.Security.MembershipUser( membershipName ?? Name, user.UserName, user.Id, user.Email, null, null, true, false, user.CreatedOn, System.DateTime.MinValue, System.DateTime.MinValue, System.DateTime.MinValue, System.DateTime.MinValue)).ToList(); var collection = new System.Web.Security.MembershipUserCollection(); mUsers.ForEach(collection.Add); return(collection); }
public static MembershipUserCollection GetAllUserWithSelectUser() { MembershipUserCollection misUsuariosConOtro = new MembershipUserCollection(); MembershipUserCollection misUsuarios = Membership.GetAllUsers(); if (misUsuarios == null) return null; MembershipUser miOtroUsuario = null; foreach (MembershipUser miUsuario in misUsuarios) { miOtroUsuario = new MembershipUser( miUsuario.ProviderName, "[Seleccione un usuario...]", miUsuario.ProviderUserKey, miUsuario.Email, miUsuario.PasswordQuestion, miUsuario.Comment, miUsuario.IsApproved, miUsuario.IsLockedOut, miUsuario.CreationDate, miUsuario.LastLoginDate, miUsuario.LastActivityDate, miUsuario.LastPasswordChangedDate, miUsuario.LastLockoutDate); break; } misUsuariosConOtro.Add(miOtroUsuario); foreach (MembershipUser miUsuario in misUsuarios) { misUsuariosConOtro.Add(miUsuario); } return misUsuariosConOtro; }
/// <summary> /// Converts a collection of user objects to ASP.NET MembershipUser objects /// </summary> /// <param name="users">The users.</param> /// <returns></returns> private MembershipUserCollection ConvertUserVOListToMembershipUserCollection(IList users) { MembershipUserCollection userCollection = new MembershipUserCollection(); foreach (UserVO userVO in users) { userCollection.Add(ConvertUserVOToMembershipUser(userVO)); } return userCollection; }