Example #1
0
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env,
                              IAutostartActorInitializer autostartActorInitializer,
                              DbContext dbContext,
                              IPasswordCryptoService passwordCryptoService)
        {
            app.UseCors(x => x
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials());

            app.UseMiddleware <JwtTokenMiddleware>();
            app.UseAuthentication();

            app.UseMvc();
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Bellwether api v1");
            });

            (dbContext as BellwetherContext).EnsureSeedData(passwordCryptoService);

            autostartActorInitializer.FindAndStartActors();
        }
        public UserCommandActor(IActorBootstraper actorBootstraper,
                                IPasswordCryptoService passwordCryptoService) : base(actorBootstraper)
        {
            _passwordCryptoService = passwordCryptoService;

            ReceiveAsync <RegisterUserCommand>(Handle);
        }
 public UserAuthorizationService(
     IReadOnlyUnitOfWork readOnlyUnitOfWork,
     IUnitOfWork unitOfWork,
     IPasswordCryptoService passwordCryptoService
     )
 {
     _readOnlyUnitOfWork    = readOnlyUnitOfWork;
     _passwordCryptoService = passwordCryptoService;
     _unitOfWork            = unitOfWork;
 }
 private static async void SeedUser(string name,
                                    string surname,
                                    string email,
                                    string password,
                                    UserType userType,
                                    IPasswordCryptoService passwordCryptoService,
                                    JobFinderContext JobFinderContext)
 {
     var salt         = passwordCryptoService.GenerateSalt();
     var passwordHash = passwordCryptoService.HashPassword(password, salt);
     var user         = JobFinderUser.Create(Guid.NewGuid(), name, surname, email, passwordHash, salt, userType);
     await JobFinderContext.Set <JobFinderUser>().AddAsync(user);
 }
        public static void EnsureSeedData(this JobFinderContext JobFinderContext, IPasswordCryptoService passwordCryptoService)
        {
            var JobFinderUsers = JobFinderContext.Set <JobFinderUser>();

            if (!JobFinderUsers.AnyAsync(bu => bu.UserType == UserType.Admin).Result)
            {
                SeedUser("Admin", "Admin", "*****@*****.**", "admin1234", UserType.Admin, passwordCryptoService, JobFinderContext);
            }

            if (!JobFinderUsers.AnyAsync(bu => bu.UserType == UserType.Client).Result)
            {
                SeedUser("Clinet", "Client", "*****@*****.**", "client1234", UserType.Client, passwordCryptoService, JobFinderContext);
            }

            JobFinderContext.SaveChangesAsync();
        }
Example #6
0
 public PasswordCryptoServiceTests(AutofacFixture autofac, ITestOutputHelper outputHelper)
 {
     _outputHelper          = outputHelper;
     _passwordCryptoService = autofac.Scope.Resolve <IPasswordCryptoService>();
 }