public ActionResult RequestforBusinessAccount(BusinessProfileViewModel businessProfileVM)
 {
     if (ModelState.IsValid)
     {
         if (Membership.FindUsersByName(businessProfileVM.BusinessName).Count == 1)
         {
             ModelState.AddModelError("", "Business name already exists");
             ViewBag.businessCategoryList = commonController.GetAllBusinessCategory();
             return(View(businessProfileVM));
         }
         else if (Membership.FindUsersByEmail(businessProfileVM.Email).Count == 1)
         {
             ModelState.AddModelError("", "Email already exists");
             ViewBag.businessCategoryList = commonController.GetAllBusinessCategory();
             return(View(businessProfileVM));
         }
         else
         {
             businessProfileService.CreateBusinessprofile(businessProfileVM);
             return(RedirectToAction("BusinessView", "Account"));
         }
     }
     else
     {
         ViewBag.businessCategoryList = commonController.GetAllBusinessCategory();
         return(View());
     }
 }
 private static void InitializeSecurity()
 {
     if (Membership.FindUsersByName("admin").Cast <MembershipUser>().FirstOrDefault() == null)
     {
         Membership.CreateUser("admin", "password", "*****@*****.**");
     }
 }
Beispiel #3
0
        public void TestCreateUserOverrides()
        {
            try
            {
                MembershipCreateStatus status;
                Membership.CreateUser("foo", "barbar!", null, "question", "answer", true, out status);
                int records;
                MembershipUserCollection users = Membership.FindUsersByName("F%", 0, 10, out records);
                Assert.Equal(1, records);
                Assert.Equal("foo", users["foo"].UserName);

                Membership.CreateUser("test", "barbar!", "*****@*****.**",
                                      "question", "answer", true, out status);
                users = Membership.FindUsersByName("T%", 0, 10, out records);
                Assert.Equal(1, records);
                Assert.Equal("test", users["test"].UserName);
            }
            catch (Exception ex)
            {
                Assert.True(ex.Message != String.Empty, ex.Message);
            }

            //Cleanup
            Membership.DeleteUser("test", true);
            Membership.DeleteUser("foo", true);
        }
Beispiel #4
0
        /// <summary>
        /// Enableds the changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        public void EnabledChanged(object sender, EventArgs e)
        {
            try {
                string   userID   = null;
                CheckBox checkBox = sender as CheckBox;
                if (checkBox == null)
                {
                    return;
                }

                if (!string.IsNullOrEmpty(checkBox.Attributes["Value"]))
                {
                    userID = checkBox.Attributes["Value"];
                }

                if (userID == null)
                {
                    return;
                }

                MembershipUser user = Membership.FindUsersByName(userID)[userID];
                user.IsApproved = checkBox.Checked;

                Membership.UpdateUser(user);
            }
            catch (Exception ex) {
                Logger.Error(typeof(userlist).Name + ".EnabledChanged", ex);
                Master.MessageCenter.DisplayCriticalMessage(ex.Message);
            }
        }
Beispiel #5
0
    public void fillgrid()
    {
        admin     ad = new admin();
        int       totrec;
        ArrayList list = new ArrayList(Roles.GetUsersInRole("user"));
        //MembershipUserCollection coll = // Roles.GetUsersInRole(ddlrole.SelectedItem.Text);
        DataTable dtt = new DataTable();

        dtt.Columns.Add("UserName");
        dtt.Columns.Add("Name");
        dtt.Columns.Add("Email");
        dtt.Columns.Add("MobileNumber");


        int j = 0;

        foreach (string strrr in list)
        {
            MembershipUserCollection coll = Membership.FindUsersByName(strrr);
            foreach (MembershipUser user1 in coll)
            {
                ProfileCommon com = Profile.GetProfile(user1.UserName);
                string        a   = user1.ProviderUserKey.ToString();
                dtt.Rows.Add(user1.UserName, com.name, user1.Email, com.Mobile);
                ++j;
            }
        }


        totrec = j;
        GridView1.DataSource = dtt;
        GridView1.DataBind();
    }
        protected void RadButtonCreate_Click(object sender, EventArgs e)
        {
            if (Membership.FindUsersByName(TextBoxUserName.Text).Count == 0 && Membership.FindUsersByEmail(TextBoxUserName.Text).Count == 0)
            {
                MembershipUser membershipUser = Membership.CreateUser(TextBoxUserName.Text, TextBoxPassword.Text, TextBoxUserName.Text);

                Roles.AddUserToRole(TextBoxUserName.Text, "User");
                //        Roles.AddUserToRole(TextBoxUserName.Text, "Administrator");

                PlaceHolderCreateAdmin.Visible = false;
                CreateAdminStatus.Text         = "User account " + TextBoxUserName.Text + " is created";

                DALPortalDataContext dc      = new DataAccess.Database.DALPortalDataContext();
                userSetting          setting = new userSetting();
                setting.userId             = (Guid)membershipUser.ProviderUserKey;
                setting.name               = TextBoxName.Text;
                setting.companyCode        = companyDDL.SelectedValue;
                setting.defaultCultureCode = "nl";

                dc.userSettings.InsertOnSubmit(setting);
                dc.SubmitChanges();
                Session["username"] = TextBoxUserName.Text;
                Session["name"]     = TextBoxName.Text;
                Response.Redirect("~/Pages/AddRole.aspx");
            }
            else
            {
                CreateAdminStatus.Text = "There is already a user with that username";
            }
        }
Beispiel #7
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    /* //th20101124 ให้ไปใส่ Detail อื่น ๆ ต่อ
                     * FormsService.SignIn(model.UserName, false);
                     * return RedirectToAction("Index", "Home");
                     */
                    var    UserList = Membership.FindUsersByName(model.UserName);
                    string userid   = "";
                    foreach (MembershipUser user in UserList)
                    {
                        userid = user.ProviderUserKey.ToString();
                        break;
                    }
                    return(RedirectToAction("Details", "UserAdministration", new { area = "UserAdministration", id = userid }));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }
Beispiel #8
0
 public ActionResult Login(LoginInfo loginInfo, string returnUrl = "")
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     if (Membership.ValidateUser(loginInfo.UserName, loginInfo.Password))
     {
         FormsAuthentication.SetAuthCookie(loginInfo.UserName, false);
         if (string.IsNullOrEmpty(returnUrl))
         {
             return(Redirect("/"));
         }
         return(Redirect(returnUrl));
     }
     else
     {
         //这段代码为了演示“自动化”异常处理
         if (Membership.FindUsersByName(loginInfo.UserName).Count == 0)
         {
             throw new InvalidUserNameException("Specified user account does not exists!");
         }
         throw new InvalidPasswordException("Specified password is incorrect!");
     }
 }
Beispiel #9
0
 public ActionResult Create()
 {
     if (User.IsInRole("Administrator"))
     {
         MembershipUserCollection users = Membership.GetAllUsers();
         var model = new CreateStudentViewModel
         {
             Users = users.OfType <MembershipUser>().Select(x => new SelectListItem
             {
                 Value = x.UserName,
                 Text  = x.UserName,
             })
         };
         return(View(model));
     }
     if (User.IsInRole("Default"))
     {
         MembershipUserCollection users = Membership.FindUsersByName(User.Identity.Name);
         var model = new CreateStudentViewModel
         {
             Users = users.OfType <MembershipUser>().Select(x => new SelectListItem
             {
                 Value = x.UserName,
                 Text  = x.UserName,
             })
         };
         return(View(model));
     }
     return(View(/*user has a role that is not "Default" or "Administrator"  Needs error message*/));
 }
Beispiel #10
0
        public AuthController()
        {
            String AdminRole = "Admin";

            if (!Roles.RoleExists(AdminRole))
            {
                Roles.CreateRole(AdminRole);
            }

            String BasicUserRole = "User";

            if (!Roles.RoleExists(BasicUserRole))
            {
                Roles.CreateRole(BasicUserRole);
            }

            String AdminEmail    = "*****@*****.**";
            String AdminPassword = "******";

            if (Membership.FindUsersByName(AdminEmail).Count == 0)
            {
                Membership.CreateUser(AdminEmail, AdminPassword, AdminEmail);
                Roles.AddUserToRole(AdminEmail, AdminRole);
            }

            String UserEmail    = "*****@*****.**";
            String UserPassword = "******";

            if (Membership.FindUsersByName(UserEmail).Count == 0)
            {
                Membership.CreateUser(UserEmail, UserPassword, UserEmail);
                Roles.AddUserToRole(UserEmail, BasicUserRole);
            }
        }
Beispiel #11
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            // Use LocalDB for Entity Framework by default - Use same connect string, allowing the appharbor injection
            string defaultString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            Database.DefaultConnectionFactory = new SqlConnectionFactory(defaultString);

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            if (!Roles.RoleExists("User"))
            {
                Roles.CreateRole("User");
            }
            if (Membership.FindUsersByName("adminstrador").Count == 0)
            {
                MembershipUser user = Membership.CreateUser("adminstrador", "password4@DM1N");
                if (!Roles.RoleExists("Admin"))
                {
                    Roles.CreateRole("Admin");
                }
                Roles.AddUserToRole("adminstrador", "Admin");
                user.Comment = "MainAdmin";
                Membership.UpdateUser(user);
            }
        }
Beispiel #12
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Panel pnlLogoutControl = (Panel)Login1.FindControl("pnlLogoutControl");
            pnlLogoutControl.Visible = false;
            Panel pnlLoginControl = (Panel)Login1.FindControl("pnlLoginControl");
            pnlLoginControl.Visible = true;
            Label          lblUsername = (Label)pnlLogoutControl.FindControl("lblUsername");
            MembershipUser user        = null;
            if (Login1.UserName != null && Login1.UserName.Length > 0)
            {
                MembershipUserCollection users = Membership.FindUsersByName(Login1.UserName);
                user = users[Login1.UserName];
            }

            if (user != null)
            {
                // show logout button
                pnlLogoutControl.Visible = true;
                pnlLoginControl.Visible  = false;
                lblUsername.Text         = user.UserName;
            }
            else if (User.Identity.IsAuthenticated)
            {
                // show logout button
                pnlLogoutControl.Visible = true;
                pnlLoginControl.Visible  = false;
                lblUsername.Text         = User.Identity.Name;
            }
        }
    }
Beispiel #13
0
        public ActionResult UserRol(string id)
        {
            MembershipUserCollection mu = Membership.FindUsersByName(id);

            ViewBag.Rollar = Roles.GetAllRoles();
            return(View(mu));
        }
        public string Execute(params string[] parameters)
        {
            MembershipUserCollection results = null;

            if (!string.IsNullOrEmpty(ByEmail))
            {
                results = Membership.FindUsersByEmail(ByEmail);
            }
            else if (!string.IsNullOrEmpty(ByName))
            {
                results = Membership.FindUsersByName(ByName);
            }
            else
            {
                results = Membership.GetAllUsers();
            }
            int usercnt = 0;

            foreach (MembershipUser user in results)
            {
                usercnt++;
                if (OnlyOnline && !user.IsOnline)
                {
                    continue;
                }

                OnCommandOutput?.Invoke(this, user);
            }
            int onlinecnt = Membership.GetNumberOfUsersOnline();

            return($"Went through {usercnt} users. {onlinecnt} users online.");
        }
Beispiel #15
0
    protected void SearchForUsers(object sender, EventArgs e, GridView dataGrid, DropDownList dropDown, TextBox textBox)
    {
        ICollection coll = null;
        string      text = textBox.Text;

        text = text.Replace("*", "%");
        text = text.Replace("?", "_");
        int total = 0;

        if (text.Trim().Length != 0)
        {
            if (dropDown.SelectedIndex == 0 /* userID */)
            {
                coll = Membership.FindUsersByName(text);
            }
            else
            {
                coll = Membership.FindUsersByEmail(text);
            }
        }

        dataGrid.PageIndex  = 0;
        dataGrid.DataSource = coll;
        dataGrid.DataBind();

        Pager1.TotalRecords = coll.Count;
    }
Beispiel #16
0
        private void BindAllUsers(bool reloadAllUsers)
        {
            MembershipUserCollection allUsers = null;

            if (reloadAllUsers)
            {
                allUsers = Membership.GetAllUsers();
            }
            string usernameToMatch = "";

            if (!string.IsNullOrEmpty(this.UsersGridView.Attributes["SearchText"]))
            {
                usernameToMatch = this.UsersGridView.Attributes["SearchText"];
            }
            if (!string.IsNullOrEmpty(this.UsersGridView.Attributes["SearchByEmail"]))
            {
                bool.Parse(this.UsersGridView.Attributes["SearchByEmail"]);
            }
            if (usernameToMatch.Length > 0)
            {
                allUsers = Membership.FindUsersByName(usernameToMatch);
            }
            else
            {
                allUsers = this.allRegisteredUsers;
            }
            this.UsersGridView.DataSource = allUsers;
            this.UsersGridView.DataBind();
        }
        protected void lnkLast_Click(object sender, EventArgs e)
        {
            MembershipUserCollection allUsers = new MembershipUserCollection();

            if (UsernameToMatch == string.Empty)
            {
                allUsers = Membership.GetAllUsers();
            }
            else
            {
                allUsers = Membership.FindUsersByName(this.UsernameToMatch + "%");
            }


            int totalRecords = 0;
            MembershipUserCollection filteredUsers = new MembershipUserCollection();

            foreach (MembershipUser user in allUsers)
            {
                if (user.IsApproved == true)
                {
                    filteredUsers.Add(user);
                    totalRecords++;
                }
            }

            this.PageIndex = (totalRecords - 1) / this.PageSize;
            BindUserAccounts();
        }
Beispiel #18
0
        //
        // GET: /Convocatoria/Details/5

        public void DetailsAsync(int idConv)
        {
            AsyncManager.OutstandingOperations.Increment(3);
            var front = new FrontOffice.FrontOfficeServiceClient();

            AsyncManager.Parameters["confirmo"]       = true;
            front.GetFuentesDatosMovimientoCompleted += (s, e) =>
            {
                AsyncManager.Parameters["fweb"] = e.Result;
                AsyncManager.OutstandingOperations.Decrement();
            };
            front.GetFuentesDatosMovimientoAsync((int)Session["idMov"]);

            front.ObtenerConvocatoriaXIdCompleted += (s, e) =>
            {
                AsyncManager.Parameters["conv"] = e.Result;
                AsyncManager.OutstandingOperations.Decrement();
            };
            front.ObtenerConvocatoriaXIdAsync(idConv);

            if ((Session["logueado"] != null && (bool)Session["logueado"]) && Membership.FindUsersByName((String)Session["emailUs"]).Count > 0)
            {
                front.ConfirmoAsistenciaUsuarioCompleted += (s, e) =>
                {
                    AsyncManager.Parameters["confirmo"] = e.Result;
                    AsyncManager.OutstandingOperations.Decrement();
                };
                front.ConfirmoAsistenciaUsuarioAsync(idConv, (int)Session["idUsr"]);
            }
            else
            {
                AsyncManager.OutstandingOperations.Decrement();
            }
        }
        public virtual IEnumerable <Claim> GetClaims(ClaimsPrincipal principal, RequestDetails requestDetails)
        {
            var userName = principal.Identity.Name;
            var claims   = new List <Claim>(from c in principal.Claims select c);

            // email address
            var membership = Membership.FindUsersByName(userName)[userName];

            if (membership != null)
            {
                string email = membership.Email;
                if (!String.IsNullOrEmpty(email))
                {
                    claims.Add(new Claim(ClaimTypes.Email, email));
                }
            }

            // roles
            GetRolesForToken(userName).ToList().ForEach(role => claims.Add(new Claim(ClaimTypes.Role, role)));

            // profile claims
            claims.AddRange(GetProfileClaims(userName));

            return(claims);
        }
Beispiel #20
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int userCount;
            MembershipUserCollection usersCollection;

            if (string.IsNullOrWhiteSpace(this.userName.Text))
            {
                usersCollection = Membership.GetAllUsers(int.Parse(this.pageIndex.Value), int.Parse(this.pageSize.Value), out userCount);
            }
            else
            {
                usersCollection = Membership.FindUsersByName(this.userName.Text.Trim(), int.Parse(this.pageIndex.Value), int.Parse(this.pageSize.Value), out userCount);
            }

            List <EFUser> users = new List <EFUser>(usersCollection.Count);

            foreach (MembershipUser user in usersCollection)
            {
                users.Add(user as EFUser);
            }

            this.infoCount.Value      = userCount.ToString();
            this.usersView.DataSource = users;
            this.usersView.DataBind();
        }
Beispiel #21
0
 /// <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);
     }
 }
Beispiel #22
0
        private static void InitializeSecurity()
        {
            var adminUser = Membership.FindUsersByName("admin").Cast <MembershipUser>().FirstOrDefault();

            if (adminUser == null)
            {
                lock (lockObject)
                {
                    adminUser = Membership.FindUsersByName("admin").Cast <MembershipUser>().FirstOrDefault();

                    if (adminUser == null)
                    {
                        adminUser = Membership.CreateUser("admin", "Passw0rd!", "*****@*****.**");

                        var adminUserId = adminUser.ProviderUserKey.ToString();
                        IUserPrivilegesRepository userPrivilegesRepository = new UserTablesServiceContext();
                        userPrivilegesRepository.AddPrivilegeToUser(adminUserId, PrivilegeConstants.AdminPrivilege);
                        userPrivilegesRepository.AddPrivilegeToUser(adminUserId, PrivilegeConstants.QueuesUsagePrivilege);
                        userPrivilegesRepository.AddPrivilegeToUser(adminUserId, PrivilegeConstants.TablesUsagePrivilege);
                        userPrivilegesRepository.AddPrivilegeToUser(adminUserId, PrivilegeConstants.BlobContainersUsagePrivilege);
                        userPrivilegesRepository.AddPrivilegeToUser(adminUserId, string.Format(CultureInfo.InvariantCulture, "{0}{1}", "SampleData", PrivilegeConstants.TablePrivilegeSuffix));
                    }
                }
            }
        }
Beispiel #23
0
        public IEnumerable <Claim> GetClaims(IClaimsPrincipal principal, RequestDetails requestDetails)
        {
            var userName = principal.Identity.Name;
            var claims   = new List <Claim>();

            // email address
            string email = Membership.FindUsersByName(userName)[userName].Email;

            if (!String.IsNullOrEmpty(email))
            {
                claims.Add(new Claim(ClaimTypes.Email, email));
            }

            // roles
            GetRolesForToken(userName).ToList().ForEach(role => claims.Add(new Claim(ClaimTypes.Role, role)));

            // profile claims
            if (ProfileManager.Enabled)
            {
                var profile = ProfileBase.Create(userName, true);
                if (profile != null)
                {
                    foreach (SettingsProperty prop in ProfileBase.Properties)
                    {
                        string value = profile.GetPropertyValue(prop.Name).ToString();
                        if (!String.IsNullOrWhiteSpace(value))
                        {
                            claims.Add(new Claim(ProfileClaimPrefix + prop.Name.ToLowerInvariant(), value));
                        }
                    }
                }
            }

            return(claims);
        }
Beispiel #24
0
        /// <summary>
        /// Get a list of internal users that contain the given criteria
        /// </summary>
        /// <param name="UserName">The account criteria name</param>
        /// <returns>An account collection</returns>
        public static MembershipUserCollection LookUpUsers(string UserName)
        {
            if (UserName != null && UserName.Length > 0)
            {
                UserName = "******" + UserName + "%";
            }
            else
            {
                UserName = "******";
            }

            MembershipUserCollection MemUser = Membership.FindUsersByName(UserName);

            MembershipUserCollection theFinalList = new MembershipUserCollection();

            if (MemUser.Count <= 0)
            {
                return(null);
            }

            foreach (MembershipUser theUser in MemUser)
            {
                theFinalList.Add(theUser);
            }

            return(theFinalList);
        }
Beispiel #25
0
        public virtual IEnumerable <Claim> GetClaims(ClaimsPrincipal principal, RequestDetails requestDetails)
        {
            var userName = principal.Identity.Name;
            var claims   = new List <Claim>(from c in principal.Claims select c);

            claims.Add(new Claim("http://schemas.microsoft.com/LiveID/Federation/2008/05/ImmutableID", userName));
            var nameIdClaim = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier);

            if (nameIdClaim == null)
            {
                claims.Add(new Claim(ClaimTypes.NameIdentifier, userName));
            }

            // email address
            var membership = Membership.FindUsersByName(userName)[userName];

            if (membership != null)
            {
                string email = membership.Email;
                if (!String.IsNullOrEmpty(email))
                {
                    claims.Add(new Claim(ClaimTypes.Email, email));
                }
            }

            // roles
            GetRolesForToken(userName).ToList().ForEach(role => claims.Add(new Claim(ClaimTypes.Role, role)));

            // profile claims
            claims.AddRange(GetProfileClaims(userName));

            return(claims);
        }
    protected void BindAllUsers(bool reloadUsers)
    {
        MembershipUserCollection users = null;
        string searchText    = string.Empty;
        bool   searchByEmail = false;

        if (reloadUsers)
        {
            users = Membership.GetAllUsers();
        }
        if (!string.IsNullOrEmpty(gvUsers.Attributes["SearchText"]))
        {
            searchText = gvUsers.Attributes["SearchText"];
        }
        if (!string.IsNullOrEmpty(gvUsers.Attributes["SeachByEmail"]))
        {
            searchByEmail = bool.Parse(gvUsers.Attributes["SeachByEmail"]);
        }
        if (searchText.Length > 0)
        {
            users = searchByEmail ? Membership.FindUsersByEmail(searchText) : Membership.FindUsersByName(searchText);
        }
        else
        {
            users = allUsers;
        }
        gvUsers.DataSource = users;
        gvUsers.DataBind();
    }
        public ActionResult Manage(ManageViewModel model)
        {
            var users = Membership.FindUsersByName(HttpContext.User.Identity.Name);

            foreach (MembershipUser user in users)
            {
                if (user != null)
                {
                    if (model.Email != null)
                    {
                        user.Email = model.Email;
                        Membership.UpdateUser(user);
                    }

                    try
                    {
                        model.Email            = user.Email;
                        model.LastActivityDate = user.LastActivityDate;
                        model.UserName         = user.UserName;
                    }
                    catch (Exception e)
                    {
                        ModelState.AddModelError("", "Произошла ошибка");
                    }
                }
            }
            // Появление этого сообщения означает наличие ошибки; повторное отображение формы

            return(View(model));
        }
Beispiel #28
0
    public void EnabledChanged(object sender, EventArgs e)
    {
        string   userID   = null;
        CheckBox checkBox = sender as CheckBox;

        if (checkBox == null)
        {
            return;
        }

        if (!string.IsNullOrEmpty(checkBox.Attributes["Value"]))
        {
            userID = checkBox.Attributes["Value"];
        }

        if (userID == null)
        {
            return;
        }

        MembershipUser user = Membership.FindUsersByName(userID)[userID];

        user.IsApproved = checkBox.Checked;

        Membership.UpdateUser(user);
    }
Beispiel #29
0
    protected void btnChangePassword_Click(object sender, EventArgs e)
    {
        try
        {
            var oUser             = new User();
            var btnChangePassword = sender as RadButton;
            var row = btnChangePassword.Parent;

            var UserName = (row.FindControl("txtUserName") as RadTextBox).Text;
            var Password = (row.FindControl("txtPassword") as RadTextBox).Text;

            if (Membership.FindUsersByName(UserName).Count == 0)
            {
                oUser.UserInsert(UserName, UserName, Password, "");
            }
            else
            {
                oUser.ChangePassword(UserName, Password);
            }
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }
Beispiel #30
0
        private void BindUserAccounts()
        {
            MembershipUserCollection allUsers = new MembershipUserCollection();

            if (UsernameToMatch == string.Empty)
            {
                allUsers = Membership.GetAllUsers();
            }
            else if (this.UsernameToMatch == "All")
            {
                this.PageIndex = 0;
                allUsers       = Membership.GetAllUsers();
            }
            else
            {
                allUsers = Membership.FindUsersByName(this.UsernameToMatch + "%");
            }


            int totalRecords = 0;
            MembershipUserCollection filteredUsers = new MembershipUserCollection();

            foreach (MembershipUser user in allUsers)
            {
                if (user.IsApproved == true)
                {
                    filteredUsers.Add(user);
                    totalRecords++;
                }
            }
            List <MembershipUser> users = new List <MembershipUser>();

            foreach (MembershipUser user in filteredUsers)
            {
                users.Add(user);
            }

            List <MembershipUser> _sortedUsers = users.OrderByDescending(x => x.CreationDate).ToList();

            if (UsernameToMatch == string.Empty)
            {
                UsersGridView.DataSource = _sortedUsers.Skip(this.PageIndex * this.PageSize).Take(this.PageSize);
            }
            else
            {
                UsersGridView.DataSource = _sortedUsers;
            }
            UsersGridView.DataBind();

            bool visitingFirstPage = (this.PageIndex == 0);

            lnkFirst.Enabled = !visitingFirstPage;
            lnkPrev.Enabled  = !visitingFirstPage;

            int  lastPageIndex    = (totalRecords - 1) / this.PageSize;
            bool visitingLastPage = (this.PageIndex >= lastPageIndex);

            lnkNext.Enabled = !visitingLastPage;
            lnkLast.Enabled = !visitingLastPage;
        }