Beispiel #1
0
 public EditModel(ApplicationDbContext context, ImageUploader uploader, OgmaConfig config, IMapper mapper)
 {
     _context  = context;
     _uploader = uploader;
     _config   = config;
     _mapper   = mapper;
 }
Beispiel #2
0
 public FolderModel(ClubRepository clubRepo, FoldersRepository foldersRepo, OgmaConfig config, StoriesRepository storiesRepo)
 {
     _clubRepo    = clubRepo;
     _foldersRepo = foldersRepo;
     _config      = config;
     _storiesRepo = storiesRepo;
 }
Beispiel #3
0
 public DeleteModel(ApplicationDbContext context, IB2Client b2Client, IConfiguration config, OgmaConfig ogmaConfig)
 {
     _context    = context;
     _b2Client   = b2Client;
     _config     = config;
     _ogmaConfig = ogmaConfig;
 }
Beispiel #4
0
 public CreateModel(ApplicationDbContext context, ImageUploader uploader, OgmaConfig config, NotificationsRepository notificationsRepo)
 {
     _context           = context;
     _uploader          = uploader;
     _config            = config;
     _notificationsRepo = notificationsRepo;
 }
Beispiel #5
0
 public InviteCodesController(ApplicationDbContext context, OgmaUserManager userManager, OgmaConfig config, IMapper mapper)
 {
     _context     = context;
     _userManager = userManager;
     _config      = config;
     _mapper      = mapper;
 }
Beispiel #6
0
 public CommentsController(ApplicationDbContext context, OgmaConfig ogmaConfig, CommentsRepository commentsRepo, IMapper mapper)
 {
     _context      = context;
     _ogmaConfig   = ogmaConfig;
     _commentsRepo = commentsRepo;
     _mapper       = mapper;
 }
Beispiel #7
0
 public FolderModel(ApplicationDbContext context, IMapper mapper, OgmaConfig config, ClubRepository clubRepo)
 {
     _context  = context;
     _mapper   = mapper;
     _config   = config;
     _clubRepo = clubRepo;
 }
Beispiel #8
0
 public CommentsController(ApplicationDbContext context, OgmaConfig ogmaConfig, CommentsRepository commentsRepo, NotificationsRepository notificationsRepo, CommentRedirector redirector, IMapper mapper)
 {
     _context           = context;
     _ogmaConfig        = ogmaConfig;
     _commentsRepo      = commentsRepo;
     _notificationsRepo = notificationsRepo;
     _redirector        = redirector;
     _mapper            = mapper;
 }
Beispiel #9
0
 public IndexModel(
     OgmaUserManager userManager,
     SignInManager <OgmaUser> signInManager,
     IB2Client b2Client,
     ImageUploader uploader,
     OgmaConfig ogmaConfig)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _b2Client      = b2Client;
     _uploader      = uploader;
     _ogmaConfig    = ogmaConfig;
 }
Beispiel #10
0
 public Settings(OgmaConfig config)
 {
     _config = config;
 }
Beispiel #11
0
 public ConfigTestController(OgmaConfig ogmaConfig)
 {
     _ogmaConfig = ogmaConfig;
 }
Beispiel #12
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options => options.UseNpgsql(
                                                             Environment.GetEnvironmentVariable("DATABASE_URL") ?? Configuration.GetConnectionString("DbConnection")
                                                             ));
            services.AddDatabaseDeveloperPageExceptionFilter();

            // Repositories
            services.AddScoped <UserRepository>();
            services.AddScoped <ClubRepository>();
            services.AddScoped <ThreadRepository>();
            services.AddScoped <StoriesRepository>();
            services.AddScoped <TagsRepository>();
            services.AddScoped <ChaptersRepository>();
            services.AddScoped <BlogpostsRepository>();
            services.AddScoped <CommentsRepository>();
            services.AddScoped <FoldersRepository>();
            services.AddScoped <NotificationsRepository>();

            // Custom persistent config
            services.AddSingleton(OgmaConfig.Init("config.json"));

            // Routing
            services.AddRouting(options => options.LowercaseUrls = true);

            // HttpContextAccessor
            services.AddHttpContextAccessor();

            // ActionContextAccessor
            services.AddSingleton <IActionContextAccessor, ActionContextAccessor>();

            // UrlHelperFactory
            services.AddSingleton <IUrlHelperFactory, UrlHelperFactory>();

            // Identity
            services.AddIdentity <OgmaUser, OgmaRole>(config =>
            {
                config.SignIn.RequireConfirmedEmail   = true;
                config.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_ ";
                config.User.RequireUniqueEmail        = true;
            })
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddUserManager <OgmaUserManager>()
            .AddDefaultTokenProviders()
            .AddUserStore <UserStore <OgmaUser, OgmaRole, ApplicationDbContext, long, IdentityUserClaim <long>, UserRole, IdentityUserLogin <long>, IdentityUserToken <long>, IdentityRoleClaim <long> > >()
            .AddRoleStore <RoleStore <OgmaRole, ApplicationDbContext, long, UserRole, IdentityRoleClaim <long> > >();

            // Logged in user service
            services.AddTransient <IUserService, UserService>();

            // Claims
            services.AddScoped <IUserClaimsPrincipalFactory <OgmaUser>, OgmaClaimsPrincipalFactory>();
            services.AddScoped(s => s.GetService <IHttpContextAccessor>()?.HttpContext?.User);

            // Argon2 hasher
            services.UpgradePasswordSecurity().UseArgon2 <OgmaUser>();

            // Email
            services.AddTransient <IEmailSender, EmailSender>();
            services.Configure <AuthMessageSenderOptions>(Configuration);

            // Backblaze
            var b2Options = Configuration.GetSection("B2").Get <B2Options>();
            var b2Client  = new B2Client(B2Client.Authorize(b2Options));

            services.AddSingleton <IB2Client>(b2Client);

            // File uploader
            services.AddSingleton <ImageUploader>();

            // ReCaptcha
            services.Configure <RecaptchaSettings>(Configuration.GetSection("RecaptchaSettings"));
            services.AddTransient <IRecaptchaService, RecaptchaService>();

            // Seeding
            services.AddAsyncInitializer <DbSeedInitializer>();

            // Auth
            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme);

            // Auth
            services.AddAuthorization(options =>
            {
                options.AddPolicy("RequireAdminRole", policy => policy.RequireRole("Admin"));
            });


            // Cookies
            services.ConfigureApplicationCookie(options =>
            {
                options.LoginPath           = new PathString("/login");
                options.LogoutPath          = new PathString("/logout");
                options.AccessDeniedPath    = new PathString("/login");
                options.Cookie.SameSite     = SameSiteMode.Lax;
                options.Cookie.SecurePolicy = CookieSecurePolicy.Always;

                options.Events.OnRedirectToLogin =
                    HandleApiRequest(StatusCodes.Status401Unauthorized, options.Events.OnRedirectToLogin);
                options.Events.OnRedirectToAccessDenied =
                    HandleApiRequest(StatusCodes.Status403Forbidden, options.Events.OnRedirectToLogin);
            });

            // Compression
            services.AddResponseCompression();

            // Cache
            services.AddMemoryCache();

            // Automapper
            services.AddAutoMapper(typeof(AutoMapperProfile));

            // Runtime compilation
            services.AddControllersWithViews().AddRazorRuntimeCompilation();

            // Razor
            services.AddRazorPages().AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeAreaFolder("Admin", "/", "RequireAdminRole");
                options.Conventions
                .AddPageRoute("/Club/Index", "/club/{slug}-{id}")
                .AddAreaPageRoute("Identity", "/Account/Manage/ChangePassword", "/.well-known/change-password");
            });

            // MVC
            services
            .AddMvc(options =>
            {
                options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
            })
            .AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
                options.JsonSerializerOptions.IgnoreNullValues = true;
            });

            // SignalR
            services.AddSignalR();
        }
Beispiel #13
0
 public void OnGet()
 {
     Config = _config;
 }
Beispiel #14
0
 public IndexModel(ApplicationDbContext context, ClubRepository clubRepo, OgmaConfig config)
 {
     _context  = context;
     _clubRepo = clubRepo;
     _config   = config;
 }
Beispiel #15
0
 public CdnImgTagHelper(OgmaConfig ogmaConfig)
 {
     _ogmaConfig = ogmaConfig;
 }
Beispiel #16
0
 public IndexModel(ApplicationDbContext context, StoriesRepository storiesRepo, OgmaConfig config)
 {
     _context     = context;
     _storiesRepo = storiesRepo;
     _config      = config;
 }
Beispiel #17
0
 public EmailSender(IOptions <AuthMessageSenderOptions> optionsAccessor, OgmaConfig config)
 {
     _config  = config;
     _options = optionsAccessor.Value;
 }
Beispiel #18
0
 public IndexModel(ClubRepository clubRepo, OgmaConfig config)
 {
     _clubRepo = clubRepo;
     _config   = config;
 }
Beispiel #19
0
 public CreateModel(ApplicationDbContext context, ImageUploader uploader, OgmaConfig config)
 {
     _context  = context;
     _uploader = uploader;
     _config   = config;
 }
Beispiel #20
0
 public DeleteModel(ApplicationDbContext context, IB2Client b2Client, OgmaConfig config)
 {
     _context  = context;
     _b2Client = b2Client;
     _config   = config;
 }
Beispiel #21
0
 public IndexModel(ApplicationDbContext context, IMapper mapper, OgmaConfig config)
 {
     _context = context;
     _mapper  = mapper;
     _config  = config;
 }
Beispiel #22
0
 public CdnPictureTagHelper(OgmaConfig config)
 {
     _config = config;
 }