c70f751f0a951b914adbc804d21f69426d764ea7
max
  Tue Jan 21 03:44:01 2014 -0800
change hgLogin to allow deactivating the email confirmation email viahg.conf refs #11957

diff --git src/hg/hgLogin/hgLogin.c src/hg/hgLogin/hgLogin.c
index 8f430b9..66702c7 100644
--- src/hg/hgLogin/hgLogin.c
+++ src/hg/hgLogin/hgLogin.c
@@ -75,31 +75,33 @@
     return cloneString("NULL_browserAddr");
 else
     return cloneString(cfgOption(CFG_LOGIN_BROWSER_ADDR));
 }
 
 char *mailSignature()
 /* Return the signature to be used by outbound mail or NULL. Allocd here. */
 {
 if isEmpty(cfgOption(CFG_LOGIN_MAIL_SIGNATURE))
     return cloneString("NULL_mailSignature");
 else
     return cloneString(cfgOption(CFG_LOGIN_MAIL_SIGNATURE));
 }
 
 char *mailReturnAddr()
-/* Return the return addr. to be used by outbound mail or NULL. Allocd here. */
+/* Return the return addr. to be used by outbound mail or NULL. Allocd here. 
+ * If set to "NOEMAIL" then no email will be sent and the account is activated right away.
+ * */
 {
 if isEmpty(cfgOption(CFG_LOGIN_MAIL_RETURN_ADDR))
     return cloneString("NULL_mailReturnAddr");
 else
     return cloneString(cfgOption(CFG_LOGIN_MAIL_RETURN_ADDR));
 }
 
 /* ---- password functions depend on optionally installed openssl lib ---- */
 #ifdef USE_SSL
 #include <openssl/md5.h>
 
 void cryptWikiWay(char *password, char *salt, char* result)
 /* encrypt password in mediawiki format - 
    ':B:'.$salt.':'. md5($salt.'-'.md5($password ) */
 {
@@ -338,73 +340,77 @@
 void returnToURL(int delay)
 /* delay for delay mill-seconds then return to the "returnto" URL */
 {
 char *returnURL = getReturnToURL();
 hPrintf(
     "<script  language=\"JavaScript\">\n"
     "<!-- "
     "\n"
     "window.setTimeout(afterDelay, %d);\n"
     "function afterDelay() {\n"
     "window.location =\"%s\";\n}"
     "\n//-->\n"
     "</script>", delay, returnURL);
 }
 
+static void redirectToLoginPage(char *paramStr)
+/* redirect to hgLogin page with given parameter string */
+{
+char *hgLoginHost = wikiLinkHost();
+hPrintf("<script  language=\"JavaScript\">\n"
+    "<!-- \n"
+    "window.location =\"http%s://%s/cgi-bin/hgLogin?%s\""
+    "//-->"
+    "\n"
+    "</script>", cgiAppendSForHttps(), hgLoginHost, paramStr);
+}
+    
 void  displayActMailSuccess()
 /* display Activate mail success box */
 {
 char *returnURL = getReturnToURL(); 
 hPrintf(
     "<div id=\"confirmationBox\" class=\"centeredContainer formBox\">"
     "\n"
     "<h2>%s</h2>", brwName);
 hPrintf(
     "<p id=\"confirmationMsg\" class=\"confirmationTxt\">A confirmation email has been sent to you. \n"
     "Please click the confirmation link in the email to activate your account.</p>"
     "\n"
     "<p><a href=\"%s\">Return</a></p>", returnURL);
 cartRemove(cart, "hgLogin_email");
 cartRemove(cart, "hgLogin_userName");
 }
 
 void sendActMailOut(char *email, char *subject, char *msg)
 /* send mail to email address */
 {
-char *hgLoginHost = wikiLinkHost();
 int result;
 result = mailViaPipe(email, subject, msg, returnAddr);
 
 if (result == -1)
     {
     hPrintf(
         "<h2>%s</h2>", brwName);
     hPrintf(
         "<p align=\"left\">"
         "</p>"
         "<h3>Error emailing to: %s</h3>"
         "Click <a href=hgLogin?hgLogin.do.displayAccHelpPage=1>here</a> to return.<br>", email );
     }
 else
-    {
-    hPrintf("<script  language=\"JavaScript\">\n"
-        "<!-- \n"
-        "window.location =\"http%s://%s/cgi-bin/hgLogin?hgLogin.do.displayActMailSuccess=1\""
-        "//-->"
-        "\n"
-        "</script>", cgiAppendSForHttps(), hgLoginHost);
-    }
+    redirectToLoginPage("hgLogin.do.displayActMailSuccess=1");
 }
 
 void  displayMailSuccess()
 /* display mail success confirmation box */
 {
 char *sendMailTo = cartUsualString(cart, "hgLogin_sendMailTo", "");
 hPrintf(
     "<div id=\"confirmationBox\" class=\"centeredContainer formBox\">"
     "<h2>%s</h2>", brwName);
 hPrintf(
     "<p id=\"confirmationMsg\" class=\"confirmationTxt\">All usernames on file (if any) for <B>%s</B> "
   "have been sent to that address.<BR><BR>"
     "  If <B>%s</B> is not your registered email address, you will not receive an email."
     " If you can't find the message we sent you, please contact %s for help.</p>", sendMailTo, sendMailTo, returnAddr);
 hPrintf(
@@ -1031,35 +1037,47 @@
     errMsg = cloneString("Password field cannot be blank.");
     signupPage(conn);
     return;
     }
 if (password && password2 && !sameString(password, password2))
     {
     freez(&errMsg);
     errMsg = cloneString("Passwords do not match.");
     signupPage(conn);
     return;
     }
 
 /* pass all the checks, OK to create the account now */
 char encPwd[45] = "";
 encryptNewPwd(password, encPwd, sizeof(encPwd));
+char *accActStatus = "N";
+
+if (sameWord(returnAddr, "NOEMAIL"))
+    accActStatus = "Y";
+
 sqlSafef(query,sizeof(query), "INSERT INTO gbMembers SET "
     "userName='%s',realName='%s',password='%s',email='%s', "
-    "lastUse=NOW(),accountActivated='N'",
-    user,user,encPwd,email);
+    "lastUse=NOW(),accountActivated='%s'",
+    user,user,encPwd,email,accActStatus);
 sqlUpdate(conn, query);
+
+if (sameWord(returnAddr, "NOEMAIL"))
+    {
+    redirectToLoginPage("hgLogin.do.displayLoginPage=1");
+    return;
+    }
+
 setupNewAccount(conn, email, user);
 /* send out activate code mail, and display the mail confirmation box */
 hPrintf("<h2>%s</h2>", brwName);
 hPrintf(
     "<p align=\"left\">\n"
     "</p>\n"
     "<h3>User %s successfully added.</h3>\n", user);
 cartRemove(cart, "hgLogin_email");
 cartRemove(cart, "hgLogin_email2");
 cartRemove(cart, "hgLogin_userName");
 cartRemove(cart, "user");
 cartRemove(cart, "token");
 returnToURL(150);
 }