Ejemplo n.º 1
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalRegisterModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
                return RedirectToAction("Index", "Profile");

            if (!ModelState.IsValid)
            {
                ViewBag.ReturnUrl = returnUrl;
                return View(model);
            }

            // 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 User
            {
                UserName = model.Email,
                Name = model.Name,
                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);
                    CreateSamples(user);

                    ExceptionlessClient.Default
                        .CreateFeatureUsage("Register User")
                        .AddObject(user)
                        .Submit();
                    
                    return RedirectToLocal(returnUrl);
                }
            }

            AddErrors(result);

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
Ejemplo n.º 2
0
        public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
        {
            var loginInfo = await _authenticationManager.GetExternalLoginInfoAsync();
            if (loginInfo == null)
                return RedirectToAction("Login");

            // Sign in the user with this external login provider if the user already has a login
            var result = await _signInManager.ExternalSignInAsync(loginInfo, isPersistent: false);
            switch (result)
            {
                case SignInStatus.Success:
                    return RedirectToLocal(returnUrl);
                //case SignInStatus.LockedOut:
                //    return View("Lockout");
                //case SignInStatus.RequiresVerification:
                //    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false });
                case SignInStatus.Failure:
                default:
                    // If the user does not have an account, then prompt the user to create an account
                    ViewBag.ReturnUrl = returnUrl;
                    ViewBag.LoginProvider = loginInfo.Login.LoginProvider;

                    var model = new ExternalRegisterModel()
                    {
                        Name = loginInfo.DefaultUserName,
                        Email = loginInfo.Email
                    };
                    
                    return View("ExternalLoginConfirmation", model);
            }
        }