Exemplo n.º 1
0
        private static void AddUser( )
        {
            string externalAccount = null;
            bool userAlreadyExists = false;

            Console.WriteLine( "\nADD USER: "******"\n" );
            Console.WriteLine( "To add a user, you must associate the username with an external" );
            Console.WriteLine( "account on the local machine or on a domain server. To do this," );
            Console.WriteLine( "enter the username as \"DOMAIN\\USERNAME\" or as \"MACHINE\\USERNAME\"\n");
            Console.Write( "External Account: " );

            // Read in the external user account to use...
            externalAccount = Console.ReadLine( );

            Permissions permissions = new Permissions( );

            Console.WriteLine( "\nNow, permissions for this user must be set.\n" );
            Console.Write( "Allow to Create Tests [y/n]? " );
            permissions.CreateTests = ConvertResponseToBool( Console.ReadLine( ) );

            Console.Write( "Allow to Delete Tests [y/n]? " );
            permissions.DeleteTests = ConvertResponseToBool( Console.ReadLine( ) );

            Console.Write( "Allow to Modify Tests [y/n]? " );
            permissions.ModifyTests = ConvertResponseToBool( Console.ReadLine( ) );

            Console.Write( "Allow to Create Areas [y/n]? " );
            permissions.CreateAreas = ConvertResponseToBool( Console.ReadLine( ) );

            Console.Write( "Allow to Delete Areas [y/n]? " );
            permissions.DeleteAreas = ConvertResponseToBool( Console.ReadLine( ) );

            Console.Write( "Allow to Modify Areas [y/n]? " );
            permissions.ModifyAreas = ConvertResponseToBool( Console.ReadLine( ) );

            User user = new User( );
            user.PermissionSettings = permissions;
            user.ExternID = externalAccount.ToUpper( );
            user.Name = UserName.ToUpper( );

            Console.WriteLine( "\n**YOU ENTERED**" );
            PrintUserInformation( user );
            Console.Write( "\nDoes the above information look correct [y/n]?" );

            try
            {
                if ( ConvertResponseToBool( Console.ReadLine( ) ) )
                {
                    SQLDatabase dbConnection = new SQLDatabase( );
                    dbConnection.Connect( );

                    try
                    {
                        dbConnection.GetUserIDFromName( user.Name );

                        userAlreadyExists = true;
                    }
                    catch ( Exception )
                    {
                        // this is the SUCCESS case...
                    }

                    if ( userAlreadyExists )
                        throw new Exception( "User Already Exists!" );

                    dbConnection.AddUser( user );
                    dbConnection.Disconnect( );

                    Console.WriteLine( "\nTHE USER WAS ADDED SUCCESSFULLY" );
                }
                else
                {
                    Console.WriteLine( "\nPLEASE RUN THE TOOL AGAIN WITH THE PROPER INFORMATION" );
                }
            }
            catch ( Exception )
            {
                Console.WriteLine( "\nERROR: The user could not be added because the user already exists, or" );
                Console.WriteLine( "you do not have access to the sql database." );
            }
        }
Exemplo n.º 2
0
        public User()
        {
            UserName = null;
            UserID = Guid.NewGuid( ).ToString( );
            ExternalID = null;

            UserPermissions = new Permissions( );
        }