allow auto login from actual login page and some related code refactoring