Example #1
0
        protected static async void AddUser(IPCSOAuthContext context, string username, string password, bool isAdmin, UserManager <User> userManager)
        {
            var verifyUser = await context.Users.Where(w => w.UserName == username).FirstOrDefaultAsync();

            if (verifyUser == null)
            {
                verifyUser = new User
                {
                    UserName       = username,
                    FirstName      = username,
                    LastName       = username,
                    Email          = username,
                    CreationDate   = DateTime.Now,
                    EmailConfirmed = true,
                    Valid          = true,
                    PhoneNumber    = "55555555555555"
                };
                var result = await userManager.CreateAsync(verifyUser, password);
            }
            var isInRole = await userManager.IsInRoleAsync(verifyUser, "ROLE_USER");

            if (!isInRole)
            {
                await userManager.AddToRoleAsync(verifyUser, "ROLE_USER");
            }
            isInRole = await userManager.IsInRoleAsync(verifyUser, "ROLE_ADMIN");

            if (!isInRole)
            {
                await userManager.AddToRoleAsync(verifyUser, "ROLE_ADMIN");
            }

            await context.SaveChangesAsync();
        }
Example #2
0
        protected static async void AddRole(IPCSOAuthContext context, string roleName)
        {
            if (context.Roles.Where(w => w.Name == roleName).Count() == 0)
            {
                await context.Roles.AddAsync(new IdentityRole { Name = roleName, NormalizedName = roleName });

                await context.SaveChangesAsync();
            }
        }
Example #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              ILoggerFactory loggerFactory, IPCSOAuthContext context, UserManager <User> userManager)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddFile(Configuration.GetSection("LoggingFile"));
            loggerFactory.AddDebug();

            app.UseIdentity();
            app.UseIdentityServer();

            app.UseCors("CorsPolicy");
            app.UseMvc();
            DBInitialize.Seed(context, userManager);
        }
Example #4
0
        public static void Seed(IPCSOAuthContext context, UserManager <User> userManager)
        {
            context.Database.Migrate();
            AddRole(context, "ROLE_ADMIN");
            AddRole(context, "ROLE_USER");
#if __HPU__
            AddUser(context, "*****@*****.**", "Buildup1", true, userManager);
            AddUser(context, "*****@*****.**", "Buildup1", false, userManager);
#else
            AddUser(context, "*****@*****.**", "BuildUpAdmin123!", true, userManager);
#endif

#if DEBUG
            //AddUser(context, "*****@*****.**", userManager);
            //AddUser(context, "*****@*****.**", "Testing123!", userManager);
#endif
        }
 public RecoverPasswordRepository(IPCSOAuthContext context) : base(context)
 {
 }
Example #6
0
 public UserRepository(IPCSOAuthContext context) : base(context)
 {
 }