Пример #1
0
    public async Task <Result> InviteUserByEmail(League league, string inviteEmail)
    {
        var existingInvite = await GetMatchingInvite(league, inviteEmail);

        if (existingInvite is not null)
        {
            return(Result.Failure("User is already invited to this league."));
        }

        FantasyCriticUser inviteUser = await _userManager.FindByEmailAsync(inviteEmail);

        if (inviteUser != null)
        {
            bool userInLeague = await UserIsInLeague(league, inviteUser);

            if (userInLeague)
            {
                return(Result.Failure("User is already in league."));
            }
        }

        LeagueInvite invite = new LeagueInvite(Guid.NewGuid(), league, inviteEmail);

        await _fantasyCriticRepo.SaveInvite(invite);

        return(Result.Success());
    }
        public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var user = await _userManager.FindByEmailAsync(request.EmailAddress);

            if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
            {
                return(Ok());
            }

            var code = await _userManager.GeneratePasswordResetTokenAsync(user);

            string baseURL = $"{Request.Scheme}://{Request.Host.Value}";
            await _emailSender.SendForgotPasswordEmail(user, code, baseURL);

            return(Ok());
        }
        public async Task <IActionResult> InvitePlayer([FromBody] InviteRequest 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 (league.Value.LeagueManager.UserID != currentUser.UserID)
            {
                return(Unauthorized());
            }

            foreach (var year in league.Value.Years)
            {
                var leagueYear = await _fantasyCriticService.GetLeagueYear(league.Value.LeagueID, year);

                if (leagueYear.Value.PlayStatus.PlayStarted)
                {
                    return(BadRequest("You can't add a player to a league that has already started playing"));
                }
            }

            FantasyCriticUser inviteUser = await _userManager.FindByEmailAsync(request.InviteEmail);

            if (inviteUser is null)
            {
                string baseURL = $"{Request.Scheme}://{Request.Host.Value}";
                await _emailSender.SendInviteEmail(request.InviteEmail, league.Value, baseURL);
            }

            Result result = await _fantasyCriticService.InviteUser(league.Value, request.InviteEmail);

            if (result.IsFailure)
            {
                return(BadRequest(result.Error));
            }

            return(Ok());
        }
Пример #4
0
        public async Task <IActionResult> InvitePlayer([FromBody] CreateInviteRequest 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 (league.Value.LeagueManager.UserID != currentUser.UserID)
            {
                return(Forbid());
            }

            string            baseURL = $"{Request.Scheme}://{Request.Host.Value}";
            FantasyCriticUser inviteUser;

            if (!request.IsDisplayNameInvite())
            {
                string inviteEmail = request.InviteEmail.ToLower();
                inviteUser = await _userManager.FindByEmailAsync(inviteEmail);

                if (inviteUser is null)
                {
                    Result userlessInviteResult = await _leagueMemberService.InviteUserByEmail(league.Value, inviteEmail);

                    if (userlessInviteResult.IsFailure)
                    {
                        return(BadRequest(userlessInviteResult.Error));
                    }

                    await _emailSender.SendSiteInviteEmail(inviteEmail, league.Value, baseURL);

                    return(Ok());
                }
            }
            else
            {
                inviteUser = await _userManager.FindByDisplayName(request.InviteDisplayName, request.InviteDisplayNumber.Value);
            }

            if (inviteUser is null)
            {
                return(BadRequest("No user is found with that information."));
            }

            Result userInviteResult = await _leagueMemberService.InviteUserByUserID(league.Value, inviteUser);

            if (userInviteResult.IsFailure)
            {
                return(BadRequest(userInviteResult.Error));
            }

            await _emailSender.SendLeagueInviteEmail(inviteUser.EmailAddress, league.Value, baseURL);

            return(Ok());
        }