예제 #1
0
        public async Task <Result <ExternalLoginRegisterViewModel> > GetExternalLoginViewModel(string returnUrl)
        {
            ExternalLoginInfo externalLoginInfo = await _signInManager.GetExternalLoginInfoAsync();

            if (externalLoginInfo == null)
            {
                _logger.LogError($"Error getting external login info");
                return(Result.Fail <ExternalLoginRegisterViewModel>("failed_to_get_external_longin_info", "Failed to get external login info"));
            }

            ExternalLoginRegisterViewModel externalLoginRegisterViewModel = new ExternalLoginRegisterViewModel(
                email: externalLoginInfo.Principal.FindFirstValue(ClaimTypes.Email),
                firstName: externalLoginInfo.Principal.FindFirstValue(ClaimTypes.GivenName),
                lastName: externalLoginInfo.Principal.FindFirstValue(ClaimTypes.Surname),
                externalLoginProviderName: externalLoginInfo.LoginProvider,
                returnUrl: returnUrl);

            return(Result.Ok(externalLoginRegisterViewModel));
        }
예제 #2
0
        public async Task <IActionResult> ExternalLoginConfirmation(ExternalLoginRegisterViewModel model, string returnUrl = null)
        {
            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await _signInManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    throw new ApplicationException("Error loading external login information during confirmation.");
                }
                var user = new User {
                    UserName = model.Email, Email = model.Email, PhoneNumber = model.PhoneNumber, FullName = model.FullName
                };
                var result = await userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        //await _signInManager.SignInAsync(user, isPersistent: false);
                        //_logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
                        //这里不能直接登录,_signInManager.SignInAsync()方法并没有做登录前检查
                        //例如,当系统开启了“手机验证”、“邮箱验证”、“注册用户审核”等功能后,直接发放登录令牌会导致用户越权访问。
                        return(RedirectToLocal(Url.Action(nameof(NotAllowed))));
                    }
                }
                AddErrors(result);
            }
            //await Task.Run(()=> { });

            ViewData["ReturnUrl"] = returnUrl;
            return(View(nameof(ExternalLogin), model));
        }
예제 #3
0
 public IActionResult ExternalLoginRegister(ExternalLoginRegisterViewModel model)
 {
     //_accountService.
     return(View());
 }