public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    UserDetail newUserDetail = new UserDetail()
                    {
                        UserID    = user.Id,
                        FirstName = model.FirstName,
                        LastName  = model.LastName
                    };

                    StoreFrontEntities db = new StoreFrontEntities();
                    db.UserDetails.Add(newUserDetail);
                    db.SaveChanges();

                    UserManager.AddToRole(user.Id, "Customer");
                    return(RedirectToAction("Login"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //----Custom User Registration---------
                    //By default there is no reference to the database in this controller (all other objects are created using ViewModels).
                    UserDetail newUserDetail = new UserDetail();
                    newUserDetail.UserID    = user.Id;
                    newUserDetail.FirstName = model.FirstName;
                    newUserDetail.LastName  = model.LastName;

                    //Save the UserDetail object to EF and Presist/save to the database
                    StoreFrontEntities ctx = new StoreFrontEntities();
                    ctx.UserDetails.Add(newUserDetail);         //Sends to EF
                    ctx.SaveChanges();                          //Persists/save to the DB

                    UserManager.AddToRole(user.Id, "Customer"); //MVC 2 Account controller for ref



                    return(View("Login"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //var 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 this link: <a href=\"" + callbackUrl + "\">link</a>");
                    //ViewBag.Link = callbackUrl;

                    //**********USER DETAILS STEP 3 -- make sure to add using statment for DATA LAYER
                    #region dealing with custom user details
                    UserDetail newUserDeets = new UserDetail();
                    newUserDeets.UserID    = user.Id;
                    newUserDeets.FirstName = model.FirstName;
                    newUserDeets.LastName  = model.LastName;
                    newUserDeets.Address   = model.Address;
                    newUserDeets.City      = model.City;
                    newUserDeets.State     = model.State;
                    newUserDeets.Zip       = model.Zip;
                    newUserDeets.Phone     = model.Phone;

                    //newUserDeets.ResumeFile = model.ResumeFile;

                    StoreFrontEntities db = new StoreFrontEntities();
                    db.UserDetails.Add(newUserDeets);
                    db.SaveChanges();

                    #endregion

                    //var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    //UserManager.AddToRole(user.Id, "Sales");

                    //var trySignIn = await SignInManager.PasswordSignInAsync(user.UserName, model.Password, false, false);
                    return(View("Login"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //If we land here, the new ASPNetUser account has been created
                    #region Assign UserDetails during registration
                    UserDetail newUserDetails = new UserDetail();
                    newUserDetails.UserID        = user.Id;
                    newUserDetails.FirstName     = model.FirstName;
                    newUserDetails.LastName      = model.LastName;
                    newUserDetails.FavoriteMovie = model.FavoriteMovie;

                    //now save the info to the database
                    StoreFrontEntities db = new StoreFrontEntities();
                    db.UserDetails.Add(newUserDetails);
                    db.SaveChanges();
                    #endregion

                    //Send the user to the login page to log in with their new account
                    return(View("Login"));

                    //var 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 this link: <a href=\"" + callbackUrl + "\">link</a>");
                    //ViewBag.Link = callbackUrl;
                    //return View("DisplayEmail");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //var 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 this link: <a href=\"" + callbackUrl + "\">link</a>");
                    //ViewBag.Link = callbackUrl;

                    #region Custom User Details
                    UserDetail newUserDeets = new UserDetail();
                    newUserDeets.UserID        = user.Id;
                    newUserDeets.FirstName     = model.FirstName;
                    newUserDeets.LastName      = model.LastName;
                    newUserDeets.FavCategoryID = model.FavCategoryID;

                    StoreFrontEntities db = new StoreFrontEntities();
                    db.UserDetails.Add(newUserDeets);
                    db.SaveChanges();
                    #endregion

                    UserManager.AddToRole(user.Id, "Customer");

                    var trySignIn = await SignInManager.PasswordSignInAsync(user.UserName, model.Password, false, false);

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

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 6
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, "Customer");

                    UserDetail newUser = new UserDetail()
                    {
                        UserID       = user.Id,
                        CustomerName = model.FirstName + " " + model.LastName,
                    };

                    //build the instance of the database context
                    StoreFrontEntities db = new StoreFrontEntities();

                    //send object to EF
                    db.UserDetails.Add(newUser);

                    //save changes to the database
                    db.SaveChanges();

                    //have them login with their NEW credentials
                    return(RedirectToAction("Login"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }