public ActionResult EmailPassword(string email) { User user = busUser.LoadUserByEmail(email); if (user == null) { // always confirm - otherwise link gets spammed ErrorDisplay.ShowMessage("We've sent password recovery info to: " + busUser.Entity.Email); } //ErrorDisplay.ShowError( // "Email address doesn't exist. Please make sure you have typed the address correctly"); else { // Always create a new random password string password = StringUtils.NewStringId(); user.Password = App.EncodePassword(password, user.Id); busUser.Save(); if (AppWebUtils.SendEmail(App.Configuration.ApplicationTitle + " Email Information", "Your CodePaste account password is: " + password + "\r\n\r\n" + "You can log on at: " + WebUtils.GetFullApplicationPath() + "\r\n\r\n" + "Please log in, view your profile and then change your password to something you can more easily remember.", busUser.Entity.Email, true)) { ErrorDisplay.ShowMessage("We've sent password recovery info to: " + busUser.Entity.Email); } else { ErrorDisplay.ShowError("Emailing of password failed."); } } return(View(ViewModel)); }
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"); }