DeleteUser() public abstract méthode

public abstract DeleteUser ( string name, bool deleteAllRelatedData ) : bool
name string
deleteAllRelatedData bool
Résultat bool
Exemple #1
0
        public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            var conn = new OdbcConnection(_connectionString);
            var cmd  = new OdbcCommand("{call OpenId_DeleteUserOpenIdLink(?)}", conn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@userId", OdbcType.VarChar, 255).Value = NonOpenIdMembershiProvider.GetUser(username, false).ProviderUserKey.ToString();

            try
            {
                conn.Open();
                cmd.ExecuteNonQuery();
                return(NonOpenIdMembershiProvider.DeleteUser(username, deleteAllRelatedData));
            }
            catch (OdbcException e)
            {
                if (WriteExceptionsToEventLog)
                {
                    Utility.WriteToEventLog(e, "DeleteUser");
                }

                throw new OpenIdMembershipProviderException(e.Message, e.Source, e.StackTrace);
            }
            finally
            {
                conn.Close();
            }
        }
        public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            SqlConnection conn = new SqlConnection(_connectionString);
            SqlCommand    cmd  = new SqlCommand("OpenId_DeleteUserOpenIdLink", conn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@userId", SqlDbType.VarChar, 255).Value = NonOpenIdMembershiProvider.GetUser(username, false).ProviderUserKey.ToString();

            try
            {
                conn.Open();
                cmd.ExecuteNonQuery();
                return(NonOpenIdMembershiProvider.DeleteUser(username, deleteAllRelatedData));
            }
            catch (SqlException e)
            {
                if (WriteExceptionsToEventLog)
                {
                    Utility.WriteToEventLog(e, "DeleteUser");
                }

                throw new OpenIdMembershipProviderException("DeleteUser failed.", e);
            }
            finally
            {
                conn.Close();
            }
        }
        public override System.Web.Security.MembershipUser CreateUser(string username,
                                                                      string password,
                                                                      string email,
                                                                      string passwordQuestion,
                                                                      string passwordAnswer,
                                                                      bool isApproved,
                                                                      object providerUserKey,
                                                                      out MembershipCreateStatus status)
        {
            var membershipUser = PrimaryMembershipProvider.CreateUser(username,
                                                                      password,
                                                                      email,
                                                                      passwordQuestion,
                                                                      passwordAnswer,
                                                                      isApproved,
                                                                      providerUserKey,
                                                                      out status);

            if (membershipUser == null)
            {
                return(null);
            }
            if (status.Equals(MembershipCreateStatus.Success))
            {
                string userId;
                var    providerId = membershipUser.ProviderUserKey ?? membershipUser.UserName;
                try {
                    var guid = new Guid(providerId.ToString());
                    userId = guid.ToString("N");
                } catch (FormatException) {
                    userId = HashToString(providerId.ToString());
                }
                base.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, userId, out status);
                if (!status.Equals(MembershipCreateStatus.Success))
                {
                    PrimaryMembershipProvider.DeleteUser(username, true);
                }
            }
            return(GetHybridMembershipUser(membershipUser));
        }
        public void DeleteUser()
        {
            CreateUserWithHashedPassword();
            Assert.IsTrue(provider.DeleteUser("foo", true));
            var count = _db.GetCollection<User>(provider.CollectionName).Count();
            Assert.AreEqual(0, count);

            provider = new MembershipProvider();
            CreateUserWithHashedPassword();

            // in Mongo, all associated data is stored in same document so
            // passing true or false to DeleteUser will be the same.
            Assert.IsTrue(provider.DeleteUser("foo", deleteAllRelatedData: true));
            count = _db.GetCollection<User>(provider.CollectionName).Count();
            Assert.AreEqual(0, count);
            //Assert.IsTrue(Membership.DeleteUser("foo", false));
            //table = FillTable("SELECT * FROM my_aspnet_Membership");
            //Assert.AreEqual(0, table.Rows.Count);
            //table = FillTable("SELECT * FROM my_aspnet_Users");
            //Assert.AreEqual(1, table.Rows.Count);
        }
Exemple #5
0
        public bool DeleteUser(string applicationName, string username, bool deleteAllRelatedData)
        {
            _Provider.ApplicationName = _ApplicationName;

            return(_Provider.DeleteUser(username, deleteAllRelatedData));
        }
Exemple #6
0
        public static string CreateUserAccount(MembershipProvider userMembershipProvider, User user)
        {
            string error = "";

            user.Email = user.Email.ToLower();

            User validateUser = UserService.GetUserByUsername(user.Username);
            if (validateUser.UserID > 0)
                return UserMessages.UsernameAlreadyUsed;

            validateUser = UserService.GetUserByEmail(user.Email);
            if (validateUser.UserID > 0)
                return UserMessages.EmailAlreadyUsed;

            MembershipCreateStatus status;
            MembershipUser mu = userMembershipProvider.CreateUser(user.Email, user.Password, user.Email, null, null, true, null, out status);

            if (status != MembershipCreateStatus.Success)
                return UserMessages.ErrorCreatingAccount;

            user.AspnetUserID = (Guid)mu.ProviderUserKey;

            int userID = CreateUserAccount(user);

            if(userID == 0)
            {
                // Delete user account
                userMembershipProvider.DeleteUser(user.Email, true);
                return UserMessages.ErrorCreatingAccount;
            }

            user.UserID = userID;

            return error;
        }