Beispiel #1
0
        // deletes user from user table and membership tables.
        public static void DeleteUser(User user)
        {
            var simpleRoles = (SimpleRoleProvider)Roles.Provider;
            var simpleMembership = (SimpleMembershipProvider)Membership.Provider;

            List<string> roles = new List<string>();
            if (simpleRoles.IsUserInRole(user.Email, "Admin")) roles.Add("Admin");
            if (simpleRoles.IsUserInRole(user.Email, "Member")) roles.Add("Member");

            // possible OAuth account

            var oAuths = OAuthWebSecurity.GetAccountsFromUserName(user.Email);
            var oAuth = oAuths.Count > 0 ? oAuths.ToList()[0] : null;

            // ** Unit of Work Pattern

            using (var uow = new UnitOfWorkDistributed())
            {
                simpleRoles.RemoveUsersFromRoles(new string[] { user.Email }, roles.ToArray());

                if (oAuth != null)
                    OAuthWebSecurity.DeleteAccount(oAuth.Provider, oAuth.ProviderUserId);
                else
                    simpleMembership.DeleteAccount(user.Email);

                simpleMembership.DeleteUser(user.Email, false);

                uow.Complete();
            }
        }
Beispiel #2
0
        // add a user to user table, oauth membership table and role table

        public static void InsertOAuthUser(User user, string provider, string providerUserId, string role)
        {
            // ** Unit of Work Pattern

            using (var uow = new UnitOfWorkDistributed())
            {
                BikeShopContext.Users.Insert(user);
                OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, user.Email);
                Roles.AddUserToRole(user.Email, role);

                uow.Complete();
            }
        }
Beispiel #3
0
        // add a user to user table, simplemembership table, and roles table

        public static void InsertUser(User user, string password, string role)
        {
            // ** Unit of Work Pattern

            using (var uow = new UnitOfWorkDistributed())
            {
                BikeShopContext.Users.Insert(user);
                WebSecurity.CreateAccount(user.Email, password);
                Roles.AddUserToRole(user.Email, role);

                uow.Complete();
            }
        }
Beispiel #4
0
        // add a user to user table, oauth membership table and role table
        public static void InsertOAuthUser(User user, string provider, string providerUserId, string role)
        {
            // ** Unit of Work Pattern

            using (var uow = new UnitOfWorkDistributed())
            {
                BikeShopContext.Users.Insert(user);
                OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, user.Email);
                Roles.AddUserToRole(user.Email, role);

                uow.Complete();
            }
        }
Beispiel #5
0
        // deletes user from user table and membership tables.

        public static void DeleteUser(User user)
        {
            var simpleRoles      = (SimpleRoleProvider)Roles.Provider;
            var simpleMembership = (SimpleMembershipProvider)Membership.Provider;

            List <string> roles = new List <string>();

            if (simpleRoles.IsUserInRole(user.Email, "Admin"))
            {
                roles.Add("Admin");
            }
            if (simpleRoles.IsUserInRole(user.Email, "Member"))
            {
                roles.Add("Member");
            }

            // possible OAuth account

            var oAuths = OAuthWebSecurity.GetAccountsFromUserName(user.Email);
            var oAuth  = oAuths.Count > 0 ? oAuths.ToList()[0] : null;

            // ** Unit of Work Pattern

            using (var uow = new UnitOfWorkDistributed())
            {
                simpleRoles.RemoveUsersFromRoles(new string[] { user.Email }, roles.ToArray());

                if (oAuth != null)
                {
                    OAuthWebSecurity.DeleteAccount(oAuth.Provider, oAuth.ProviderUserId);
                }
                else
                {
                    simpleMembership.DeleteAccount(user.Email);
                }

                simpleMembership.DeleteUser(user.Email, false);

                uow.Complete();
            }
        }
Beispiel #6
0
        // add a user to user table, simplemembership table, and roles table
        public static void InsertUser(User user, string password, string role)
        {
            // ** Unit of Work Pattern

            using (var uow = new UnitOfWorkDistributed())
            {
                BikeShopContext.Users.Insert(user);
                WebSecurity.CreateAccount(user.Email, password);
                Roles.AddUserToRole(user.Email, role);

                uow.Complete();
            }
        }