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; }
// 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"); } }); }
public ActionsController(MongoDatabaseService dbService, UserManager <User> userManager) { _dbService = dbService; _userManager = userManager; }
public MongoDataInitializer(MongoDatabaseService dbService) { _dbService = dbService; }
public ItemsController(MongoDatabaseService dbService) { _dbService = dbService; }
public UpdateController() { db = new MongoDatabaseService(); }
public UserController() { MongoDatabaseService = new MongoDatabaseService(); }
public SensorsController(MongoDatabaseService dbService) { _dbService = dbService; }