Add redirection to referrer page after logging in, out or registering - issue #806