Пример #1
0
            public async Task <LoginSystemUserQueryResponse> Handle(LoginSystemUserQuery request, CancellationToken cancellationToken)
            {
                var entity = await _context.SystemUsers.SingleOrDefaultAsync(x => x.EmailAddress == request.EmailAddress.ToLower());

                if (entity == null)
                {
                    throw new EntityNotFoundException(nameof(SystemUser), request.EmailAddress);
                }
                if (!entity.IsActive)
                {
                    throw new AuthException(nameof(SystemUser), "User account is deactivated. Please contact the system administrator.");
                }

                if (!entity.IsLocked)
                {
                    throw new AuthException(nameof(SystemUser), "User account is locked. Please contact the system administrator.");
                }

                if (!entity.IsVerified)
                {
                    throw new AuthException(nameof(SystemUser), "User account is not verified. Please verify your user account or contact the system administrator.");
                }

                if (!_passwordService.VerifyPasswordHash(request.Password, entity.PasswordHash, entity.PasswordSalt))
                {
                    throw new BadRequestException("Email address or password is incorrect.");
                }

                var vm = new LoginSystemUserQueryResponse(_jwtService.GenerateJwtToken(entity));

                return(vm);
            }