public RegisterVM GetRegisterViewModel()
 {
     var roleProvider = new SimpleRoleProvider(Roles.Provider);
     var userVM = new RegisterVM();
     userVM.Roles = roleProvider.GetAllRoles().ToList();
     return userVM;
 }
示例#2
0
        internal static void InitializeRoleProvider(
            SimpleRoleProvider simpleRoles,
            DatabaseConnectionInfo connect,
            string userTableName,
            string userIdColumn,
            string userNameColumn,
            bool createTables,
            SimpleMembershipProviderCasingBehavior casingBehavior
            )
        {
            if (simpleRoles.InitializeCalled)
            {
                throw new InvalidOperationException(
                          WebDataResources.Security_InitializeAlreadyCalled
                          );
            }

            simpleRoles.CasingBehavior = casingBehavior;
            simpleRoles.ConnectionInfo = connect;
            simpleRoles.UserTableName  = userTableName;
            simpleRoles.UserIdColumn   = userIdColumn;
            simpleRoles.UserNameColumn = userNameColumn;

            if (createTables)
            {
                simpleRoles.CreateTablesIfNeeded();
            }
            simpleRoles.InitializeCalled = true;
        }
 private static SimpleRoleProvider CreateDefaultSimpleRoleProvider(string name, RoleProvider currentDefault)
 {
     RoleProvider previousProvider = currentDefault;
     SimpleRoleProvider provider = new SimpleRoleProvider(previousProvider);
     NameValueCollection config = new NameValueCollection();
     provider.Initialize(name, config);
     return provider;
 }
示例#4
0
        private static SimpleRoleProvider CreateDefaultSimpleRoleProvider(string name, RoleProvider currentDefault)
        {
            var roleProvider           = new SimpleRoleProvider(previousProvider: currentDefault);
            NameValueCollection config = new NameValueCollection();

            roleProvider.Initialize(name, config);
            return(roleProvider);
        }
        /// <summary>
        /// Iterates through a list of students, sets up the default password then
        /// assigns the student to the relevant role
        /// </summary>
        /// <param name="membership">instance of the simplemembership provider</param>
        /// <param name="roleProvider">instance of the simpleroleprovider</param>
        private static void SetUpStudents(SimpleMembershipProvider membership, SimpleRoleProvider roleProvider)
        {
            new List<string> {"Andrew", "Tim", "Bartoz", "Narelle", "Robert"}
                .ForEach(u =>

                        SetUpUserInRole(membership,roleProvider,"Student",u)
                    );
        }
        /// <summary>
        /// Iterates through a list of Instructors, sets up the default password then
        /// assigns the instructor to the relevant role
        /// </summary>
        /// <param name="membership">instance of the simplemembership provider</param>
        /// <param name="roles">instance of the simpleroleprovider</param>
        private static void SetUpInstructors(SimpleMembershipProvider membership, SimpleRoleProvider roles)
        {
            new List<string> {"JPaterson", "BMacDonald"}
                .ForEach(u =>

                        SetUpUserInRole(membership, roles, "Instructor", u)
                    );
        }
        public void DeletUser(int userId)
        {
            var user = db.Users.Find(userId);
            
            var roleProvider = new SimpleRoleProvider(Roles.Provider);
            roleProvider.RemoveUsersFromRoles(new[] { user.EmailAddress }, roleProvider.GetRolesForUser(user.EmailAddress));
            ((SimpleMembershipProvider)Membership.Provider).DeleteAccount(user.EmailAddress); // deletes record from webpages_Membership table

            Membership.DeleteUser(user.EmailAddress, true);
            
        }
 public List<UserVM> GetUsersViewModel()
 {
     var userVMs = new List<UserVM>();
     var roleProvider = new SimpleRoleProvider(Roles.Provider);
     foreach (var user in db.Users.ToList())
     {
         string[] roles = roleProvider.GetRolesForUser(user.EmailAddress);
         var userVM = new UserVM { FirstName = user.FirstName, LastName = user.LastName, EmailAddress = user.EmailAddress, SelectedRole = roles[0], ID = user.ID };
         userVMs.Add(userVM);
     }
     return userVMs;
 }
示例#9
0
        private static void InitializeProviders(DatabaseConnectionInfo connect, string userTableName, string userIdColumn, string userNameColumn, bool autoCreateTables)
        {
            SimpleMembershipProvider sMembership = Membership.Provider as SimpleMembershipProvider;

            if (sMembership != null)
            {
                InitializeMembershipProvider(sMembership, connect, userTableName, userIdColumn, userNameColumn, autoCreateTables);
            }

            SimpleRoleProvider sRoles = Roles.Provider as SimpleRoleProvider;

            if (sRoles != null)
            {
                InitializeRoleProvider(sRoles, connect, userTableName, userIdColumn, userNameColumn, autoCreateTables);
            }
        }
        /// <summary>
        /// Check to see if required roles exist if not create them
        /// </summary>
        /// <param name="roleProvider">instance of the simpleroleprovider</param>
        private static void SetUpRoles(SimpleRoleProvider roleProvider)
        {
            if (!roleProvider.RoleExists("Admin"))
            {
                roleProvider.CreateRole("Admin");
            }

            if (!roleProvider.RoleExists("Instructor"))
            {
                roleProvider.CreateRole("Instructor");
            }

            if (!roleProvider.RoleExists("Student"))
            {
                roleProvider.CreateRole("Student");
            }
        }
        public static void Initialize()
        {

            if (WebSecurity.Initialized)
            {
                return;
            }

  //          try
    //        {

                WebSecurity.InitializeDatabaseConnection("ULTRA_TGZ", "Users", "ID", "Email", true);

                // Create DefaultSuperUser and DefaultRoles

                if (!WebSecurity.UserExists("TGZ_ROOT"))
                {

                    WebSecurity.CreateUserAndAccount("TGZ_ROOT", "cegth.pthTGZ2016");
                }

                SimpleRoleProvider role = new SimpleRoleProvider();
                if (!role.RoleExists("TGZ_ADMIN_STORE"))
                {
                    role.CreateRole("TGZ_ADMIN_STORE");
                }

                role.AddUsersToRoles(new[] { "TGZ_ROOT" }, new[] { "TGZ_ADMIN_STORE" });


//            }

           /* catch (Exception e)
            {
                Logger.Instance.Error("System Error: Ошибка инициализации хранилища SimpleMembershipProvider - " + e);
                return;
            }*/

            Logger.Instance.Debug("Service SimpleMembershipProvider проинициализирован... ");

        }
示例#12
0
 /// <summary>
 /// Creates the default simple role provider.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="currentDefault">The current default.</param>
 /// <returns></returns>
 private static SimpleRoleProvider CreateDefaultSimpleRoleProvider(string name, RoleProvider currentDefault)
 {
     var roleProvider = new SimpleRoleProvider(previousProvider: currentDefault);
     var config = new NameValueCollection();
     roleProvider.Initialize(name, config);
     return roleProvider;
 }
 // GET: /Admin/Role/
 public ActionResult Index()
 {
     SimpleRoleProvider provider = new SimpleRoleProvider();
     return null;
 }
        /// <summary>
        /// Sets up the account of the provided username in the role provided
        /// </summary>
        /// <param name="membership">instance of the simple membership provider</param>
        /// <param name="roleProvider">instance of the simple roleprovider</param>
        /// <param name="role">Role type to be assigned</param>
        /// <param name="userName">Username</param>
        private static void SetUpUserInRole(SimpleMembershipProvider membership,SimpleRoleProvider roleProvider,string role,string userName)
        {
            var user = membership.GetUser(userName, false);

            // test if user exists and if the membership details also exist.  If not the date returned is 01/01/0001
            if (user != null && membership.GetCreateDate(userName) == default(DateTime))
            {
                membership.CreateAccount(userName, "password");

            }

            IList rolesforuser = roleProvider.GetRolesForUser(userName);

            if (!rolesforuser.Contains(role))
            {
                roleProvider.AddUsersToRoles(new[] { userName }, new[] { role });
            }
        }
 public void RegisterUser(string emailAddress, string password, string firstName, string lastName, string userType)
 {
     WebSecurity.CreateUserAndAccount(emailAddress, password, new { FirstName = firstName, LastName = lastName });
     var roleProvider = new SimpleRoleProvider(Roles.Provider);
     roleProvider.AddUsersToRoles(new string[] { emailAddress }, new string[] { userType });
 }
示例#16
0
 internal static void InitializeRoleProvider(SimpleRoleProvider simpleRoles, DatabaseConnectionInfo connect, string userTableName, string userIdColumn, string userNameColumn, bool createTables)
 {
     if (simpleRoles.InitializeCalled)
     {
         throw new InvalidOperationException(WebDataResources.Security_InitializeAlreadyCalled);
     }
     simpleRoles.ConnectionInfo = connect;
     simpleRoles.UserTableName = userTableName;
     simpleRoles.UserIdColumn = userIdColumn;
     simpleRoles.UserNameColumn = userNameColumn;
     if (createTables)
     {
         simpleRoles.CreateTablesIfNeeded();
     }
     simpleRoles.InitializeCalled = true;
 }
        /// <summary>
        /// Checks if account and role of super user needs to be setup
        /// </summary>
        /// <param name="membershipProvider">instance of the simplemembership provider</param>
        /// <param name="roleProvider">instance of the simpleroleprovider</param>
        private static void SetUpSuperUser(SimpleMembershipProvider membershipProvider, SimpleRoleProvider roleProvider)
        {
            if (membershipProvider.GetUser("admin", false) == null)
            {
                membershipProvider.CreateUserAndAccount("admin", "password");
            }

            IList rolesforuser = roleProvider.GetRolesForUser("admin");

            if (!rolesforuser.Contains("Admin"))
            {
                roleProvider.AddUsersToRoles(new[] {"admin"}, new[] {"Admin"});
            }
        }
示例#18
0
        private void AsignUserRoles(CGDataEntities.CGWebEntities webEntities)
        {
            SimpleRoleProvider provider = new SimpleRoleProvider();

            List<int> roleKeyList = _usersInRoles.Select(T => T.Value).Distinct().ToList();
            foreach (int roleKey in roleKeyList)
            {
                string roleName = _roles[roleKey];
                int[] usersInRoleIndexes = _usersInRoles.Where(kv => kv.Value.Equals(roleKey)).Select(kv => kv.Key).ToArray();
                string[] userNames = new string[usersInRoleIndexes.Count()];

                for (int i = 0; i < usersInRoleIndexes.Count(); i++)
                {
                    userNames[i] = _userProfileList[usersInRoleIndexes[i]].Username;
                }

                //wont work without HttpContext :(
                //provider.AddUsersToRoles(userNames, roleNames);
                webpages_Roles currentRole = webEntities.webpages_Roles.Where(R => R.RoleName.Equals(roleName)).Single();
                foreach (UserProfile profile in webEntities.UserProfiles.Where(UP => userNames.Contains(UP.UserName)))
                    profile.webpages_Roles.Add(currentRole);
                webEntities.SaveChanges();
            }

            log.Info("Added Roles to system.");
        }