6e42d75d18cc9c8b59ba22448d4bb5412bcf2c91
chinhli
  Mon Jun 18 13:25:03 2012 -0700
Finish soft code domain name.
diff --git src/hg/hgLogin/hgLogin.c src/hg/hgLogin/hgLogin.c
index d18bf48..7cb67d2 100644
--- src/hg/hgLogin/hgLogin.c
+++ src/hg/hgLogin/hgLogin.c
@@ -1024,69 +1024,70 @@
 return;
 }
 
 boolean usingNewPassword(struct sqlConnection *conn, char *userName)
 /* The user is using  requested new password */
 {
 char query[256];
 safef(query,sizeof(query), "select passwordChangeRequired from gbMembers where userName='%s'", userName);
 char *change = sqlQuickString(conn, query);
 if (change && sameString(change, "Y"))
     return TRUE;
 else
     return FALSE;
 }
 
-char *cookieDomainName()
-/* Return the domain name to be used by the cookies or NULL. Allocd
- * here. */
-/* Return central.domain if the returnToURL is also in the same domain
- * */
-/* else return the domain in returnTo URL generated by (remote)
- * hgSession.*/
+char *getCookieDomainName()
+/* Return domain name to be used by the cookies or NULL. Allocd here.   */
+/* Return central.domain if returnToURL is also in the same domain.     */
+/* else return the domain in returnTo URL generated by remote hgSession.*/
 {
 char *centralDomain=cloneString(cfgOption(CFG_CENTRAL_DOMAIN));
 char *returnURL = getReturnToURL();
 char returnToDomain[256];
-sscanf(returnURL, "http://%[^/]", returnToDomain);
+
+/* parse the URL */
+struct netParsedUrl rtpu;
+netParseUrl(returnURL, &rtpu);
+safecpy(returnToDomain, sizeof(returnToDomain), rtpu.host);
 if (endsWith(returnToDomain,centralDomain))
     return centralDomain;
 else
     return cloneString(returnToDomain);
 }
 
 void displayLoginSuccess(char *userName, int userID)
 /* display login success msg, and set cookie */
 {
 hPrintf("<h2>UCSC Genome Browser</h2>"
     "<p align=\"left\">"
     "</p>"
     "<span style='color:red;'></span>"
     "\n");
 /* Set cookies */
-char *domainName=cookieDomainName();
+char *domainName=getCookieDomainName();
 hPrintf("<script language=\"JavaScript\">"
     " document.write(\"Login successful, setting cookies now...\");"
     "</script>\n"
     "<script language=\"JavaScript\">"
     "document.cookie =  \"wikidb_mw1_UserName=%s; domain=%s; expires=Thu, 31 Dec 2099, 20:47:11 UTC; path=/\"; "
     "\n"
     "document.cookie =  \"wikidb_mw1_UserID=%d; domain=%s; expires=Thu, 31 Dec 2099, 20:47:11 UTC; path=/\";"
     " </script>"
     "\n", userName, domainName, userID, domainName);
 cartRemove(cart,"hgLogin_userName");
-returnToURL(15);
+returnToURL(150);
 }
 
 void displayLogin(struct sqlConnection *conn)
 /* display and process login info */
 {
 struct sqlResult *sr;
 char **row;
 char query[256];
 char *userName = cartUsualString(cart, "hgLogin_userName", "");
 if (sameString(userName,""))
     {
     freez(&errMsg);
     errMsg = cloneString("User name cannot be blank.");
     displayLoginPage(conn);
     return;
@@ -1142,31 +1143,31 @@
     errMsg = cloneString("Invalid user name or password.");
     displayLoginPage(conn);
     return;
     }
 gbMembersFree(&m);
 }
 
 void  displayLogoutSuccess()
 /* display logout success msg, and reset cookie */
 {
 hPrintf("<h2>UCSC Genome Browser Sign Out</h2>"
     "<p align=\"left\">"
     "</p>"
     "<span style='color:red;'></span>"
     "\n");
-char *domainName=cookieDomainName();
+char *domainName=getCookieDomainName();
 hPrintf("<script language=\"JavaScript\">"
     "document.cookie =  \"wikidb_mw1_UserName=; domain=%s; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/\"; "
     "\n"
     "document.cookie =  \"wikidb_mw1_UserID=; domain=%s; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/\";"
     "</script>\n", domainName, domainName);
 /* return to "returnto" URL */
 returnToURL(150);
 }
 
 void doMiddle(struct cart *theCart)
 /* Write the middle parts of the HTML page.
  * This routine sets up some globals and then
  * dispatches to the appropriate page-maker. */
 {
 struct sqlConnection *conn = hConnectCentral();