public ActionResult Register(string id) { ViewData["IsNew"] = false; if (string.IsNullOrEmpty(id)) { id = AppUserState.UserId; } if (string.IsNullOrEmpty(id)) { busUser.NewEntity(); ViewData["IsNew"] = true; } else { if (id != AppUserState.UserId) { return(RedirectToAction("Register", new { id = "" })); } if (busUser.Load(id) == null) { return(RedirectToAction("LogOn", "Account", new { returnUrl = Url.Action("Register", "Account") })); } } return(View("Register", 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"); }