Refactor web pages to deduplicate login.

This also fixes the issue that users could login with
Facebook and Twitter, but could only enrol/connect with
Google or Yahoo.  There are also some bug fixes.

Jira issue: WP-955