示例#1
0
        public async Task <ActionResult> RegisterAsync([Bind(Exclude = "UserPhoto")] RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                // TODO : Check file content type
                byte[] imageData = null;
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase poImgFile = Request.Files["UserPhoto"];

                    using (var binary = new BinaryReader(poImgFile.InputStream))
                    {
                        imageData = binary.ReadBytes(poImgFile.ContentLength);
                    }
                }

                var user = Mapper.Map <RegisterViewModel, ApplicationUser>(model);

                user.UserPhoto = imageData;

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");


                    // Hardcode addding of admin role
                    // TODO: DELETE
                    if (model.UserName == "admin")
                    {
                        using (var context = new DeltaDucksContext())
                        {
                            SeedData.GetRoles().ForEach(r => context.Roles.Add(r));
                            context.Commit();
                            SeedData.AsignAdminRole().ForEach(ar => context.Roles.FirstOrDefault(r => r.Name == "Admin").Users.Add(ar));
                            context.Commit();
                        }
                    }

//                    if (User.IsInRole("Admin"))
//                    {
//                        return RedirectToAction("")
//                    }


                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View("Register", model));
        }
示例#2
0
        protected void Application_Start()
        {
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new RazorViewEngine());

            GlobalConfiguration.Configure(WebApiConfig.Register);
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            DeltaDucksContext.Create();
            //Autofac Config
            Bootstrapper.Run();
        }
示例#3
0
 public DeltaDucksContext Init()
 {
     return(_dbContext ?? (_dbContext = new DeltaDucksContext()));
 }