示例#1
0
        public void CreateMany(string userNamePrefix, int usernameSuffix, int teamId, string password, int port, string userGroupName, string userNames, bool disablepwchange, bool pwneverexpires)
        {
            GroupPrincipal group = GroupPrincipal.FindByIdentity(context, userGroupName);

                string[] studentNames = userNames.Replace(Environment.NewLine, "").Split(',').Select(x => x.Trim()).ToArray();
                string usernamePrefix = userNamePrefix.Replace(" ", "");
                string username = usernamePrefix + usernameSuffix;
                string description = "Bruger oprettet med UserHelper";
                string physicalPath = "C:\\inetpub\\wwwroot\\" + username + "\\";
                try
                {
                    for (int i = 0; i < studentNames.Length; i++)
                    {
                        UserPrincipal user = new UserPrincipal(context);
                        UserManagement management = new UserManagement(user, group);
                        //Create Windows User
                        management.CreateLocalWindowsAccount(username, password, username, description, disablepwchange, pwneverexpires, user);
                        management.AddUserToGroup(group, user);
                        //Create IIS Website
                        iis.CreateWebsite(username, "DefaultAppPool", "*:" + port + ":", physicalPath);

                        //Create FTP Virtual Directory
                        //txtStatusMessages.Text += iis.CreateFTPVDir("localhost", username, physicalPath, username);
                        iis.CreateVirtualDirectory("_FTP", username, physicalPath);

                        //create databases
                        sql.CreateSQLLoginUserAndDatabase(username, username, password);

                        Credentials cred = new Credentials();
                        cred.DatabaseUserName = username;
                        cred.DatabasePassword = password;
                        cred.FTPUserName = username;
                        cred.FTPPassword = password;
                        cred.WebsitePort = port;
                        cred.WindowsUserGroupName = group.Name;

                        Student student = new Student();
                        student.Name = studentNames[i];
                        student.Team = db.Teams.Find(teamId);
                        student.Credentials = cred;
                        db.Students.Add(student);

                        //Change username and port for next iteration
                        usernameSuffix++;
                        username = usernamePrefix + usernameSuffix;
                        physicalPath = "C:\\inetpub\\wwwroot\\" + username + "\\";
                        port++;

                    }

                    db.SaveChanges();

                    BatchState.State = UserProcessState.INITIAL;
                    //done
                }
                catch (Exception)
                {
                    throw;
                }
        }
示例#2
0
        public void CreateSingleUser(string userName, string password, int port, string name, int teamId, string userGroupName, bool disablepwchange, bool pwneverexpires)
        {
            UserPrincipal user = new UserPrincipal(context);
                GroupPrincipal group = GroupPrincipal.FindByIdentity(context, userGroupName);
                Repository rep = new Repository();
                UserManagement management = new UserManagement(user, group);
                string username = userName.Replace(" ", "");
                string description = "Bruger oprettet med UserHelper";
                string physicalPath = "C:\\inetpub\\wwwroot\\" + username + "\\";
                try
                {
                    //Create Windows User
                    management.CreateLocalWindowsAccount(username, password, username, description, disablepwchange, pwneverexpires, user);
                    management.AddUserToGroup(group, user);
                    //Create IIS Website
                    iis.CreateWebsite(username, "DefaultAppPool", "*:" + port + ":", physicalPath);

                    //Create FTP Virtual Directory
                    //txtStatusMessages.Text += iis.CreateFTPVDir("localhost", username, physicalPath, username);
                    iis.CreateVirtualDirectory("_FTP", username, physicalPath);

                    //Create database for user
                    sql.CreateSQLLoginUserAndDatabase(username, username, password);

                    Credentials cred = new Credentials();
                    cred.DatabaseUserName = username;
                    cred.DatabasePassword = password;
                    cred.FTPUserName = username;
                    cred.FTPPassword = password;
                    cred.WebsitePort = port;
                    cred.WindowsUserGroupName = group.Name;
                    Student student = new Student();
                    student.Name = name;
                    sql.InsertUserWithCredentialsOnTeam(student,cred,teamId);

                    BatchState.State = UserProcessState.INITIAL;
                    //done

                }
                catch (Exception)
                {
                    RollbackOnError(BatchState.State, username);
                    throw;
                }
        }