Constant magnetic field in closed string theory: An exactly solvable model