Exemplo n.º 1
0
        private JsonResult HandleGetNews(Entity[] entities)
        {
            var lists             = GetLists(entities);
            var suggestedArticles = MongoController.GetArticlesByEntities(lists.catLs, lists.dateLs);

            return(Json(new ChatResponse {
                Type = 0, Value = suggestedArticles
            }));
        }
Exemplo n.º 2
0
 public string GetLike([FromRoute] string articleId, [FromRoute] bool isPositive)
 {
     MongoController.UpdatePreferences(articleId, isPositive);
     if (isPositive)
     {
         return("Merci :)");
     }
     else
     {
         return("Nous allons mettre à jour vos préférences, désolé.");
     }
 }
Exemplo n.º 3
0
 public static void Main(string[] args)
 {
     MongoController.Initialize();
     // MongoController.PostDocument(new TestMongoModel(1111, "titlellelle"), "testColl").Wait();
     BuildWebHost(args).Run();
 }
Exemplo n.º 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.Configure <AuthOptionsConfig>(Configuration.GetSection("AuthOptions"));
            services.Configure <RedisConnectionConfig>(Configuration.GetSection("RedisConnection"));
            services.Configure <InternalApiConfig>(Configuration.GetSection("InternalApi"));

            services.AddScoped <IWorkContext, WorkContext>();
            services.AddScoped <DefaultJwtBearerEvents>();

            // Load services
            services.AddScoped <IUserService, UserService>();
            services.AddScoped <IRoomService, RoomService>();
            services.AddScoped <ITestService, TestService>();
            services.AddScoped <IMemberService, MemberService>();
            services.AddScoped <IAttemptService, AttemptService>();
            services.AddScoped <IValidationService, ValidationService>();

            services.AddSingleton <ITokenGeneratorService, TokenGeneratorService>();

            // Load repositories
            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IRoomRepository, RoomRepository>();
            services.AddScoped <ITestRepository, TestRepository>();
            services.AddScoped <IMemberRepository, MemberRepository>();
            services.AddScoped <IAttemptRepository, AttemptRepository>();

            services.AddSingleton <ICacheRepository, CacheRepository>();
            services.AddSingleton <ITokenRepository, TokenRepository>();

            services.AddCors();

            var mongoConnection = Configuration.GetSection("MongoConnection").Get <MongoConnectionConfig>();

            MongoController.ConnectToDB(
                mongoConnection.Username,
                mongoConnection.Password,
                mongoConnection.Host,
                mongoConnection.Port,
                mongoConnection.DefaultAuthDb,
                mongoConnection.Options);

            var authOptions = Configuration.GetSection("AuthOptions").Get <AuthOptionsConfig>();

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.RequireHttpsMetadata      = false;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    // укзывает, будет ли валидироваться издатель при валидации токена
                    ValidateIssuer = true,
                    // строка, представляющая издателя
                    ValidIssuer = authOptions.Issuer,

                    // будет ли валидироваться потребитель токена
                    ValidateAudience = true,
                    // установка потребителя токена
                    ValidAudience = authOptions.Audience,
                    // будет ли валидироваться время существования
                    ValidateLifetime = true,

                    // установка ключа безопасности
                    IssuerSigningKey = authOptions.SymmetricSecurityKey,
                    // валидация ключа безопасности
                    ValidateIssuerSigningKey = true,
                };
                options.EventsType = typeof(DefaultJwtBearerEvents);
            });

            services.AddMvc(options =>
            {
                options.Filters.Add(typeof(CommonAPI_ValidateModelAttribute));

                options.EnableEndpointRouting = false;
            });

            AutoMapperConfig.Initialize();
        }