Пример #1
0
        public static bool Authenticate(User user)
        {
            MongoDatabaseService db = null;
            User entity = null;
            bool authorized = false;

            if (!String.IsNullOrWhiteSpace(user.email) && !String.IsNullOrWhiteSpace(user.userid))
            {
                db = new MongoDatabaseService();
                entity = db.Retrieve<User>(new QueryDocument("userid", user.userid)).FirstOrDefault();

                if (entity != null)
                {
                    authorized = true;
                }
                else
                {
                    // create user account
                    if (db.Create<User>(user) != null)
                    {
                        authorized = true;
                    }
                }
            }

            return authorized;
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <User> userManager, RoleManager <Role> roleManager, MongoDatabaseService mongoDatabaseService)
        {
            new MongoDataInitializer(mongoDatabaseService).SeedData();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            if (!env.IsDevelopment())
            {
                app.UseSpaStaticFiles();
            }

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

            app.UseRouting();

            app.UseCors("AllowAll");

            app.UseAuthentication();
            IdentityDataInitializer.SeedData(userManager, roleManager);
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");
            });

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
Пример #3
0
 public ActionsController(MongoDatabaseService dbService, UserManager <User> userManager)
 {
     _dbService   = dbService;
     _userManager = userManager;
 }
Пример #4
0
 public MongoDataInitializer(MongoDatabaseService dbService)
 {
     _dbService = dbService;
 }
Пример #5
0
 public ItemsController(MongoDatabaseService dbService)
 {
     _dbService = dbService;
 }
Пример #6
0
 public UpdateController()
 {
     db = new MongoDatabaseService();
 }
Пример #7
0
 public UserController()
 {
     MongoDatabaseService = new MongoDatabaseService();
 }
Пример #8
0
 public SensorsController(MongoDatabaseService dbService)
 {
     _dbService = dbService;
 }