Exemplo n.º 1
0
        static async Task <int> Main(string[] args)
        {
            MxReturnCode <int> rc = new MxReturnCode <int>($"{Program.WebAppName} v{Program.WebAppVersion}", 1);

            rc.Init(Assembly.GetExecutingAssembly(), "*****@*****.**", null, null, null, MxMsgs.SupportedCultures);

            Console.WriteLine(rc.GetInvokeDetails());

            var config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("local.settings.json")
                         .Build();
            var conn = config?["ConnectionStrings:DefaultConnection"];  //03-12-18

            if (conn == null)
            {
                rc.SetError(2010101, MxError.Source.AppSetting, "config not built or ConnectionStrings:DefaultConnection not found");
            }
            else
            {
                using (IAdminRepo repo = new AdminRepo(conn))
                {
                    rc += await repo.GetUrdCountAsync();
                }
                if (rc.IsSuccess(true))
                {
                    Console.WriteLine($"Roles found = {rc.GetResult()}");
                    rc.SetResult(0);
                }
            }
            Console.WriteLine(rc.IsError(true) ? rc.GetErrorUserMsg() : $"Hello World!");
            Console.WriteLine(rc.IsError(true) ? rc.GetErrorTechMsg(): "no error");

            return(rc.GetResult());
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>($"{Startup.WebAppName} v{Startup.WebAppVersion}");

            rc.Init(Assembly.GetExecutingAssembly(), "*****@*****.**", null,
                    Configuration?.GetConnectionString("AzureWebJobsServiceBus"), Configuration?["MxLogMsg:AzureServiceBusQueueName"], MxMsgs.SupportedCultures);

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
                options.ConsentCookie         = new CookieBuilder
                {
                    Name        = PrivacyModel.ConsentCookieName,
                    Expiration  = new TimeSpan(PrivacyModel.ConsentCookieExpiryDays, 0, 0, 0),
                    IsEssential = true
                };  //ConsentCookie needs to be marked essential - see support 119030623000476 https://docs.microsoft.com/en-us/aspnet/core/security/gdpr?view=aspnetcore-2.2
            });

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(
                                                             Configuration.GetConnectionString("DefaultConnection")));
            services.AddDefaultIdentity <IdentityUser>()
            .AddRoles <IdentityRole>()                      //add support for roles - https://github.com/aspnet/Identity/issues/1884
            .AddDefaultUI(UIFramework.Bootstrap4)
            .AddEntityFrameworkStores <ApplicationDbContext>();

            services.Configure <IdentityOptions>(options =>
            {
                // Password settings.
                options.Password.RequireDigit           = true;
                options.Password.RequireLowercase       = true;
                options.Password.RequireNonAlphanumeric = false; //was true
                options.Password.RequireUppercase       = true;
                options.Password.RequiredLength         = 6;
                options.Password.RequiredUniqueChars    = 1;

                // Lockout settings.
                options.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromMinutes(5);
                options.Lockout.MaxFailedAccessAttempts = 5;
                options.Lockout.AllowedForNewUsers      = true;

                // User settings.
                options.User.AllowedUserNameCharacters = MxIdentityCommon.EmailAllowedChars;
                //at registration must allow same characters as for email, but when changing username restrict
                //to MxIdentityCommon.NewUsernameAllowedChars - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+";
                options.User.RequireUniqueEmail      = true; //was false
                options.SignIn.RequireConfirmedEmail = true; //added
            });

            services.AddAuthentication()
            .AddMicrosoftAccount(microsoftOptions =>
            {
                microsoftOptions.ClientId     = Configuration["Authentication:Microsoft:ClientId"];
                microsoftOptions.ClientSecret = Configuration["Authentication:Microsoft:ClientSecret"];
            })
            .AddGoogle(googleOptions =>
            {
                googleOptions.ClientId     = Configuration["Authentication:Google:ClientId"];
                googleOptions.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
            });

            services.AddMvc(options =>
            {
                options.SslPort = _isDevelopment ? 44357 : 443;
                options.Filters.Add(new RequireHttpsAttribute());
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddScoped <IMxIdentitySeedDb, MxIdentitySeedDb>();

            services.AddSingleton <IEmailSender, EmailSender>();
            services.Configure <ServiceConfig>(Configuration.GetSection("ServiceConfig"));

            var recapt = new RecaptchaOptions
            {
                SiteKey   = Configuration["ServiceConfig:reCaptchaSiteKey"] ?? "MissingRecaptchaSiteKey",
                SecretKey = Configuration["ServiceConfig:reCaptchaSecretKey"] ?? "MissingRecaptchaSecretKey"
            };

            services.AddRecaptcha(recapt);
        }