示例#1
0
        public ActionResult DeleteAccount(string UserName)
        {
            try
            {
                if (!WebSecurity.UserExists(UserName))
                {
                    return(Content(String.Format("<h4 class='text-danger'>Не найден пользователь '{0}'</h4>", UserName)));
                }

                string[] userRoles = Roles.GetRolesForUser(UserName);
                if (userRoles.Count() > 0)
                {
                    Roles.RemoveUserFromRoles(UserName, userRoles);
                }
                SimpleMembershipProvider provider = Membership.Provider as SimpleMembershipProvider;
                bool deleteResult = provider.DeleteAccount(UserName);
                deleteResult = deleteResult && provider.DeleteUser(UserName, true);
                if (deleteResult)
                {
                    return(Content(String.Format("<h4 class='text-success'>Аккаунт пользователя '{0}' успешно удален</h4>", UserName)));
                }
                else
                {
                    return(Content(String.Format("<h4 class='text-danger'>Аккаунта пользователя '{0}' возможно не удалось удалить полностью</h4>", UserName)));
                }
            }
            catch (Exception)
            {
                return(Content(String.Format("<h4 class='text-danger'>Возникли ошибки в процессе удаления аккаунта пользователя '{0}'</h4>", UserName)));
            }
        }
        public JsonResult Delete(Guid id)
        {
            try
            {
                Customer customer = unitOfWork.CustomerRepository().GetByID(id);
                int      userId   = customer.UserId;
                unitOfWork.CustomerRepository().Delete(customer);
                unitOfWork.Save();

                SimpleMembershipProvider membership = (SimpleMembershipProvider)Membership.Provider;
                string userName = membership.GetUserNameFromId(userId);

                if (Roles.GetRolesForUser(userName).Count() > 0)
                {
                    Roles.RemoveUserFromRoles(userName, Roles.GetRolesForUser(userName));
                }
                membership.DeleteAccount(userName);
                membership.DeleteUser(userName, true);

                return(this.Json(new { success = true }));
            }
            catch
            {
                return(this.Json(new { success = false }));
            }
        }
示例#3
0
        public void DeleteUser(string username)
        {
            var userRoles = roles.GetRolesForUser(username);

            foreach (var userRole in userRoles)
            {
                roles.RemoveUsersFromRoles(new[] { username }, new[] { userRole });
            }
            memberships.DeleteAccount(username);
            memberships.DeleteUser(username, true);
        }
示例#4
0
 public static void DeleteUserIfExist(string userName)
 {
     if (membership.GetUser(userName, false) != null)
     {
         if (roles.GetRolesForUser(userName).Count() > 0)
         {
             roles.RemoveUsersFromRoles(new[] { userName }, roles.GetRolesForUser(userName));
         }
         membership.DeleteAccount(userName);
         membership.DeleteUser(userName, true);
     }
 }
示例#5
0
            public void CanDeleteAccount()
            {
                var simpleMembershipProvider = new SimpleMembershipProvider();

                simpleMembershipProvider.DeleteAccount("Test1");
            }
示例#6
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // 尝试注册用户
                try
                {
                    //首先注册用户
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    Email.RegisterReminder("新用户注册提醒!注册ID:" + model.UserName + ",姓名:" + model.Name +
                                           ",移动电话:" + model.MobilePhone + ",注册时间:" + DateTime.Now
                                           );
                    #region 附加用户Profile信息
                    UserProfile adduser = UsersDB.UserProfiles.Where(i => i.UserName == model.UserName).Single();

                    adduser.Name        = model.Name;        //用户名 必填
                    adduser.MobilePhone = model.MobilePhone; //移动电话 必填

                    adduser.Phone                = model.Phone;
                    adduser.Birth                = model.Birth;
                    adduser.Country              = model.Country;
                    adduser.Place                = model.Place;
                    adduser.Address              = model.Address;
                    adduser.ZipCode              = model.ZipCode;
                    adduser.WantGet              = model.WantGet;
                    adduser.HasGlucometer        = model.HasGlucometer;
                    adduser.GlucometerType       = model.GlucometerType;
                    adduser.GlucometerId         = model.GlucometerId;
                    adduser.IsWantGetInformation = model.IsWantGetInformation;

                    adduser.Gender          = model.Gender;
                    adduser.DateOfDiagnosis = model.DateOfDiagnosis;
                    adduser.DiabetesType    = model.DiabetesType;
                    //adduser.DiseaseControl = model.DiseaseControl;
                    adduser.DiseaseControl = Request.Form["DiseaseControl"];
                    // adduser.HasRecommend = model.HasRecommend;
                    adduser.HasRecommend  = Request.Form["HasRecommend"];
                    adduser.TestFrequency = model.TestFrequency;
                    #endregion


                    try
                    {
                        UsersDB.SaveChanges();
                    }
                    catch
                    {
                        //删除用户
                        if (WebSecurity.UserExists(model.UserName))
                        {
                            SimpleMembershipProvider smp = new SimpleMembershipProvider();
                            smp.DeleteAccount(model.UserName);
                        }
                    }

                    WebSecurity.Login(model.UserName, model.Password);
                    return(RedirectToAction("RegisterSuccess", "Account"));
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return(View(model));
        }