Beispiel #1
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)

            { 
                 return RedirectToAction("Index", "Dashboard");
            }
            //Check to see if we can read their profile RSS feed. If not, then id is invalid. Return to page and ask again.
            try
            {
                ParsedFeed profilecheck = new ParsedFeed(model.CustomerID);
            }
            catch
            {
                ViewBag.Error = "There is a problem with that Amazon Profile ID. Please check and try again.";
                ViewBag.ReturnUrl = returnUrl;
                return View(model);
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new ApplicationUser { UserName = model.CustomerID, Email = model.Email, CustomerID = model.CustomerID };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await UserManager.AddToRoleAsync(user.Id, "customer");

                        //We're not logging in customer until they verify email
                        //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                        Customer customer = new Customer();
                        customer.Email = model.Email;
                        customer.FirstName = model.FirstName;
                        customer.LastName = model.LastName;
                        customer.CustomerID = model.CustomerID;
                        customer.LastReviewCheck = DateTime.Now;
                        customer.JoinDate = DateTime.Now;
                        customer.Qualified = true;
                        db.Customers.Add(customer);
                        db.SaveChanges();

                        string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                        var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

                        var response = SendEmailConfirmation(user.Email, callbackUrl, false);

                        // Uncomment to debug locally 
                        // TempData["ViewBagLink"] = callbackUrl;



                        return RedirectToAction("Welcome", "Dashboard", new { message = "confirmmail" });

                        //return RedirectToAction("Welcome", "Dashboard");

                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }