/// <summary> /// Makes user account inactive, sets a new validator /// and then emails the user. /// Assume busUser.Entity is set. /// </summary> private void SetAccountForEmailValidation() { busUser.SetUserForEmailValidation(); busUser.Save(); var msg = string.Format( @"In order to validate your email address for CodePaste.net, please click or paste the following link into your browser's address bar: {0} Once you click the link you're ready to create new code pastes with your account on the CodePaste.net site. Sincerely, The CodePaste.net Team ", WebUtils.ResolveServerUrl("~/Account/ValidateEmail/" + busUser.Entity.Validator)); AppWebUtils.SendEmail("Codepaste.net Email Validation", msg, busUser.Entity.Email, true); }
public async Task <ActionResult> ExternalLinkLoginCallback() { // Handle external Login Callback var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(XsrfKey, AppUserState.UserId); if (loginInfo == null) { IdentitySignout(); // to be safe we log out return(RedirectToAction("Register", new { message = "Unable to authenticate with external login." })); } // Authenticated! string providerKey = loginInfo.Login.ProviderKey; string providerName = loginInfo.Login.LoginProvider; // Now load, create or update our custom user // normalize email and username if available if (string.IsNullOrEmpty(AppUserState.Email)) { AppUserState.Email = loginInfo.Email; } if (string.IsNullOrEmpty(AppUserState.Name)) { AppUserState.Name = loginInfo.DefaultUserName; } var userBus = new busUser(); User user = null; if (!string.IsNullOrEmpty(AppUserState.UserId)) { user = userBus.Load(AppUserState.UserId); } if (user == null && !string.IsNullOrEmpty(providerKey)) { user = userBus.LoadUserByProviderKey(providerKey); } if (user == null && !string.IsNullOrEmpty(loginInfo.Email)) { user = userBus.LoadUserByEmail(loginInfo.Email); } if (user == null) { user = userBus.NewEntity(); userBus.SetUserForEmailValidation(user); } if (string.IsNullOrEmpty(user.Email)) { user.Email = AppUserState.Email; } if (string.IsNullOrEmpty(user.Name)) { user.Name = AppUserState.Name ?? "Unknown (" + providerName + ")"; } if (loginInfo.Login != null) { user.OpenIdClaim = loginInfo.Login.ProviderKey; user.OpenId = loginInfo.Login.LoginProvider; } else { user.OpenId = null; user.OpenIdClaim = null; } // finally save user inf bool result = userBus.Save(user); // update the actual identity cookie AppUserState.FromUser(user); IdentitySignin(AppUserState, loginInfo.Login.ProviderKey); return(RedirectToAction("Register")); }
public async Task<ActionResult> ExternalLinkLoginCallback() { // Handle external Login Callback var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(XsrfKey, AppUserState.UserId); if (loginInfo == null) { IdentitySignout(); // to be safe we log out return RedirectToAction("Register", new {message = "Unable to authenticate with external login."}); } // Authenticated! string providerKey = loginInfo.Login.ProviderKey; string providerName = loginInfo.Login.LoginProvider; // Now load, create or update our custom user // normalize email and username if available if (string.IsNullOrEmpty(AppUserState.Email)) AppUserState.Email = loginInfo.Email; if (string.IsNullOrEmpty(AppUserState.Name)) AppUserState.Name = loginInfo.DefaultUserName; var userBus = new busUser(); User user = null; if (!string.IsNullOrEmpty(AppUserState.UserId)) user = userBus.Load(AppUserState.UserId); if (user == null && !string.IsNullOrEmpty(providerKey)) user = userBus.LoadUserByProviderKey(providerKey); if (user == null && !string.IsNullOrEmpty(loginInfo.Email)) user = userBus.LoadUserByEmail(loginInfo.Email); if (user == null) { user = userBus.NewEntity(); userBus.SetUserForEmailValidation(user); } if (string.IsNullOrEmpty(user.Email)) user.Email = AppUserState.Email; if (string.IsNullOrEmpty(user.Name)) user.Name = AppUserState.Name ?? "Unknown (" + providerName + ")"; if (loginInfo.Login != null) { user.OpenIdClaim = loginInfo.Login.ProviderKey; user.OpenId = loginInfo.Login.LoginProvider; } else { user.OpenId = null; user.OpenIdClaim = null; } // finally save user inf bool result = userBus.Save(user); // update the actual identity cookie AppUserState.FromUser(user); IdentitySignin(AppUserState, loginInfo.Login.ProviderKey); return RedirectToAction("Register"); }