Exemplo n.º 1
0
    private void mDelete(Guid iDUser, bool loadList = true)
    {
        //DAL.GlobalCore.TransactionMgr tx = DAL.GlobalCore.TransactionMgr.ThreadTransactionMgr();
        try
        {
            //tx.BeginTransaction();

            Members member = new Members(iDUser);
            member.MarkAsDeleted(false);
            member.Save();

            MembershipUser user = Membership.GetUser(iDUser);
            Membership.DeleteUser(user.UserName, true);

            if (loadList)
            {
                pMessage.Clear();
                pMessage.Add(Farschidus.Translator.AppTranslate["general.message.deleted"], Farschidus.Web.UI.Message.MessageTypes.Success);
                mShowMessage(pMessage);

                mLoadList();
            }
        }
        catch (Exception ex)
        {
            pMessage.Clear();
            pMessage.Add(ex.Message, Farschidus.Web.UI.Message.MessageTypes.Error);
            mShowMessage(pMessage);
            //tx.RollbackTransaction();
        }
    }
        public ActionResult Delete(PrimarySchoolStaff model)
        {
            try
            {
                // TODO: Add delete logic here
                string             firstName = model.FirstName;
                string             lastName  = model.LastName;
                PrimarySchoolStaff theStaff  = work.PrimarySchoolStaffRepository.GetByID(model.PersonID);
                work.PrimarySchoolStaffRepository.Delete(theStaff);
                Membership.DeleteUser(Convert.ToString(theStaff.UserID));
                work.Save();

                if (User.Identity.Name != "5000001")
                {
                    AuditTrail audit = new AuditTrail {
                        Date = DateTime.Now, Action = "Staff was Deleted,  First Name:-" + firstName + " Last Name:-" + lastName, UserID = User.Identity.Name
                    };
                    work.AuditTrailRepository.Insert(audit);
                    work.Save();
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 批量删除数据
        /// </summary>
        private void OnDelete()
        {
            string userName = hV.Value.Trim();

            if (string.IsNullOrEmpty(userName))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "请勾选一行数据进行操作", "操作错误", "error");
                return;
            }

            string errorMsg = string.Empty;

            try
            {
                if (Membership.DeleteUser(userName))
                {
                    WebHelper.MessageBox.MessagerShow(this.Page, lbtnPostBack, "操作成功!");
                    GetSearchItem();
                    Bind();
                }
                else
                {
                    WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "操作失败,请检查!", "系统提示");
                }
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
            }
            if (!string.IsNullOrEmpty(errorMsg))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, errorMsg, "系统异常提示");
            }
        }
Exemplo n.º 4
0
        public ActionResult Deactivate(LogOnModel model)
        {
            ViewBag.Title = "Deactivate User";
            string emailAdd = model.EmailAddress;

            //[email protected]
            string UserName = Membership.GetUserNameByEmail(emailAdd);


            if (!string.IsNullOrEmpty(UserName))
            {
                if (Membership.DeleteUser(UserName))
                {
                    ViewBag.Message = UserName + " Was Deleted Successfully";
                }
                else
                {
                    ViewBag.Message = UserName + " Was Not Deleted";
                }
            }
            else
            {
                ViewBag.Message = UserName + " was not found to be deleted";
            }

            return(View("ValidateUser"));
        }
Exemplo n.º 5
0
        public ActionResult DeleteUser(string id)
        {
            ViewData["PageTitle"] = "Delete User";

            if (Request.HttpMethod != "POST")
            {
                ModelState.SetModelValue("id", new ValueProviderResult(id, id, CultureInfo.CurrentUICulture));
            }
            else
            {
                MembershipUser user = Membership.GetUser(id);
                if (user == null)
                {
                    ModelState.AddModelError("id", "Username not found");
                }

                if (ModelState.IsValid)
                {
                    Membership.DeleteUser(id, true);
                }
                return(RedirectToAction("Accounts"));
            }

            return(View());
        }
Exemplo n.º 6
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void AdminGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
        case "DeleteUser":

            //Delete user from the UserProfiles table by UserGuid

            try
            {
                //remove all the user's roles
                string[] usersRoles = Roles.GetRolesForUser(e.CommandArgument.ToString());
                foreach (string r in usersRoles)
                {
                    Roles.RemoveUserFromRole(e.CommandArgument.ToString(), r);
                }

                //delete the membership user

                Membership.DeleteUser(e.CommandArgument.ToString(), true);

                //bind
                this.BindAdminGridView();
            }
            catch
            {
            }

            break;
        }
    }
Exemplo n.º 7
0
 public ActionResult DeleteAccount(string id)
 {
     //Membership.FindUsersByEmail("");
     //repository.DeleteAccount(id);
     Membership.DeleteUser(id);
     return(View("ViewAllUsers"));
 }
        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);
        }
        public void UnlockUser()
        {
            MembershipCreateStatus status;

            Membership.CreateUser("foo", "barbar!", null, "question", "answer", true, out status);
            Assert.False(Membership.ValidateUser("foo", "bar2"));
            Assert.False(Membership.ValidateUser("foo", "bar3"));
            Assert.False(Membership.ValidateUser("foo", "bar3"));
            Assert.False(Membership.ValidateUser("foo", "bar3"));
            Assert.False(Membership.ValidateUser("foo", "bar3"));

            // the user should be locked now so the right password should fail
            Assert.False(Membership.ValidateUser("foo", "barbar!"));

            MembershipUser user = Membership.GetUser("foo");

            Assert.True(user.IsLockedOut);

            Assert.True(user.UnlockUser());
            user = Membership.GetUser("foo");
            Assert.False(user.IsLockedOut);

            Assert.True(Membership.ValidateUser("foo", "barbar!"));

            //Cleanup
            Membership.DeleteUser("foo");
        }
Exemplo n.º 10
0
        public void DeleteUser(DT.User user)
        {
            RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);

            if (user.Id != null && user.Id != Guid.Empty)
            {
                //delete asp.net user
                Membership.DeleteUser(user.UserName);
                using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
                    var query = context.UserGroupBases.OfType <DA.User>().Where(x => x.Id == user.Id);
                    if (query.Count() > 0)
                    {
                        //delete affiliation first
                        var queryMapping = context.UserGroupUserGroups.Where(x => x.UserGroupId == user.Id);
                        if (queryMapping.Count() > 0)
                        {
                            context.UserGroupUserGroups.DeleteAllOnSubmit(queryMapping);
                        }

                        //delete user from access db
                        context.UserGroupBases.DeleteOnSubmit(query.First());
                        context.SubmitChanges();
                    }
                }
            }
        }
Exemplo n.º 11
0
        public ActionResult DeleteHead(string UserName)
        {
            //delete head on Laboratory
            var x = (from y in con.Laboratories
                     where y.UserName == UserName
                     select y.UserName).FirstOrDefault();


            if (x != "")
            {
                x = null;
            }

            var z = (from y in con.Laboratory_Head
                     where y.UserName == UserName
                     select y).FirstOrDefault();

            con.DeleteObject(z);


            //delete User from aspnet users
            Membership.DeleteUser(UserName);


            con.SaveChanges();

            //    return View();
            return(RedirectToAction("Head", "AdminBold"));
        }
Exemplo n.º 12
0
        /// <summary>
        /// 注册用户
        /// <param name="User">用户注册资料</param>
        /// <param name="UserEX">用户附加详细资料</param>
        /// </summary>
        /// <returns></returns>
        public bool UserReg(User_ViewModel User, aspnet_UsersEX UserEX)
        {
            String guid = Guid.NewGuid().ToString();

            User = User ?? new User_ViewModel()
            {
                UserName     = guid,
                UserPassword = guid,
                Email        = "",
                Answer       = "no",
                Question     = "no"
            };
            MembershipCreateStatus state     = new MembershipCreateStatus();
            MembershipUser         Temp_User = Membership.CreateUser(User.UserName, User.UserPassword, User.Email, User.Question, User.Answer, false, out state);

            if (state == MembershipCreateStatus.Success)
            {
                UserEX.User_ID = (Guid)Temp_User.ProviderUserKey;
            }
            else
            {
                return(false);
            }

            if (!DB_UserEX.Insert(UserEX))
            {
                Membership.DeleteUser(Temp_User.UserName);
            }
            else
            {
                Roles.AddUserToRole(User.UserName, "普通会员");
            }
            return(true);
        }
Exemplo n.º 13
0
        protected void deleteLongTimePreregisteredUsers()
        {
            string taskName = "Mazání předregistrovaných uživatelů bez autorizace e-mailem";

            try
            {
                using (dboManager dboManager = new dboManager())
                {
                    dboManager.command.CommandText = "SELECT * FROM [aspnet_UsersDetails] WHERE [userStatus] = 'PreRegistered'";
                    SqlDataReader reader = dboManager.command.ExecuteReader();
                    while (reader.Read())
                    {
                        if (Membership.GetUser(new Guid(reader["userId"].ToString())).CreationDate < DateTime.Now.AddDays(2))
                        {
                            Membership.DeleteUser(Membership.GetUser(new Guid(reader["userId"].ToString())).UserName);
                            dboManager.command2.CommandText = "DELETE [aspnet_UsersDetails] WHERE [userId] = @userId";
                            dboManager.command2.Parameters.Clear();
                            dboManager.command2.Parameters.AddWithValue("@userId", reader["userId"].ToString());
                            dboManager.command2.ExecuteNonQuery();
                        }
                    }
                }
                userManagementUL.InnerHtml += "<li><i class='icon-ok'></i>&nbsp;&nbsp;&nbsp;" + taskName + "</li>";
            }
            catch (Exception ex) { userManagementUL.InnerHtml += "<li><span class='alert-danger'><i class='icon-warning-sign'></i>&nbsp;&nbsp;&nbsp;" + taskName + "<ul style='padding-left: 20px;'><li>" + ex.Message + "</li></ul><span></li>"; }
        }
Exemplo n.º 14
0
        public ActionResult delete_user(string u_name)
        {
            var user_profile = db.userprofiles.Where(r => r.username == u_name).FirstOrDefault();

            db.userprofiles.Remove(user_profile);
            Membership.DeleteUser(u_name);

            var user_deposit = db.deposit_history.Where(r => r.username == u_name).ToList();

            if (user_deposit.Count() > 0)
            {
                foreach (var d in user_deposit)
                {
                    db.deposit_history.Remove(d);
                }
            }
            var user_refill = db.refil_history.Where(r => r.username == u_name).ToList();

            if (user_refill.Count() > 0)
            {
                foreach (var re in user_refill)
                {
                    db.refil_history.Remove(re);
                }
            }
            db.SaveChanges();
            return(RedirectToAction("AllProfiles", "Home"));
        }
        public void Delete(int id)
        {
            var entity = _repository.Repository <User>().GetAllBy(null, null, "webpages_Roles").Where(u => u.ID == id).SingleOrDefault();

            var roles = System.Web.Security.Roles.GetRolesForUser(entity.Username);

            if (roles.Any())
            {
                System.Web.Security.Roles.RemoveUserFromRoles(entity.Username, roles);
            }

            try
            {
                foreach (var p in entity.UserPlants)
                {
                    _repository.Repository <UserPlant>().Delete(p);
                }
                _repository.Save();
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw;
            }

            Membership.DeleteUser(entity.Username);
        }
        public void UpdateUser()
        {
            MembershipCreateStatus status;

            Membership.CreateUser("foo", "barbar!", "*****@*****.**", "color", "blue", true, out status);
            Assert.Equal(MembershipCreateStatus.Success, status);

            MembershipUser user = Membership.GetUser("foo");

            user.Comment          = "my comment";
            user.Email            = "my email";
            user.IsApproved       = false;
            user.LastActivityDate = new DateTime(2008, 1, 1);
            user.LastLoginDate    = new DateTime(2008, 2, 1);
            Membership.UpdateUser(user);

            MembershipUser newUser = Membership.GetUser("foo");

            Assert.Equal(user.Comment, newUser.Comment);
            Assert.Equal(user.Email, newUser.Email);
            Assert.Equal(user.IsApproved, newUser.IsApproved);
            Assert.Equal(user.LastActivityDate, newUser.LastActivityDate);
            Assert.Equal(user.LastLoginDate, newUser.LastLoginDate);

            //Cleanup
            Membership.DeleteUser("foo");
        }
Exemplo n.º 17
0
 public IBLMessage DeleteUser(string userEmail)
 {
     try
     {
         MembershipUser user = Membership.GetUser(userEmail);
         if (user != null)
         {
             if (Membership.DeleteUser(userEmail))
             {
                 UserManagementDAL.DeleteApplication(userEmail);
                 UserManagementDAL.DeleteCustomer(userEmail);
                 return(new BLMessage {
                     Message = "User deleted.", Result = SaveAttempts.Success
                 });
             }
             else
             {
                 return new BLMessage {
                            Message = "User could not be deleted.", Result = SaveAttempts.Failure
                 }
             };
         }
         return(new BLMessage {
             Message = "There is no user with this email.", Result = SaveAttempts.Failure
         });
     }
     catch (Exception exception)
     {
         // log exception...
         Logger.Write(exception.Message, "AdminBusiness");
     }
     return(new BLMessage {
         Message = "An error occured during deleting user. Please try again later.", Result = SaveAttempts.Failure
     });
 }
        public void GetPasswordWithNullValues()
        {
            MembershipCreateStatus status;

            provider = new MySQLMembershipProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("requiresQuestionAndAnswer", "false");
            config.Add("enablePasswordRetrieval", "true");
            config.Add("passwordFormat", "clear");
            config.Add("applicationName", "/");
            provider.Initialize(null, config);

            MembershipUser user = provider.CreateUser("foo", "barbar!", "*****@*****.**", null, null, true, null, out status);

            Assert.NotNull(user);

            string pw = provider.GetPassword("foo", null);

            Assert.Equal("barbar!", pw);

            //Cleanup
            Membership.DeleteUser("foo");
        }
        public ActionResult Clear()
        {
            // delete all tipper data
            using (var ctxt = new TippSpielContext())
            {
                foreach (var tipp in ctxt.TippMatchList)
                {
                    ctxt.Entry(tipp).State = System.Data.EntityState.Deleted;
                }

                ctxt.SaveChanges();
            }

            // delete all users
            var users = GetUserList();

            foreach (var user in users)
            {
                var username = user.username;

                try
                {
                    if (WebSecurity.UserExists(username) == true)
                    {
                        Membership.DeleteUser(username);
                    }
                }
                catch (MembershipCreateUserException e)
                {
                    log.ErrorFormat("User {0} not created: {1}", user.username, e.Message);
                }
            }

            return(RedirectToAction("Index"));
        }
Exemplo n.º 20
0
        public ActionResult DeleteUser(string username)
        {
            MembershipUser user = Membership.GetUser(username);

            Membership.DeleteUser(username);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 21
0
        protected void lnkDeleteSelected_Click(object sender, EventArgs e)
        {
            string cids = Request["cid"];

            using (CourseEntities context = new CourseEntities())
            {
                MemberManager manager = new MemberManager(new GeneralRepository <Member>(context));
                if (cids.Contains(','))
                {
                    string[] ids = cids.Split(',');

                    foreach (var i in ids)
                    {
                        int    j  = Convert.ToInt32(i);
                        Member mb = manager.Find(x => x.MemberID == j).Result.FirstOrDefault();
                        Membership.DeleteUser(mb.Name);
                        manager.Delete(j);
                    }
                }
                else
                {
                    int    j  = Convert.ToInt32(cids);
                    Member mb = manager.Find(x => x.MemberID == j).Result.FirstOrDefault();
                    Membership.DeleteUser(mb.Name);
                    manager.Delete(j);
                }
            }
            PopulateControls();
        }
Exemplo n.º 22
0
        /// <summary>
        /// Deletes all registration data of specified user
        /// </summary>
        /// <param name="userId">Id of the user</param>
        public void DeleteUser(int userId)
        {
            string userName = this.GetUserName(userId);
            var    roles    = Roles.GetRolesForUser(userName);

            if (roles.Length > 0)
            {
                Roles.RemoveUserFromRoles(userName, roles);
            }

            var membershipProvider = Membership.Provider as SimpleMembershipProvider;

            if (membershipProvider.HasLocalAccount(userId))
            {
                membershipProvider.DeleteAccount(userName);
            }
            else
            {
                var accounts = membershipProvider.GetAccountsForUser(userName);
                if (accounts.Count != 0)
                {
                    foreach (var account in accounts)
                    {
                        membershipProvider.DeleteOAuthAccount(account.Provider, account.ProviderUserId);
                    }
                }
            }

            Membership.DeleteUser(userName, true);
        }
Exemplo n.º 23
0
        protected void Application_Start(object sender, EventArgs e)
        {
            var logCfg = new System.IO.FileInfo(HttpContext.Current.Server.MapPath("~/Log4net.config"));

            log4net.Config.XmlConfigurator.ConfigureAndWatch(logCfg);

            var roles = Roles.GetAllRoles();

            if (!roles.Any(m => m.Equals(DefaultRoleName, StringComparison.OrdinalIgnoreCase)))
            {
                Roles.CreateRole(DefaultRoleName);
            }

            if (!Membership.ValidateUser(DefaultUserName, DefaultUserName + "123456"))
            {
                var user = Membership.GetUser(DefaultUserName);
                if (user != null)
                {
                    Membership.DeleteUser(DefaultUserName, true);
                }

                user = Membership.CreateUser(DefaultUserName, DefaultUserName + "123456");
                Roles.AddUserToRole(DefaultUserName, DefaultRoleName);
            }
        }
Exemplo n.º 24
0
 public void Initialize()
 {
     if (Membership.FindUsersByName("test.user2") != null)
     {
         Membership.DeleteUser("test.user2");
     }
 }
 public void DeleteUser(object sender, EventArgs e)
 {
     // Membership.DeleteUser(username, false);
     ProfileManager.DeleteProfile(username);
     Membership.DeleteUser(username, true);
     Response.Redirect("edit_user_modal_success.aspx");
 }
Exemplo n.º 26
0
 private void EliminarUsuario(string nombre)
 {
     if (!string.IsNullOrEmpty(nombre))
     {
         Membership.DeleteUser(nombre, true);
     }
 }
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string        selName = GridView1.DataKeys[e.RowIndex].Value.ToString();
            SqlConnection con     = new SqlConnection(str);

            con.Open();
            SqlCommand    chkCmd = new SqlCommand("select * from IssueRecords where UserName='******'", con);
            SqlDataReader dr     = chkCmd.ExecuteReader();

            if (dr.Read())
            {
                lblError.Text      = "Sorry , You Can't Delete This User";
                lblError.ForeColor = System.Drawing.Color.Red;
                lblError.Visible   = true;
            }
            else
            {
                Membership.DeleteUser(selName);
                strQuery = "delete DeleteRequest where UserName='******'";
                change(strQuery);
                strQuery = "delete from Library_User where UserName='******'";
                change(strQuery);
                getData("select * from Library_User ", 0);
            }
        }
Exemplo n.º 28
0
        protected void btnDeleteUser_Click(object sender, EventArgs e)
        { // check if user exists, there is two ways
          //  if (Membership.FindUsersByName(txtUser.Text).Count != 0)  // one way

            // is to create an instance of MembershipUser and check to fill it from db, if not null means user exists,
            MembershipUser existingUser = null;  // second way

            existingUser = Membership.GetUser(txtUser.Text);
            if (existingUser != null)  // if user exists, then delete him
            {
                if (Membership.DeleteUser(txtUser.Text))
                {
                    postMsg("Was Deleted");
                    populateGvAllUsers();
                }
                else
                {
                    postMsg("Was Not Deleted");
                }
            }
            else
            {
                postMsg("User does not exists!!");
            }
            populateCheckBoxListRolesUsers();
        }
Exemplo n.º 29
0
        private static void CreateUser(string username, string email)
        {
            var         scope = ObjectScopeProvider1.GetNewObjectScope();
            List <User> users = (from c in scope.GetOqlQuery <User>().ExecuteEnumerable()
                                 where c.Username.ToLower().Trim().Equals(username.Trim().ToLower())
                                 select c).ToList();

            Membership.DeleteUser(username);
            Membership.CreateUser(username, "password@123", email);
            if (users.Count == 0)
            {
                scope.Transaction.Begin();
                var user = new User
                {
                    Email                = email,
                    Failcount            = 0,
                    IsheAdmin            = true,
                    IsheDonationReceiver = true,
                    Username             = username.Trim().ToLower()
                };
                scope.Add(user);
                scope.Transaction.Commit();
            }
            else
            {
                foreach (var user in users)
                {
                    scope.Transaction.Begin();
                    user.IsheDonationReceiver = true;
                    user.IsheAdmin            = true;
                    scope.Add(user);
                    scope.Transaction.Commit();
                }
            }
        }
Exemplo n.º 30
0
        //Delete an account.
        public ActionResult DeleteAccount(int id, string userName)
        {
            List <int> idlist = new List <int>();

            idlist.Add(id);

            if (accountService.DeleteUser(idlist))
            {
                var user  = Membership.GetUser(userName);
                var roles = Roles.GetAllRoles();
                foreach (var item in roles)
                {
                    if (Roles.IsUserInRole(userName, item))
                    {
                        Roles.RemoveUserFromRole(userName, item);
                    }
                }
                Membership.DeleteUser(userName, true);

                TempData["message"] = " The account was deleted.";
                return(RedirectToAction("ListAccount"));
            }
            TempData["message"] = "Delete account error.";
            return(RedirectToAction("ListAccount"));
        }