public async Task <IActionResult> Login(AccountLoginViewModel model) { var returnModel = new AccountViewModel() { Login = model }; if (ModelState.IsValid) { var result = await Identities.LoginAsync(model.Email, model.Password, true); if (result.IsSuccess) { var cookieConsent = HttpContext.Features.Get <ITrackingConsentFeature>(); cookieConsent.GrantConsent(); return(RedirectToAction("Index", "Personal", new { area = "Participant" })); } else { SetUserError("כשלון בהתחברות ", result.Details); return(View("LoginOrRegister", returnModel)); } } else { var invalidProperty = ModelState.First(x => x.Value.ValidationState == ModelValidationState.Invalid); SetUserError("תקלה במידע שהתקבל", invalidProperty.Value.Errors.FirstOrDefault()?.ErrorMessage ?? "אנא נסו שוב"); return(View("LoginOrRegister", returnModel)); } // If we got this far, something failed, redisplay form return(View("LoginOrRegister", model)); }
public async Task <IActionResult> Register(AccountRegisterViewModel model) { var returnModel = new AccountViewModel() { Register = model }; if (ModelState.IsValid) { var participant = new LongTermParticipant { YearOfBirth = model.YearOfBirth, UserName = model.Email, FullName = model.FullName, Email = model.Email, IsAllowingPromotions = model.IsAllowingPromotions, PhoneNumber = model.PhoneNumber, }; var addResult = await Identities.AddNewParticipant(participant, model.Password); if (addResult.IsSuccess) { await Communication.SendWelcomeMessageAsync(participant); var signInResult = await Identities.LoginAsync(model.Email, model.Password, true); if (signInResult.IsSuccess) { var cookieConsent = HttpContext.Features.Get <ITrackingConsentFeature>(); cookieConsent.GrantConsent(); return(RedirectToAction("Index", "Personal", new { area = "Participant" })); } else { SetUserError("כשלון בהתחברות לאחר רישום", signInResult.Details); return(View("LoginOrRegister", returnModel)); } } else { SetUserError("תקלה ביצירת משתתף", addResult.Errors.FirstOrDefault()); return(View("LoginOrRegister", returnModel)); } } else { var invalidProperty = ModelState.First(x => x.Value.ValidationState == ModelValidationState.Invalid); SetUserError("תקלה במידע שהתקבל", invalidProperty.Value.Errors.FirstOrDefault()?.ErrorMessage ?? "אנא נסו שוב"); return(View("LoginOrRegister", returnModel)); } }