Ejemplo n.º 1
0
 public NewUser(DMIUser dmiuser)
 {
     this.firstName = (dmiuser.firstname != null) ? dmiuser.firstname : GenerateRandom.StringOfLength(5);
     this.lastName  = (dmiuser.lastname != null) ? dmiuser.lastname : GenerateRandom.StringOfLength(5);
     this.username  = (dmiuser.username != null) ? dmiuser.username : GenerateRandom.StringOfLength(5);
     this.password  = (dmiuser.password != null) ? dmiuser.password : "******";
     this.email     = (dmiuser.email != null) ? dmiuser.email : Config.Environment.Email;
 }
Ejemplo n.º 2
0
        public static async Task <DMIUser> CreateDisabledUser()
        {
            IdentityProviderUser identityProvideruser = new IdentityProviderUser();
            NewUser newuser     = NewUser.GenerateRandomUser();
            var     userCreated = await identityProvideruser.Create(newuser);

            DMIUser user = new DMIUser(userCreated, Config.Environment.ClientId);

            user.password = newuser.password;

            InsertUserIntoCTNReportDatabase(user);
            user.DisableUser();

            return(user);
        }
Ejemplo n.º 3
0
        public static async Task <DMIUser> Create(string clientId)
        {
            NewUser newuser = NewUser.GenerateRandomUser();

            IdentityProviderUser identityProvideruser = new IdentityProviderUser();
            var userCreated = await identityProvideruser.Create(newuser);

            DMIUser user = new DMIUser(userCreated, clientId);

            user.password = newuser.password;

            InsertUserIntoCTNReportDatabase(user);
            Log.MetaData($"User created with username {user.username}");
            Log.MetaData($"              and password {user.password}");
            return(user);
        }
Ejemplo n.º 4
0
        public static async Task <DMIUser> Create(NewUser newuser, string clientId)
        {
            DMIUser user = new DMIUser(clientId);
            IdentityProviderUser identityProvideruser = new IdentityProviderUser();

            var userCreated = await identityProvideruser.Create(newuser);

            user.username  = userCreated.username;
            user.firstname = userCreated.firstName;
            user.lastname  = userCreated.lastName;
            user.email     = userCreated.email;
            user.userId    = userCreated.id;

            InsertUserIntoCTNReportDatabase(user);

            return(user);
        }
Ejemplo n.º 5
0
        private static void InsertUserIntoCTNReportDatabase(DMIUser user)
        {
            SqlConnection myConnection = SQLDatabaseConnection.ConnectTo("QA-AZUKS-DMI2", "CTN_Report");

            myConnection.Open();

            //generate SQL insert statement parts
            string insertInto   = "INSERT INTO [User]";
            string columnNames  = "(UserId,FirstName,Surname,ClientId,Username,Email,GlobalAdminType,UserMustChangePasswordOnLogin,Deleted,Disabled)";
            string columnValues = $"VALUES ('{user.userId}','{user.firstname}', '{user.lastname}', '2349','{user.username}','{user.email}',0,0,0,0)";

            //construct sql statement
            string command = insertInto + columnNames + columnValues;

            SqlCommand myCommand = new SqlCommand(command, myConnection);

            myCommand.ExecuteNonQuery();
        }
Ejemplo n.º 6
0
        public static async Task <DMIUser> Create(NewUser newuser, string clientId)
        {
            try
            {
                IdentityProviderUser identityProvideruser = new IdentityProviderUser();
                var userCreated = await identityProvideruser.Create(newuser);

                DMIUser user = new DMIUser(userCreated, clientId);
                user.password = newuser.password;

                Console.WriteLine("dmiuser username is:  " + user.username);
                InsertUserIntoCTNReportDatabase(user);

                return(user);
            }
            catch (Exception)
            {
                throw Log.Exception("Unable to create dmi user login details");
            }
        }
Ejemplo n.º 7
0
        public async Task <IdentityProviderUserModel> CreateFromDmiUser(DMIUser dmiuser)
        {
            var authenticateUser = new AuthenticateIdentityProviderUser();
            var token            = authenticateUser.AuthAsync().GetAwaiter().GetResult();

            string aUser       = JsonConvert.SerializeObject(dmiuser);
            var    buffer      = System.Text.Encoding.UTF8.GetBytes(aUser);
            var    byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.ContentType            = new MediaTypeHeaderValue("application/json");
            Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token);
            Client.DefaultRequestHeaders.Add("cache-control", "no-cache");
            Client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");

            var response = await Client.PostAsync(Config.Environment.IdentityProviderUsersEndpoint, byteContent);

            //read the body
            string responseBody = await response.Content.ReadAsStringAsync();

            string body = response.Content.ToString();

            return(user = parseUser(responseBody));
        }
Ejemplo n.º 8
0
        public static void InsertRightsFor(ProductType product, UserClaimAbility userClaimAbility, DMIUser user)
        {
            string rightId = FindRightIdFor(product, userClaimAbility);
            string userId  = user.userId;

            string insertInto   = "INSERT INTO[CTN_Report].[dbo].[UserRight] ";
            string columnNames  = "(UserId, RightId) ";
            string columnValues = $"VALUES ('{userId}', '{rightId}')";

            string command = insertInto + columnNames + columnValues;

            SqlConnection myConnection = SQLDatabaseConnection.ConnectTo("QA-AZUKS-DMI2", "CTN_Report");

            myConnection.Open();

            SqlCommand sqlCommand = new SqlCommand(command, myConnection);

            sqlCommand.ExecuteNonQuery();
        }