public ActionResult CreateAccount(AppUser model) { ViewBag.backLink = "Login"; model.UserName = model.Email; var validator = new AppUserValid(); var errors = validator.Validate(model); if (errors.IsValid) { model.UserName = model.Email; model.PasswordHash = HashFunctions.HashPassword(model.Password); using (var userManager = HttpContext.GetOwinContext().GetUserManager <AppUserManager>()) { var authManager = HttpContext.GetOwinContext().Authentication; var ident = userManager.Create(model); if (ident.Errors.Count() > 0) { if (((string[])ident.Errors)[0].Contains("is already taken")) { dynamic errorMessage = new { param1 = "UserName", param2 = "Account already exists." }; HttpContext.Response.StatusCode = (int)HttpStatusCode.NotAcceptable; return(Json(errorMessage, JsonRequestBehavior.AllowGet)); } } } } else { //Dictionary<String, String> err_list = GetModelErrors.GetErrors(ModelState); } return(View(model)); }
public AspNetUser(UserDetailJson detailJson) { UserName = detailJson.email; Email = detailJson.email; FirstName = detailJson.FirstName; LastName = detailJson.LastName; DisplayName = detailJson.Name; PhoneNumber = detailJson.Phone; PrefEmail = (detailJson.PrefEmail == 1) ? true: false; PrefText = (detailJson.PrefText == 1) ? true : false; CreateDate = DateTime.Now; PasswordHash = HashFunctions.HashPassword(detailJson.Password); SecurityStamp = Guid.NewGuid().ToString("D"); }