Exemplo n.º 1
0
        public async Task <IActionResult> OnGetAsync(Guid invite)
        {
            await _signInManager.SignOutAsync();


            var emailInvite = _dbContextFactory.Find <EmailInvite>(invite);

            if (emailInvite == null)
            {
                return(NotFound($"Unable find invite."));
            }

            if (!emailInvite.IsValid)
            {
                return(BadRequest("Invite is not valid anymore. Request new invite."));
            }

            var user = await _userManager.FindByEmailAsync(emailInvite.Email);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            var hasPassword = await _userManager.HasPasswordAsync(user);

            if (hasPassword)
            {
                await _signInManager.SignInAsync(user, true);

                return(LocalRedirect(Url.Content("~/Identity/Account/Manage")));
            }

            Input.Email = emailInvite.Email;

            ModelState.SetModelValue("Email", new ValueProviderResult(Input.Email, CultureInfo.InvariantCulture));

            return(Page());
        }