public async Task <IActionResult> RemovePlayer([FromBody] PlayerRemoveRequest 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());
            }

            if (league.Value.LeagueManager.UserID == request.UserID)
            {
                return(BadRequest("Can't remove the league manager."));
            }

            var removeUser = await _userManager.FindByIdAsync(request.UserID.ToString());

            if (removeUser == null)
            {
                return(BadRequest());
            }

            var playersInLeague = await _fantasyCriticService.GetUsersInLeague(league.Value);

            bool userIsInLeague = playersInLeague.Any(x => x.UserID == removeUser.UserID);

            if (!userIsInLeague)
            {
                return(BadRequest("That user is not in that league."));
            }

            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 remove a player from a league that has already started playing"));
                }
            }

            await _fantasyCriticService.RemovePlayerFromLeague(league.Value, removeUser);

            return(Ok());
        }
Пример #2
0
    public async Task <IActionResult> OnPostAsync(string returnUrl = null)
    {
        returnUrl ??= Url.Content("~/");

        var externalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();

        GoogleLogin    = externalLogins.SingleOrDefault(x => x.Name == "Google");
        MicrosoftLogin = externalLogins.SingleOrDefault(x => x.Name == "Microsoft");
        TwitchLogin    = externalLogins.SingleOrDefault(x => x.Name == "Twitch");
        DiscordLogin   = externalLogins.SingleOrDefault(x => x.Name == "Discord");

        if (ModelState.IsValid)
        {
            var user = new FantasyCriticUser {
                Id = Guid.NewGuid(), UserName = Input.DisplayName, Email = Input.Email
            };
            var result = await _userManager.CreateAsync(user, Input.Password);

            if (result.Succeeded)
            {
                _logger.LogInformation("User created a new account with password.");

                var fullUser = await _userManager.FindByIdAsync(user.Id.ToString());

                var confirmLink = await LinkBuilder.GetConfirmEmailLink(_userManager, fullUser, Request);

                await _emailSendingService.SendConfirmationEmail(fullUser, confirmLink);

                if (_userManager.Options.SignIn.RequireConfirmedAccount)
                {
                    return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                }
                else
                {
                    await _signInManager.SignInAsync(fullUser, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }
            }
            foreach (var error in result.Errors)
            {
                ModelState.AddModelError(string.Empty, error.Description);
            }
        }

        // If we got this far, something failed, redisplay form
        return(Page());
    }
    public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
    {
        returnUrl = returnUrl ?? Url.Content("~/");
        // Get the information about the user from the external login provider
        var info = await _signInManager.GetExternalLoginInfoAsync();

        if (info == null)
        {
            ErrorMessage = "Error loading external login information during confirmation.";
            return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
        }

        if (ModelState.IsValid)
        {
            var user = new FantasyCriticUser {
                Id = Guid.NewGuid(), UserName = Input.DisplayName, Email = Input.Email
            };

            var result = await _userManager.CreateAsync(user);

            if (result.Succeeded)
            {
                var fullUser = await _userManager.FindByIdAsync(user.Id.ToString());

                result = await _userManager.AddLoginAsync(fullUser, info);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
                    var confirmLink = await LinkBuilder.GetConfirmEmailLink(_userManager, fullUser, Request);

                    await _emailSendingService.SendConfirmationEmail(fullUser, confirmLink);

                    await _signInManager.SignInAsync(fullUser, isPersistent : false, info.LoginProvider);

                    return(LocalRedirect(returnUrl));
                }
            }
            foreach (var error in result.Errors)
            {
                ModelState.AddModelError(string.Empty, error.Description);
            }
        }

        ProviderDisplayName = info.ProviderDisplayName;
        ReturnUrl           = returnUrl;
        return(Page());
    }
Пример #4
0
        public async Task <IActionResult> ResendConfirmationEmail([FromBody] AdminResendConfirmationEmail request)
        {
            var user = await _userManager.FindByIdAsync(request.UserID.ToString());

            if (user is null)
            {
                return(BadRequest());
            }

            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

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

            return(Ok());
        }
        public async Task <IActionResult> ConfirmEmail([FromBody] ConfirmEmailRequest request)
        {
            var user = await _userManager.FindByIdAsync(request.UserID);

            if (user == null)
            {
                return(BadRequest());
            }

            var result = await _userManager.ConfirmEmailAsync(user, request.Code);

            if (result.Succeeded)
            {
                return(Ok());
            }

            return(BadRequest());
        }
Пример #6
0
    protected async Task <Result <FantasyCriticUser> > GetCurrentUser()
    {
        var userID = User.Claims.SingleOrDefault(x => x.Type == "sub")?.Value;

        if (userID is null)
        {
            return(Result.Failure <FantasyCriticUser>("Can't get User ID"));
        }

        var currentUser = await _userManager.FindByIdAsync(userID);

        if (currentUser is null)
        {
            return(Result.Failure <FantasyCriticUser>("User does not exist."));
        }

        return(Result.Success(currentUser));
    }