public async Task <IActionResult> ExternalLoginCallback(string returnUrl = null) { var ip = HttpContext.Connection.RemoteIpAddress.ToString(); var loginState = _externalLoginTempService.Read(); if (loginState == null) { await _securityLogService.CreateLogEntry((User)null, null, ip, "Temp auth cookie missing on callback", SecurityLogType.ExternalAssociationCheckFailed); return(View("ExternalError", Resources.LoginBad)); } var externalLoginInfo = new ExternalLoginInfo(loginState.ProviderType.ToString(), loginState.ResultData.ID, loginState.ResultData.Name); var matchResult = await _externalUserAssociationManager.ExternalUserAssociationCheck(externalLoginInfo, ip); if (matchResult.Successful) { await _userService.Login(matchResult.User, ip); _externalLoginTempService.Remove(); await PerformSignInAsync(matchResult.User, HttpContext); return(Redirect(returnUrl)); } ViewBag.Referrer = returnUrl; return(View()); }
public async Task <ViewResult> Create(SignupData signupData) { var ip = HttpContext.Connection.RemoteIpAddress.ToString(); if (_config.UseReCaptcha) { var reCaptchaResponse = await _reCaptchaService.VerifyToken(signupData.Token, ip); if (!reCaptchaResponse.IsSuccess) { ModelState.AddModelError("Email", Resources.BotError); } } await ValidateSignupData(signupData, ModelState, ip); if (ModelState.IsValid) { var user = await _userService.CreateUser(signupData, ip); await _profileService.Create(user, signupData); // TODO: get rid of FullUrlHelper extension var verifyUrl = this.FullUrlHelper("Verify", "Account"); var result = _newAccountMailer.Send(user, verifyUrl); if (result != SmtpStatusCode.Ok) { ViewData["EmailProblem"] = Resources.EmailProblemAccount + (result?.ToString() ?? "App exception") + "."; } if (_settingsManager.Current.IsNewUserApproved) { ViewData["Result"] = Resources.AccountReady; await _userService.Login(user, ip); } else { ViewData["Result"] = Resources.AccountReadyCheckEmail; } var loginState = _externalLoginTempService.Read(); if (loginState != null) { var externalLoginInfo = new ExternalLoginInfo(loginState.ProviderType.ToString(), loginState.ResultData.ID, loginState.ResultData.Name); await _externalUserAssociationManager.Associate(user, externalLoginInfo, ip); _externalLoginTempService.Remove(); } await IdentityController.PerformSignInAsync(user, HttpContext); return(View("AccountCreated")); } SetupCreateData(); return(View(signupData)); }