public Answer UpdateRoles(string participantId, string[] sysKeys, string[] conKeys) { LongTermParticipant asLongTerm = null; if (participantId.StartsWith("LongTerm")) { asLongTerm = Session.Load <LongTermParticipant>(participantId); } var isLongTerm = asLongTerm != null; var engagement = Session .Query <ConventionEngagement>() .FirstOrDefault(x => x.ConventionId == Actor.ManagedConvention.ConventionId && x.ParticipantId == participantId); if (engagement == null) { engagement = new ConventionEngagement() { ConventionId = Actor.ManagedConvention.ConventionId, ConventionStartDate = Actor.ManagedConvention.Days .Min(x => x.Date) .ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), ParticipantId = participantId, IsLongTerm = isLongTerm }; } foreach (ConventionRoles conRole in Enum.GetValues(typeof(ConventionRoles))) { if (conKeys.Contains(conRole.ToString())) { engagement.AddRole(conRole); } else { engagement.RemoveRole(conRole); } } Session.Store(engagement); if (isLongTerm) { foreach (SystemRoles system in Enum.GetValues(typeof(SystemRoles))) { if (sysKeys.Contains(system.ToString())) { asLongTerm.AddRole(system); } else { asLongTerm.RemoveRole(system); } } } Session.SaveChanges(); return(Answer.Success); }
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)); } }
public async Task <IdentityResults.Password> UpdateParticipant(LongTermParticipant user) { var result = await _userManager.UpdateAsync(user); return(result.Succeeded ? new IdentityResults.Password() { IsSuccess = true } : new IdentityResults.Password() { IsSuccess = false, Errors = result.Errors.Select(x => x.Description).ToArray() }); }
public async Task <IdentityResults.Password> ResetPasswordAsync(LongTermParticipant user, string token, string newPassword) { var storeUser = await GetStoreUser(user); if (storeUser is null) { return new IdentityResults.Password { IsSuccess = false } } ; var result = await _userManager.ResetPasswordAsync(storeUser, token, newPassword); await _session.SaveChangesAsync(); return(ToPassword(result)); }
public async Task <IdentityResults.Password> GeneratePasswordResetTokenAsync(LongTermParticipant user) { var storeUser = await GetStoreUser(user); if (storeUser is null) { return new IdentityResults.Password { IsSuccess = false } } ; var result = await _userManager.GeneratePasswordResetTokenAsync(storeUser); await _session.SaveChangesAsync(); return(new IdentityResults.Password { IsSuccess = true, Token = result }); }
private async Task <IdentityResults.Password> AddLongTermParticipant(LongTermParticipant user, string password = "") { if ((await HasUserWithEmail(user.Email)).IsSuccess) { return new IdentityResults.Password() { IsSuccess = false, Errors = new[] { "קיים משתמש עם כתובת הדואר הזו" } } } ; if (password.IsEmptyString()) { password = new RandomPasswordGenerator(12).Generate(); } //await _session.StoreAsync(user); var createUserResult = await _userManager.CreateAsync(user, password); if (createUserResult.Succeeded == false) { return(new IdentityResults.Password { IsSuccess = false, Errors = createUserResult.Errors.Select(x => $"{x.Code}: {x.Description}").ToArray() }); } await _session.SaveChangesAsync(); return(new IdentityResults.Password() { IsLongTerm = true, IsSuccess = true, Token = password }); }
public Task <Answer> SendForgotPassword(LongTermParticipant user, string callbackUrl) { return(Task.FromResult(Answer.Success)); }
public Task <Answer> SendWelcomeMessageAsync(LongTermParticipant participant) { return(Task.FromResult(Answer.Success)); }
public Task <Answer> ResetParticipantPasswordAsync(LongTermParticipant participant, string password) { return(Task.FromResult(Answer.Success)); }
public async Task <Answer> CreateParticipant(ParticipantCreateUpdateViewModel viewmodel) { var answer = ValidateParticipantFields(viewmodel); if (answer.AnswerType != AnswerType.Success) { return(answer); } IParticipant model; ConventionEngagement engagement = new ConventionEngagement { ConventionId = Actor.ManagedConvention.ConventionId, ConventionStartDate = Actor.ManagedConvention.Days .Min(x => x.Date) .ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), Payment = new PaymentInvoice() }; if (viewmodel.Email.IsEmptyString()) { model = new ShortTermParticipant { CreatedById = Actor.Me.Id }; } else { model = new LongTermParticipant { UserName = viewmodel.Email, Email = viewmodel.Email, IsAllowingPromotions = viewmodel.IsAllowingPromotions, }; engagement.IsLongTerm = true; } model.FullName = viewmodel.FullName; model.PhoneNumber = viewmodel.PhoneNumber ?? string.Empty; model.YearOfBirth = viewmodel.YearOfBirth; var result = await Identities.AddNewParticipant(model); engagement.ParticipantId = model.Id; if (result.IsSuccess) { Session.Store(engagement); Session.SaveChanges(); } if (result.IsSuccess && result.IsLongTerm) { await Hub.SendCreationPasswordAsync(model as LongTermParticipant, result.Token); } if (result.IsSuccess == false) { return(Answer.Error(result.Errors?.AsJson())); } return(Answer.Success); }
protected async Task <LongTermParticipant?> GetStoreUser(LongTermParticipant user) { return(await GetStoreUser(user.UserName)); }