public AuthenticateController(HonestProjectContext context, IConfiguration configuration, IPasswordHashUtility hashUtility, IJwtUtilities jwtUtilities)
 {
     _context          = context;
     _configuration    = configuration;
     this.hashUtility  = hashUtility;
     this.jwtUtilities = jwtUtilities;
 }
Ejemplo n.º 2
0
 public UserRepository(HonestProjectContext context, IConfiguration configuration, IPasswordHashUtility hashGenerator)
 {
     this.context       = context;
     this.configuration = configuration;
     this.hashGenerator = hashGenerator;
 }
Ejemplo n.º 3
0
 public TeamRepository(HonestProjectContext context, IConfiguration configuration)
 {
     this.context       = context;
     this.configuration = configuration;
 }
Ejemplo n.º 4
0
 public SiteRepository(HonestProjectContext context, IConfiguration config)
 {
     this.context       = context;
     this.configuration = config;
 }
Ejemplo n.º 5
0
        public static void Initialize(HonestProjectContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.Site.Any())
            {
                return;   // DB has been seeded
            }

            Site site = new Site();

            site.Name             = "Texas Legislative Council";
            site.IncludeWeekends  = false;
            site.UniqueSiteId     = "txlcis";
            site.HoursPerDay      = 8;
            site.PublicIdentifier = Guid.NewGuid();
            context.Site.Add(site);
            context.SaveChanges();

            var roles = new Role[] {
                new Role()
                {
                    PublicIdentifier = Guid.NewGuid(), Description = "Does all site administration. Has all privliges", Name = "Site Administrator"
                },
                new Role()
                {
                    PublicIdentifier = Guid.NewGuid(), Description = "Manages teams", Name = "Manager"
                },
                new Role()
                {
                    PublicIdentifier = Guid.NewGuid(), Description = "Leads teams", Name = "Team Leader"
                },
                new Role()
                {
                    PublicIdentifier = Guid.NewGuid(), Description = "A member of a team", Name = "Team Member"
                }
            };

            foreach (Role s in roles)
            {
                context.Role.Add(s);
            }
            context.SaveChanges();

            Role teamMember        = context.Role.Where(x => x.Name == "Team Member").FirstOrDefault();
            Role teamLeader        = context.Role.Where(x => x.Name == "Team Leader").FirstOrDefault();
            Role manager           = context.Role.Where(x => x.Name == "Manager").FirstOrDefault();
            Role siteAdministrator = context.Role.Where(x => x.Name == "Site Administrator").FirstOrDefault();

            PasswordHashUtility utility = new PasswordHashUtility();

            var users = new User[] {
                new User()
                {
                    Site = site, FirstName = "Colin", LastName = "Gormley", CreatedDate = DateTime.Now, PasswordHash = utility.CalculateHash("fakepassword"), EmailAddress = "[email protected]", PublicIdentifier = Guid.NewGuid(), Role = siteAdministrator
                },
                new User()
                {
                    Site = site, FirstName = "Eric", LastName = "Lavangi", CreatedDate = DateTime.Now, PasswordHash = utility.CalculateHash("fakepassword"), EmailAddress = "[email protected]", PublicIdentifier = Guid.NewGuid(), Role = teamMember
                },
                new User()
                {
                    Site = site, FirstName = "Osama", LastName = "Abdullahussein", CreatedDate = DateTime.Now, PasswordHash = utility.CalculateHash("fakepassword"), EmailAddress = "[email protected]", PublicIdentifier = Guid.NewGuid(), Role = teamMember
                },
                new User()
                {
                    Site = site, FirstName = "Kevin", LastName = "Welcht", CreatedDate = DateTime.Now, PasswordHash = utility.CalculateHash("fakepassword"), EmailAddress = "[email protected]", PublicIdentifier = Guid.NewGuid(), Role = teamMember
                },
                new User()
                {
                    Site = site, FirstName = "Rebecca", LastName = "Garcia", CreatedDate = DateTime.Now, PasswordHash = utility.CalculateHash("fakepassword"), EmailAddress = "[email protected]", PublicIdentifier = Guid.NewGuid(), Role = teamLeader
                },
                new User()
                {
                    Site = site, FirstName = "Kris", LastName = "Doer", CreatedDate = DateTime.Now, PasswordHash = utility.CalculateHash("fakepassword"), EmailAddress = "[email protected]", PublicIdentifier = Guid.NewGuid(), Role = manager
                }
            };

            foreach (User s in users)
            {
                context.User.Add(s);
            }
            context.SaveChanges();

            User leader      = context.User.Where(x => x.EmailAddress == "[email protected]").FirstOrDefault();
            User userManager = context.User.Where(x => x.EmailAddress == "[email protected]").FirstOrDefault();

            var team = new Team {
                Site = site, Name = "Picante", PublicIdentifier = Guid.NewGuid(), TeamLeader = leader, TeamManager = userManager, Description = "Responsible for everything important", TeamMembers = new System.Collections.Generic.List <User>()
            };
            User kevin = context.User.Where(x => x.EmailAddress == "[email protected]").FirstOrDefault();
            User osama = context.User.Where(x => x.EmailAddress == "[email protected]").FirstOrDefault();

            team.TeamMembers.Add(leader);
            team.TeamMembers.Add(kevin);
            team.TeamMembers.Add(osama);
            context.Team.Add(team);
            context.SaveChanges();
        }