7ef1462ddbfa4d9017a98fbe460df3b0e95b25d9
chinhli
  Fri May 4 15:31:46 2012 -0700
Reuse the wiki cookies so that the existing session user can stay logged in and do not need to login to the new hgLogin system after the switch over.
diff --git src/hg/hgSession/hgSession.c src/hg/hgSession/hgSession.c
index 5e9efdc..e50edac 100644
--- src/hg/hgSession/hgSession.c
+++ src/hg/hgSession/hgSession.c
@@ -3,31 +3,30 @@
 #include "common.h"
 #include "hash.h"
 #include "htmshell.h"
 #include "cheapcgi.h"
 #include "linefile.h"
 #include "net.h"
 #include "textOut.h"
 #include "hCommon.h"
 #include "hui.h"
 #include "cart.h"
 #include "jsHelper.h"
 #include "web.h"
 #include "hdb.h"
 #include "ra.h"
 #include "wikiLink.h"
-#include "hgLoginLink.h"
 #include "customTrack.h"
 #include "customFactory.h"
 #include "hgSession.h"
 
 
 void usage()
 /* Explain usage and exit. */
 {
 errAbort(
   "hgSession - Interface with wiki login and do session saving/loading.\n"
   "usage:\n"
   "    hgSession <various CGI settings>\n"
   );
 }
 
@@ -38,115 +37,99 @@
 
 /* Javascript to confirm that the user truly wants to delete a session. */
 #define confirmDeleteFormat "return confirm('Are you sure you want to delete %s?');"
 
 char *cgiDecodeClone(char *encStr)
 /* Allocate and return a CGI-decoded copy of encStr. */
 {
 size_t len = strlen(encStr);
 char *decStr = needMem(len+1);
 cgiDecode(encStr, decStr, len);
 return decStr;
 }
 
 
 void welcomeUser(char *wikiUserName)
-/* Tell the user they are not logged in to the wiki and tell them how to
- * do so. */
+/* Tell the user they are not logged in to the wiki or other login
+ * system and tell them how to do so. */
 {
 char *wikiHost = wikiLinkHost();
 
 cartWebStart(cart, NULL, "Welcome %s", wikiUserName);
 jsInit();
+if (loginSystemEnabled())
+{
+printf("If you are not %s (on the %s at "
+       "<A HREF=\"http://%s/\" TARGET=_BLANK>%s</A>) "
+       "and would like to sign out or change identity, \n",
+       wikiUserName, loginSystemName(), wikiHost, wikiHost);
+printf("<A HREF=\"%s\"><B>click here to sign out.</B></A>\n",
+       wikiLinkUserLogoutUrl(cartSessionId(cart)));
+ 
+} else {
 printf("If you are not %s (on the wiki at "
        "<A HREF=\"http://%s/\" TARGET=_BLANK>%s</A>) "
        "and would like to sign out or change identity, \n",
        wikiUserName, wikiHost, wikiHost);
 printf("<A HREF=\"%s\"><B>click here to sign out.</B></A>\n",
        wikiLinkUserLogoutUrl(cartSessionId(cart)));
 }
+}
 
 void offerLogin()
 /* Tell the user they are not logged in to the wiki and tell them how to
  * do so. */
 {
 char *wikiHost = wikiLinkHost();
 
 cartWebStart(cart, NULL, "Sign in to UCSC Genome Bioinformatics");
 jsInit();
+if (loginSystemEnabled())
+{
+printf("Signing in enables you to save current settings into a "
+       "named session, and then restore settings from the session later.\n"
+       "If you wish, you can share named sessions with other users.\n");
+printf("<P>The sign-in page is handled by our %s system. "
+       ,loginSystemName());
+printf("<A HREF=\"%s\"><B>click here to sign in.</B></A>\n",
+       wikiLinkUserLoginUrl(cartSessionId(cart)));
+printf("To register for an account, "
+       "<A HREF=\"http://%s/cgi-bin/hgLogin?do.signupPage=1\">"
+       "<B>click here to sign up.</B></A>\n",wikiHost);
+} else {
 printf("Signing in enables you to save current settings into a "
        "named session, and then restore settings from the session later.\n"
        "If you wish, you can share named sessions with other users.\n");
 printf("<P>The sign-in page is handled by our "
        "<A HREF=\"http://%s/\" TARGET=_BLANK>wiki system</A>:\n", wikiHost);
 printf("<A HREF=\"%s\"><B>click here to sign in.</B></A>\n",
        wikiLinkUserLoginUrl(cartSessionId(cart)));
 printf("The wiki also serves as a forum for users "
        "to share knowledge and ideas.\n");
 }
-
-void welcomeGBUser(char *hgLoginUserName)
-/* Tell the user they are not logged in to the hgLogin and tell them how
- * to do so. */
-{
-char *hgLoginHost = hgLoginLinkHost();
-
-cartWebStart(cart, NULL, "Welcome %s", hgLoginUserName);
-jsInit();
-printf("If you are not %s (on the hgLogin at "
-       "<A HREF=\"http://%s/\" TARGET=_BLANK>%s</A>) "
-       "and would like to sign out or change identity, \n",
-       hgLoginUserName, hgLoginHost, hgLoginHost);
-printf("<A HREF=\"%s\"><B>click here to sign out.</B></A>\n",
-       hgLoginLinkUserLogoutUrl(cartSessionId(cart)));
-}
-
-
-void offerGBLogin()
-/* Tell the user they are not logged in to the hgLogin and tell them how
- * to do so. */
-{
-char *hgLoginHost = hgLoginLinkHost();
-char *hgLoginSysName = hgLoginLinkSysName();
-cartWebStart(cart, NULL, "Sign in to UCSC Genome Bioinformatics");
-jsInit();
-printf("Signing in enables you to save current settings into a "
-       "named session, and then restore settings from the session later.\n"
-       "If you wish, you can share named sessions with other users.\n");
-printf("<P>The sign-in page is handled by our %s system: "
-       ,hgLoginSysName);
-printf("<A HREF=\"%s\"><B>click here to sign in.</B></A>\n",
-       hgLoginLinkUserLoginUrl(cartSessionId(cart)));
-printf("To register for an account, "
-       "<A HREF=\"http://%s/cgi-bin/hgLogin?do.signupPage=1\">"
-       "<B>click here to sign up.</B></A>\n",hgLoginHost);
 }
 
 
 char *getLinkUserName()
 /* Return the user name specified in cookies from the browser, or NULL
  * if 
  * the user doesn't appear to be logged in. */
 {
-if (hgLoginLinkEnabled())
-    return cloneString(hgLoginLinkUserName());
-else     
     if (wikiLinkEnabled())
        {
        return cloneString(wikiLinkUserName());
        }
-
 return NULL;
 }
 
 void showCartLinks()
 /* Print out links to cartDump and cartReset. */
 {
 char *session = cartSidUrlString(cart);
 char returnAddress[512];
 
 safef(returnAddress, sizeof(returnAddress), "%s?%s", hgSessionName(), session);
 printf("<A HREF=\"../cgi-bin/cartReset?%s&destination=%s\">Click here to "
        "reset</A> the browser user interface settings to their defaults.\n",
        session, cgiEncodeFull(returnAddress));
 }
 
@@ -485,124 +468,85 @@
 
 printf("See the <A HREF=\"../goldenPath/help/hgSessionHelp.html\" "
        "TARGET=_BLANK>Sessions User's Guide</A> "
        "for more information about this tool.<P/>\n");
 
 showCartLinks();
 
 printf("<FORM ACTION=\"%s\" NAME=\"mainForm\" METHOD=%s "
        "ENCTYPE=\"multipart/form-data\">\n",
        hgSessionName(), formMethod);
 cartSaveSession(cart);
 
 if (isNotEmpty(userName))
     showExistingSessions(userName);
 else if (savedSessionsSupported)
-         {
-         if (hgLoginLinkEnabled())
-             {
-             printf("<P>If you <A HREF=\"%s\">sign in</A>, "
-	     "you will also have the option to save named sessions.\n",
-	     hgLoginLinkUserLoginUrl(cartSessionId(cart)));
-             } else {
              printf("<P>If you <A HREF=\"%s\">sign in</A>, "
              "you will also have the option to save named sessions.\n",
              wikiLinkUserLoginUrl(cartSessionId(cart)));
-             }
-          }
 showSavingOptions(userName);
 showLoadingOptions(userName, savedSessionsSupported);
 printf("</FORM>\n");
 }
 
 void showLinkingTemplates(char *userName)
 /* Explain how to create links to us for sharing sessions. */
 {
 struct dyString *dyUrl = dyStringNew(1024);
 webNewSection("Sharing Sessions");
 printf("There are several ways to share saved sessions with others.\n");
 printf("<UL>\n");
 if (userName != NULL)
     {
     printf("<LI>Each previously saved named session appears with "
 	   "Browser and Email links.  "
 	   "The Browser link takes you to the Genome Browser "
 	   "with that session loaded.  The resulting Genome Browser page "
 	   "can be bookmarked in your web browser and/or shared with others.  "
 	   "The Email link invokes your email tool with a message "
 	   "containing the Genome Browser link.</LI>\n");
     }
 else if (wikiLinkEnabled())
     {
-         if (hgLoginLinkEnabled())
-             {
-             printf("<LI>If you <A HREF=\"%s\">sign in</A>, you will be able "
-                    " to save named sessions which will be displayed with "
-                    " Browser and Email links.</LI>\n", 
-                    hgLoginLinkUserLoginUrl(cartSessionId(cart)));
-             } else {
              printf("<LI>If you <A HREF=\"%s\">sign in</A>, you will be able " 
                     " to save named sessions which will be displayed with "
                     " Browser and Email links.</LI>\n",
                     wikiLinkUserLoginUrl(cartSessionId(cart)));
              }
-    }
 dyStringPrintf(dyUrl, "http://%s%s", cgiServerNamePort(), cgiScriptName());
 
 printf("<LI>If you have saved your settings to a local file, you can send "
        "email to others with the file as an attachment and direct them to "
        "<A HREF=\"%s\">%s</A> .</LI>\n",
        dyUrl->string, dyUrl->string);
 dyStringPrintf(dyUrl, "?hgS_doLoadUrl=submit&hgS_loadUrlName=");
 printf("<LI>If a saved settings file is available from a web server, "
        "you can send email to others with a link such as "
        "%s<B>U</B> where <B>U</B> is the URL of your "
        "settings file, e.g. http://www.mysite.edu/~me/mySession.txt .  "
        "In this type of link, you can replace "
        "\"hgSession\" with \"hgTracks\" in order to proceed directly to "
        "the Genome Browser.</LI>\n",
        dyUrl->string);
 printf("</UL>\n");
 dyStringFree(&dyUrl);
 }
 
 void doMainPage(char *message)
 /* Login status/links and session controls. */
 {
 puts("Content-Type:text/html\n");
-if (hgLoginLinkEnabled())
-  {
-    char *hgLoginUserName = hgLoginLinkUserName();
-
-    if (hgLoginUserName)
-        welcomeGBUser(hgLoginUserName);
-    else
-        offerGBLogin();
-
-    if (isNotEmpty(message))
-        {
-        if (cartVarExists(cart, hgsDoSessionDetail))
-            webNewSection("Session Details");
-        else
-            webNewSection("Updated Session");
-        puts(message);
-        }
-    showSessionControls(hgLoginUserName, TRUE, TRUE);
-    showLinkingTemplates(hgLoginUserName);
-
-
-  } else { /* use wiki login */
 if (wikiLinkEnabled())
     {
     char *wikiUserName = wikiLinkUserName();
     if (wikiUserName)
 	welcomeUser(wikiUserName);
     else
 	offerLogin();
     if (isNotEmpty(message))
 	{
 	if (cartVarExists(cart, hgsDoSessionDetail))
 	    webNewSection("Session Details");
 	else
 	    webNewSection("Updated Session");
 	puts(message);
 	}
@@ -613,31 +557,30 @@
     {
     if (isNotEmpty(message))
 	{
 	if (cartVarExists(cart, hgsDoSessionDetail))
 	    webNewSection("Session Details");
 	else
 	    cartWebStart(cart, NULL, "Updated Session");
 	jsInit();
 	puts(message);
 	showSessionControls(NULL, FALSE, TRUE);
 	}
     else
 	showSessionControls(NULL, FALSE, FALSE);
     showLinkingTemplates(NULL);
     }
-  }
 cartWebEnd();
 }
 
 
 void cleanHgSessionFromCart(struct cart *cart)
 /* Remove hgSession action variables that should not stay in the cart. */
 {
 char varName[256];
 safef(varName, sizeof(varName), "%s%s", cgiBooleanShadowPrefix(), hgsSharePrefix);
 cartRemovePrefix(cart, varName);
 cartRemovePrefix(cart, hgsSharePrefix);
 cartRemovePrefix(cart, hgsLoadPrefix);
 cartRemovePrefix(cart, hgsLoadLocalFileName);
 cartRemovePrefix(cart, hgsDeletePrefix);
 cartRemovePrefix(cart, hgsDo);