Ejemplo n.º 1
0
 public IActionResult Index([FromServices] QuizStore store)
 {
     return(View(store.Quizzes
                 .OrderBy(f => f.Title)
                 .Where(f => f.Visible)
                 .Select(f => new QuizListModel
     {
         Id = f.Id,
         Title = f.Title,
         Enabled = f.Enabled,
         RecordsId = f.RecordsId
     })));
 }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            try
            {
                JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
                services.AddAuthentication(options =>
                {
                    options.DefaultScheme          = CookieAuthenticationDefaults.AuthenticationScheme;
                    options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
                })
                .AddCookie()
                .AddOpenIdConnect(options =>
                {
                    options.Authority            = Configuration["auth:authority"];
                    options.RequireHttpsMetadata = !env.IsDevelopment();
                    options.ClientId             = Configuration["auth:frontend:client_id"];
                    options.ClientSecret         = Configuration["auth:frontend:client_secret"];
                    foreach (var scope in Configuration["auth:frontend:scope"]?.Split(' ', StringSplitOptions.RemoveEmptyEntries) ?? new string[0])
                    {
                        options.Scope.Add(scope);
                    }
                    options.ResponseType = "code";
                    options.GetClaimsFromUserInfoEndpoint = true;
                    options.ClaimActions.MapUniqueJsonKey("memberId", "memberId");
                    options.SaveTokens = true;
                });
                services.AddControllersWithViews();
                services.AddRazorPages().AddJsonOptions(options => options.JsonSerializerOptions.Setup());

                services.AddSingleton <ITokenClient, DefaultTokenClient>();

                var healthChecksBuilder = services.AddHealthChecks();
                services.AddMessagingApi(Configuration, healthChecksBuilder);
                services.ConfigureApi <IDatabaseApi>("database", Configuration);

                services.AddTableStorage(Configuration);
                services.AddSingleton <CertificateStore>();
                var quizStore = QuizStore.init(Configuration["local_files"]);
                if (quizStore.Quizzes.Count == 0)
                {
                    Log.Logger.Error("exams.json not found. No quizzes will be available");
                }
                services.AddSingleton(quizStore);
            }
            catch (Exception e)
            {
                Log.Logger.Error(e, "Failed to setup app");
            }
        }
Ejemplo n.º 3
0
 public ExamsController(QuizStore store, CertificateStore certificateStore, ILogger <ExamsController> logger)
 {
     this.store            = store;
     this.certificateStore = certificateStore;
     this.logger           = logger;
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> CurrentRecords([FromServices] IDatabaseApi database, [FromServices] QuizStore quizStore)
        {
            var memberStr = User.FindFirst("memberId").Value;

            if (!Guid.TryParse(memberStr, out Guid memberId))
            {
                return(Forbid());
            }

            var records = await database.ListMemberRequiredTraining(memberId);

            var interesting = records.GroupJoin(
                quizStore.Quizzes,
                f => f.Course.Id,
                g => string.IsNullOrWhiteSpace(g.RecordsId) ? Guid.Empty : new Guid(g.RecordsId),
                (l, r) => l);

            return(Json(interesting));
        }