Esempio n. 1
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                if (usersManager.CreateNewUser(model.Nickname, model.Email, model.Password, this.hashManager))
                {
                    await Authnticate(users.GetFullInfoByName(model.Nickname));

                    return(RedirectToAction("Index", "Home"));
                }
                ModelState.AddModelError("", "Incorect login and (or) passwords");
            }
            return(View(model));
        }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IUserRepository users,
                              IAuthenticationRegisterService registration, IHashable hashManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseStaticFiles();
            app.UseDefaultFiles();
            app.UseAuthentication();
            app.UseFileServer();


            app.UseSignalR(route => route.MapHub <NotificationHub>("/notification"));

            var supportedCulture = new[]
            {
                new CultureInfo("en"),
                new CultureInfo("ru")
            };

            app.UseRequestLocalization(new RequestLocalizationOptions
            {
                DefaultRequestCulture = new RequestCulture("en"),
                SupportedCultures     = supportedCulture,
                SupportedUICultures   = supportedCulture
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            if (users.GetByName("Admin") == null)
            {
                registration.CreateNewUser("Admin", "*****@*****.**", "Admin", hashManager, "Admin");
            }
        }