Exemplo n.º 1
0
        public async Task <LoginResponse> Handle(LoginRequest request, CancellationToken cancellationToken)
        {
            var user = userRepo.Query().Where(a => a.EmailAddress == request.RequestModel.EmailAddress).SingleOrDefault();

            if (user == null)
            {
                throw new NotFoundException("User not found.");
            }

            if (user.PasswordHashToBase64 != CryptographyLogic.HashStringToSha256ToBase64(request.RequestModel.Password))
            {
                throw new IdentityException("Invalid credentials!");
            }

            var jwtDetail = await jwtManager.GenerateJwtDetails(new List <Claim>() { new Claim(CustomClaimTypeConstants.EmailAddress, user.EmailAddress) });

            return(new LoginResponse
            {
                ResponseModel = new JwtDetailResponseModel
                {
                    JwtDetail = jwtDetail
                }
            });
        }