Пример #1
0
    public async Task <ActionResult <SignInSecurityTokenDto> > SignInAsync([FromBody] SignInDto input)
    {
        // Act.
        TokenContext context = await _signInService.PasswordSignInAsync(input.Email, input.Password);

        // Map.
        var output = _mapper.Map <SignInSecurityTokenDto>(context);

        // Return.
        return(Ok(output));
    }
Пример #2
0
        public async Task <IActionResult> Signin(SignInModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var member = await _userService.FindByEmailAsync(model.Email);

                if (member != null)
                {
                    var result = await _signInService.PasswordSignInAsync(member, model.Password, isPersistent : false, lockoutOnFailure : true);

                    if (result.Succeeded)
                    {
                        return(LocalRedirect(returnUrl ?? Url.Action("Index", "Home", new { area = "Portal" })));
                    }
                    else if (result.IsLockedOut)
                    {
                        return(RedirectToAction(nameof(Lockout), new { returnUrl }));
                    }
                    else if (result.RequiresTwoFactor)
                    {
                        return(RedirectToAction(nameof(Signin2fa), new { returnUrl }));
                    }
                    else if (result.IsNotAllowed)
                    {
                        if (!await _userService.IsEmailConfirmedAsync(member))
                        {
                            var token = await _userService.GenerateEmailConfirmationTokenAsync(member);

                            var link = Url.Action(nameof(VerifyEmail), "Account", new { userId = member.Id, token, returnUrl }, protocol: Request.Scheme);

                            await _messageService.SendEmailAsync(
                                messageRole : MessageRole.Notification,
                                messageType : MessageType.VerifyEmail,
                                messageDisplay : "Neimart Support",
                                email : member.Email,
                                model : new ValueTuple <User, string>(member, link));

                            TempData.AddAlert(AlertMode.Alert, AlertType.Info, $"We'll send you an email within a few minutes with instructions to verify your email address. If the email does not arrive soon, check your spam, junk, and bulk mail folders.", title: "Email Verification Required");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "We couldn't sign you in. If you forgot your password, you can request for a password reset.");
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "We couldn't sign you in. If you don't have an account yet, you should create one.");
                }
            }

            return(RedirectToAction(nameof(Signin), new { returnUrl }));
        }
Пример #3
0
        public async Task <ActionResult> Authorize(string superAdminPassword)
        {
            if (string.IsNullOrEmpty(superAdminPassword))
            {
                ModelState.AddModelError("", "Password can not be empty.");

                return(View());
            }
            else
            {
                var result = await _signInService.PasswordSignInAsync(LibraryConstants.SuperAdminUserName, superAdminPassword, isPersistent : false, shouldLockout : false);

                if (result == SignInStatus.Success)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                ModelState.AddModelError("", "The provided password was incorrect.");

                return(View());
            }
        }
Пример #4
0
        public async Task <ActionResult> Login(LoginUsuarioViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await _signInService.PasswordSignInAsync(model.Usuario, model.Password, false, false);

            switch (result)
            {
            case SignInStatus.Success:
                return(RedirectToAction("Index", "Home", new { Area = "" }));

            case SignInStatus.LockedOut:
            case SignInStatus.RequiresVerification:
            case SignInStatus.Failure:
            default:
                AddMessage("Error de login, vuelva a comprobar sus datos", Infraestructura.Managers.Imp.MessageType.Error);
                return(View(model));
            }
        }