public async Task <IActionResult> AcceptInvite([FromBody] AcceptInviteRequest request) { var currentUser = await _userManager.FindByNameAsync(User.Identity.Name); if (!ModelState.IsValid) { return(BadRequest()); } var league = await _fantasyCriticService.GetLeagueByID(request.LeagueID); if (league.HasNoValue) { return(BadRequest()); } if (!currentUser.EmailConfirmed) { return(BadRequest()); } Result result = await _fantasyCriticService.AcceptInvite(league.Value, currentUser); if (result.IsFailure) { return(BadRequest(result.Error)); } return(Ok()); }
public async Task<IActionResult> AcceptInvite(AcceptInviteRequest acceptInvite) { if (!ModelState.IsValid) { return View(); } Result result = await _addUserService.AcceptInvite(acceptInvite); if (result.Failure) { ModelState.AddErrors(result); return View(); } return RedirectToAction(nameof(RegisterSuccess)); }
private void joinRoom(int id, OnlineGame downloadGame) { var downloadComplete = game.DownloadGame(downloadGame); Task.Run(async() => { await downloadComplete.Task; if (downloadComplete.Task.Result == false) { failure(); return; } var room = new AcceptInviteRequest(id); room.Success += u => { Schedule(() => { LoadComponentAsync(new RoomScreen(u), roomScreen => { stack.Push(roomScreen); Hide(); sideMenu.Hide(); }); game.Invitations.Remove(game.Invitations.First(i => i.ID == id)); invitationsContainer.Remove(invitationsContainer.FirstOrDefault(c => c.Invitation.ID == id)); }); }; room.Failure += ex => { failure(); }; api.Queue(room); void failure() { Schedule(() => infoOverlay.Show(@"Ocurrió un error al intentar unirse a la sala", Colour4.DarkRed)); } }); }
public async Task <Result> AcceptInvite(AcceptInviteRequest acceptInvite) { ValidationResult acceptInviteValidationResult = _acceptInviteValidator.Validate(acceptInvite); ValidationResult userAttributeValidationResult = _userAttributeRequestValidator.Validate(acceptInvite); if (!acceptInviteValidationResult.IsValid || !userAttributeValidationResult.IsValid) { _logger.LogWarning($"Invalid {nameof(AcceptInviteRequest)} model"); List <Result.ResultError> errors = ResultUtils.ToResultError(acceptInviteValidationResult.Errors); errors.AddRange(ResultUtils.ToResultError(userAttributeValidationResult.Errors)); return(Result.Fail(errors)); } BaseSpecification <InviteEntity> getInviteSpecification = new BaseSpecification <InviteEntity>(); getInviteSpecification.AddFilter(x => x.Token == acceptInvite.Code); getInviteSpecification.AddFilter(x => x.Status == Data.Enums.Entity.InviteStatuses.Pending); InviteEntity inviteEntity = _inviteRepository.SingleOrDefault(getInviteSpecification); if (inviteEntity == null) { _logger.LogError($"No Invite. Token {acceptInvite.Code}"); return(Result.Fail("no_invite", "No Invite")); } if (inviteEntity.ExpiresAt < DateTimeOffset.UtcNow) { _logger.LogError($"Invite has expired"); return(Result.Fail("no_invite", "No Invite")); } List <UserAttributeEntity> userAttributes = null; if (acceptInvite.Attributes != null) { userAttributes = acceptInvite.Attributes .Select(x => new UserAttributeEntity( key: x.Key, value: x.Value)) .ToList(); } string username; if (_identityUIEndpoints.UseEmailAsUsername) { username = inviteEntity.Email; } else { if (string.IsNullOrEmpty(acceptInvite.Username)) { _logger.LogError($"Username cannot be empty"); return(Result.Fail("username_cannot_be_empty", "username_cannot_be_empty")); } username = acceptInvite.Username; } AppUserEntity appUser = new AppUserEntity( userName: username, email: inviteEntity.Email, firstName: acceptInvite.FirstName, lastName: acceptInvite.LastName, emailConfirmed: true, enabled: true, phoneNumber: acceptInvite.PhoneNumber, attributes: userAttributes); IdentityResult identityResult = await _userManager.CreateAsync(appUser, acceptInvite.Password); if (!identityResult.Succeeded) { _logger.LogError($"Failed to create new user for invite. InviteId {inviteEntity.Id}"); return(Result.Fail(ResultUtils.ToResultError(identityResult.Errors))); } inviteEntity.Update(Data.Enums.Entity.InviteStatuses.Accepted); bool updateInvite = _inviteRepository.Update(inviteEntity); if (!updateInvite) { _logger.LogWarning($"Failed to update invite status. InnivteId {inviteEntity.Id}, UserId {appUser.Id}"); } if (inviteEntity.GroupId != null) { AddToGroup(appUser.Id, inviteEntity.GroupId, inviteEntity.GroupRoleId); } if (inviteEntity.RoleId != null) { await AddToGlobalRole(appUser, inviteEntity.RoleId); } return(Result.Ok()); }
public async Task <Result> AcceptInvite(AcceptInviteRequest acceptInvite) { ValidationResult validationResult = _acceptInviteValidator.Validate(acceptInvite); if (!validationResult.IsValid) { _logger.LogWarning($"Invalid {nameof(AcceptInviteRequest)} model"); return(Result.Fail(validationResult.Errors)); } BaseSpecification <InviteEntity> getInviteSpecification = new BaseSpecification <InviteEntity>(); getInviteSpecification.AddFilter(x => x.Token == acceptInvite.Code); getInviteSpecification.AddFilter(x => x.Status == Data.Enums.Entity.InviteStatuses.Pending); InviteEntity inviteEntity = _inviteRepository.SingleOrDefault(getInviteSpecification); if (inviteEntity == null) { _logger.LogError($"No Invite. Token {acceptInvite.Code}"); return(Result.Fail("no_invite", "No Invite")); } if (inviteEntity.ExpiresAt < DateTimeOffset.UtcNow) { _logger.LogError($"Invite has expired"); return(Result.Fail("no_invite", "No Invite")); } AppUserEntity appUser = new AppUserEntity( userName: inviteEntity.Email, email: inviteEntity.Email, firstName: acceptInvite.FirstName, lastName: acceptInvite.LastName, emailConfirmed: true, enabled: true); IdentityResult identityResult = await _userManager.CreateAsync(appUser, acceptInvite.Password); if (!identityResult.Succeeded) { _logger.LogError($"Failed to create new user for invite. InviteId {inviteEntity.Id}"); return(Result.Fail(ResultUtils.ToResultError(identityResult.Errors))); } inviteEntity.Update(Data.Enums.Entity.InviteStatuses.Accepted); bool updateInvite = _inviteRepository.Update(inviteEntity); if (!updateInvite) { _logger.LogWarning($"Failed to update invite status. InnivteId {inviteEntity.Id}, UserId {appUser.Id}"); } if (inviteEntity.GroupId != null) { AddToGroup(appUser.Id, inviteEntity.GroupId, inviteEntity.GroupRoleId); } if (inviteEntity.RoleId != null) { await AddToGlobalRole(appUser, inviteEntity.RoleId); } return(Result.Ok()); }
public async Task <Core.Models.Result.Result> AcceptInvite(AcceptInviteRequest acceptInvite) { ValidationResult acceptInviteValidationResult = _acceptInviteValidator.Validate(acceptInvite); if (!acceptInviteValidationResult.IsValid) { _logger.LogWarning($"Invalid {typeof(AcceptInviteRequest).Name} model"); } IBaseSpecification <InviteEntity, InviteEntity> getInviteSpecification = SpecificationBuilder .Create <InviteEntity>() .Where(x => x.Token == acceptInvite.Code) .Where(x => x.Status == Data.Enums.Entity.InviteStatuses.Pending) .Build(); InviteEntity inviteEntity = await _inviteDAO.SingleOrDefault(getInviteSpecification); if (inviteEntity == null) { _logger.LogError($"No Invite. Token {acceptInvite.Code}"); return(Core.Models.Result.Result.Fail("no_invite", "No Invite")); } if (inviteEntity.ExpiresAt < DateTimeOffset.UtcNow) { _logger.LogError($"Invite has expired"); return(Core.Models.Result.Result.Fail("no_invite", "No Invite")); } if (inviteEntity.GroupId != null) { Result groupValidResult = await _groupUserService.ValidateGroup(inviteEntity.GroupId); if (groupValidResult.Failure) { return(Result.Fail(groupValidResult).ToOldResult()); } Result groupRoleValidResult = await _groupUserService.RoleIsValid(inviteEntity.GroupRoleId); if (groupRoleValidResult.Failure) { return(Result.Fail(groupRoleValidResult).ToOldResult()); } } acceptInvite.Email = inviteEntity.Email; Result <AppUserEntity> addUserResult = await AddUser(acceptInvite, sendConfirmationMail : false, emailConfirmed : true); if (addUserResult.Failure) { return(addUserResult.ToOldResult()); } AppUserEntity appUser = addUserResult.Value; inviteEntity.Update(Data.Enums.Entity.InviteStatuses.Accepted); bool updateInvite = await _inviteDAO.Update(inviteEntity); if (!updateInvite) { _logger.LogWarning($"Failed to update invite status. InnivteId {inviteEntity.Id}, UserId {appUser.Id}"); } if (inviteEntity.GroupId != null) { Result addToGroupResult = await _groupUserService.AddUserToGroupWithoutValidation(appUser.Id, inviteEntity.GroupId, inviteEntity.GroupRoleId); } if (inviteEntity.RoleId != null) { Result addToGlobalRole = await AddToGlobalRole(appUser, inviteEntity.RoleId); } return(Core.Models.Result.Result.Ok()); }