public JsonResult CreateAdminAccount(CreateAccount model)
        {
            CreateAdminAccount caa    = new CreateAdminAccount();
            string             result = caa.InsertAdminAccount(model.Admin.username, model.Admin.password, 1, model.Admin.name);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        private void RegisterAccount(CreateAdminAccount command)
        {
            ApplicationSetup.UpdateDatabaseToLatestSchema();

            var createUserResult = Users.Handle(command);

            if (!createUserResult.Succeeded)
            {
                throw new Exception(string.Join("\n", createUserResult.Errors));
            }
        }
示例#3
0
        public void ShouldFailCreatingAdminOnPersistenceError()
        {
            Assert.Throws <Exception>(() => {
                var user  = new User(0, "alexandre", "felix", false, UserType.Admin);
                var login = new Login("adfsf", "*****@*****.**", 0);

                var mockLoginrepo = new Mock <ILoginRepository>();
                mockLoginrepo.Setup(mock => mock.Create(login)).Returns(0);

                var mockUserRepo = new Mock <IUserRepository>();
                mockUserRepo.Setup(mock => mock.Create(It.IsAny <User>())).Returns(0);


                var createAdmin = new CreateAdminAccount(mockLoginrepo.Object, mockUserRepo.Object, user, "*****@*****.**", "");
                var res         = createAdmin.Execute();
            });
        }
示例#4
0
        public void ShouldFailCreatingAdminAccountOnEmptyPassword()
        {
            var ex = Assert.Throws <Exception>(() => {
                var user  = new User(0, "alexandre", "felix", false, UserType.Admin);
                var login = new Login("", "*****@*****.**", 0);

                var mockLoginrepo = new Mock <ILoginRepository>();
                mockLoginrepo.Setup(mock => mock.Create(login)).Returns(0);

                var mockUserRepo = new Mock <IUserRepository>();
                mockUserRepo.Setup(mock => mock.Create(It.IsAny <User>())).Returns(0);


                var createAdmin = new CreateAdminAccount(mockLoginrepo.Object, mockUserRepo.Object, user, "*****@*****.**", "");
                var res         = createAdmin.Execute();
            });

            Assert.AreEqual("mot de passe invalide", ex.Message);
        }
示例#5
0
        public void ShouldCreateAdminAccount()
        {
            var user  = new User(0, "alexandre", "felix", false, UserType.Admin);
            var login = new Login("admin", "*****@*****.**", 0);

            var mockLoginrepo = new Mock <ILoginRepository>();

            mockLoginrepo.Setup(mock => mock.Create(login)).Returns(0);

            var mockUserRepo = new Mock <IUserRepository>();

            mockUserRepo.Setup(mock => mock.Create(It.IsAny <User>())).Returns(0);


            var createAdmin = new CreateAdminAccount(mockLoginrepo.Object, mockUserRepo.Object, user, "*****@*****.**", "admin");
            var res         = createAdmin.Execute();

            Assert.AreEqual(0, res);
        }
示例#6
0
        public ActionResult CreateAdmin(CreateAdminAccount command)
        {
            if (ApplicationSetup.HasAdminUser())
            {
                ModelState.AddModelError("admin-already-exists", "Admin already exists");
            }

            if (!ModelState.IsValid)
            {
                return(View(command));
            }
            try {
                RegisterAccount(command);
            }
            catch (Exception e) {
                ModelState.AddModelError("exception", e);
                return(View(command));
            }

            return(RedirectToRoute("setup"));
        }
示例#7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var conn = Configuration["Database:ConnectionString"];

            services.AddHangfire(config => config.UsePostgreSqlStorage(conn));
            var secretKey = Configuration["Secret"];

            services
            .AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options => {
                options.TokenValidationParameters = new TokenValidationParameters {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuers             = new [] { "http://localhost:5001", "http://localhost:8100", "http://localhost" },
                    ValidAudiences           = new [] { "http://localhost:5001", "http://localhost:8100", "https://localhost" },
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey))
                };
            });
            services
            .AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
            services
            .AddCors(options =>
            {
                options.AddPolicy("allowMobileOrigin",
                                  builder =>
                {
                    builder.WithOrigins("http://localhost:8100", "http://localhost");
                    builder.AllowAnyHeader();
                    builder.AllowAnyMethod();
                });
            });

            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; });

            // REPOSITORIES
            var userRepo  = new UserRepository(conn);
            var loginRepo = new LoginRepository(conn);

            services.AddSingleton <IMealRepository>(ctx => new MealRepository(conn));
            services.AddSingleton <IMealBookingRepository>(ctx => new MealBookingRepository(conn));
            services.AddSingleton <IPlaceRepository>(ctx => new PlaceRepository(conn));
            services.AddSingleton <IRoomBookingRepository>(ctx => new RoomBookingRepository(conn));
            services.AddSingleton <IRoomRepository>(ctx => new RoomRepository(conn));
            services.AddSingleton <ISubscriptionRepository>(ctx => new SubscriptionRepository(conn));
            services.AddSingleton <ISubscriptionTypeRepository>(ctx => new SubscriptionTypeRepository(conn));
            services.AddSingleton <ITimeSlotRepository>(ctx => new TimeSlotRepository(conn));
            services.AddSingleton <IUserRepository>(ctx => userRepo);
            services.AddSingleton <ITicketRepository>(ctx => new TicketRepository(conn));
            services.AddSingleton <IWareRepository>(ctx => new WareRepository(conn));
            services.AddSingleton <ITicketAttributionRepository>(ctx => new TicketAttributionRepository(conn));
            services.AddSingleton <ILoginRepository>(ctx => loginRepo);
            services.AddSingleton <ITicketCommentRepository>(ctx => new TicketCommentRepository(conn));
            services.AddSingleton <ITicketWareRepository>(ctx => new TicketWareRepository(conn));
            services.AddSingleton <IWareBookingRepository>(ctx => new WareBookingRepository(conn));
            services.AddSingleton <IStaffLocationRepository>(ctx => new StaffLocationRepository(conn));
            services.AddSingleton(new AuthTokenHandler()
            {
                Secret = secretKey
            });
            services.AddSingleton <IScheduledService, ExpiredSubscriptionDeletionService>();

            //SERVICES
            services.AddSingleton <ITokenHandler, AuthTokenHandler>();

            var adminEmail    = Configuration["AdminAccount:Email"];
            var adminPassword = Configuration["AdminAccount:Password"];
            var hasAdmin      = userRepo.GetAll().Any(user => user.FirstName == "admin" && user.LastName == "admin");

            if (hasAdmin)
            {
                return;
            }
            var adminUser = new User(-1, "admin", "admin", false, UserType.Admin);
            var result    = new CreateAdminAccount(loginRepo, userRepo, adminUser, adminEmail, adminPassword);

            if (result.Execute() == -1)
            {
                throw new Exception("Impossible de creer le compte administrateur par défaut");
            }
        }