Esempio n. 1
0
        public async Task <object> GenerateToken(AuthorizeUserModel authorizeRequest)
        {
            var actualUser = await _userManager.GetUserByEmail(authorizeRequest.Email);

            await _signInManager.CheckPassword(actualUser, authorizeRequest.Password, false);


            var configuredToken = new
            {
                access_token = _tokenService.GetEncodedJwtToken(),
                userEmail    = actualUser.Email
            };

            return(configuredToken);
        }
        public AuthenticateUserValidator(IUserManager manager, ISignInManager signInManager)
        {
            var userManager = manager;

            RuleFor(x => x.Email).EmailAddress().NotEmpty().MustAsync(async(model, email, context) =>
            {
                var userResult = await userManager.GetUserByEmail(email);
                return(userResult != null);
            }).WithMessage($"Invalid email.");

            RuleFor(x => x.Password).NotEmpty().WithMessage($"Password can't be empty")
            .MustAsync(async(model, email, context) =>
            {
                var user           = await userManager.GetUserByEmail(model.Email);
                var passwordResult = await signInManager.CheckPassword(user, model.Password, false);
                return(passwordResult.Succeeded);
            }).WithMessage($"Password is incorrect");
        }