示例#1
0
文件: User.cs 项目: OnePlant/oneplant
        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;
 }