Пример #1
0
        private static bool InitSuperAdmin(string connectionString)
        {
            Console.WriteLine("Init SuperAdmin");
            //Create Member
            string userName = "******";
            var    memCmd   = new CreateMember_C
            {
                UserName       = userName,
                RSIHandle      = "invalid_handle",
                UserType       = "SuperAdmin",
                OrganizationID = null,
                IsActive       = true
            };

            CreateMember_CH createMember_CH = new CreateMember_CH(new SQLConnectionFactory(connectionString));
            var             memResult       = createMember_CH.Handle(Globals.UserContext, memCmd);

            if (memResult.Status != System.Net.HttpStatusCode.OK)
            {
                return(false);
            }
            var memID = Convert.ToInt32(memResult.ItemIDs.FirstOrDefault());

            //Create Credential for Member
            SHA256Managed hashalgo = new SHA256Managed();

            byte[] hash         = hashalgo.ComputeHash(System.Text.Encoding.UTF8.GetBytes(userName.ToLower()));
            string passwordHash = BitConverter.ToString(hash);

            passwordHash = passwordHash.Replace("-", "");

            var credCmd = new CreateCredential_C
            {
                MemberID       = memID,
                UserName       = userName,
                PasswordHash   = passwordHash,
                OrganizationID = null
            };

            CreateCredential_CH createCredential_CH = new CreateCredential_CH(new SQLConnectionFactory(connectionString));
            var credResult = createCredential_CH.Handle(Globals.UserContext, credCmd);

            if (credResult.Status != System.Net.HttpStatusCode.OK)
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        private static bool InitOrgAdmins(string connectionString)
        {
            Console.WriteLine("Init OrgAdmins");
            foreach (var org in SetupData._organizations)
            {
                //Setup AdminUser for Each Organization
                var qry = new GetOrganizationBySpectrumID_Q
                {
                    SpectrumID = org.OrganizationSpectrumID
                };

                GetOrganizationBySpectrumID_QH getOrganizationBySpectrumID_QH = new GetOrganizationBySpectrumID_QH(new SQLConnectionFactory(connectionString));
                var organization = getOrganizationBySpectrumID_QH.Handle(Globals.AuthHandlerToken, qry);

                if (organization != null)
                {
                    //Create Member
                    string userName = organization.OrganizationSpectrumID.ToLower() + ".admin";
                    var    memCmd   = new CreateMember_C
                    {
                        UserName       = userName,
                        RSIHandle      = "invalid_handle",
                        UserType       = "Admin",
                        OrganizationID = organization.ID,
                        IsActive       = true
                    };

                    CreateMember_CH createMember_CH = new CreateMember_CH(new SQLConnectionFactory(connectionString));
                    var             memResult       = createMember_CH.Handle(Globals.UserContext, memCmd);

                    if (memResult.Status != System.Net.HttpStatusCode.OK)
                    {
                        return(false);
                    }
                    var memID = Convert.ToInt32(memResult.ItemIDs.FirstOrDefault());

                    //Create Credential for Member
                    SHA256Managed hashalgo     = new SHA256Managed();
                    byte[]        hash         = hashalgo.ComputeHash(System.Text.Encoding.UTF8.GetBytes(userName.ToLower()));
                    string        passwordHash = BitConverter.ToString(hash);
                    passwordHash = passwordHash.Replace("-", "");

                    var credCmd = new CreateCredential_C
                    {
                        MemberID       = memID,
                        UserName       = userName,
                        PasswordHash   = passwordHash,
                        OrganizationID = organization.ID
                    };

                    CreateCredential_CH createCredential_CH = new CreateCredential_CH(new SQLConnectionFactory(connectionString));
                    var credResult = createCredential_CH.Handle(Globals.UserContext, credCmd);

                    if (credResult.Status != System.Net.HttpStatusCode.OK)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }