public ActionResult CheckEMail(string value) // The name "value" is specified by the common AJAX verifier { System.Threading.Thread.Sleep(500); try { UserAccountViewRepository.GetByEMail(value); return(Json(new { Ok = false, Message = _.AuthWeb.EMailAlreadyInUse }, JsonRequestBehavior.AllowGet)); } catch (MissingResourceException) { } return(Json(new { Ok = true, Message = _.AuthWeb.EMailNotInUse, CheckedValue = value }, JsonRequestBehavior.AllowGet)); }
public ActionResult CheckUserName(string value) // The name "value" is specified by the common AJAX verifier { System.Threading.Thread.Sleep(500); if (!UserNameValidator.IsValidUserName(value)) { return(Json(new { Ok = false, Message = _.AuthWeb.InvalidUserName }, JsonRequestBehavior.AllowGet)); } try { UserAccountViewRepository.GetByUserName(value); return(Json(new { Ok = false, Message = _.AuthWeb.UserNameNotAvailable }, JsonRequestBehavior.AllowGet)); } catch (MissingResourceException) { } return(Json(new { Ok = true, Message = _.AuthWeb.UserNameAvailable, CheckedValue = value }, JsonRequestBehavior.AllowGet)); }
public ActionResult RegisterUnknownExternal(RegisterUnknownExternalModel model) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return(RedirectToHome()); } model.ProviderName = provider; model.ProviderUserId = providerUserId; model.EMail = model.ProviderEMail; if (!string.IsNullOrEmpty(model.IsRedirect)) { ModelState.Clear(); return(View(model)); } if (ModelState.IsValid) { // Attempt to register the user try { OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); UserAccountView user = UserAccountViewRepository.GetByUserName(model.UserName); //if (!string.IsNullOrEmpty(model.Password)) // user.ChangePassword(model.Password, Chimera.Authentication.Shared.UserAccounts.Configuration.Settings.GetPasswordPolicy()); //if (!string.IsNullOrEmpty(model.EMail)) // user.ChangeEMail(model.EMail); //UserRepository.Update(user); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); return(Configuration.Settings.RegisterSuccessUrl.Redirect()); } catch (DuplicateKeyException ex) { if (ex.Key == "UserName") { ModelState.AddModelError("", "User name is already in use"); } else if (ex.Key == "EMail") { ModelState.AddModelError("", "EMail is already in use"); } else if (ex.Key == "ExternalLogin") { ModelState.AddModelError("", "External login is already in use"); } else { ModelState.AddModelError("", "Unknown error"); } } catch (InvalidUserNameException) { ModelState.AddModelError("UserName", _.AuthWeb.InvalidUserName); } catch (MembershipCreateUserException ex) { ModelState.AddModelError("", ErrorCodeToString(ex.StatusCode)); } } // If we got this far, something failed, redisplay form return(View(model)); }