char *edwGetEmailAndVerify() /* Get email from persona-managed cookies and validate them. * Return email address if all is good and user is logged in. * If user not logged in return NULL. If user logged in but * otherwise things are wrong abort. */ { char *email = findCookieData("email"); if (email) { char *sid = findCookieData("sid"); edwVerifySid(email, sid); } return email; }
void checkForGeoMirrorRedirect(struct cart *cart) // Implement Geo/IP based redirection. { char *thisNodeStr = geoMirrorNode(); if (thisNodeStr) // if geo-mirroring is enabled { char *redirectCookie = findCookieData("redirect"); char *redirect = cgiOptionalString("redirect"); // if we're not already redirected if (redirect == NULL && redirectCookie == NULL) { int thisNode = sqlUnsigned(thisNodeStr); struct sqlConnection *centralConn = hConnectCentral(); char *ipStr = cgiRemoteAddr(); int node = defaultNode(centralConn, ipStr); // if our node is not the node that's closest. if (thisNode != node) { char *geoSuffix = cfgOptionDefault("browser.geoSuffix",""); char query[1056]; sqlSafef(query, sizeof query, "select domain from gbNode%s where node = %d", geoSuffix, node); char *newDomain = sqlQuickString(centralConn, query); char *oldDomain = cgiServerName(); char *port = cgiServerPort(); char *uri = cgiRequestUri(); char *sep = strchr(uri, '?') ? "&" : "?"; int newUriSize = strlen(uri) + 1024; char *newUri = needMem(newUriSize); char *oldUri = needMem(newUriSize); safef(oldUri, newUriSize, "http%s://%s:%s%s%sredirect=manual&source=%s", cgiServerHttpsIsOn() ? "s" : "", oldDomain, port, uri, sep, oldDomain); safef(newUri, newUriSize, "http%s://%s:%s%s%sredirect=manual&source=%s", cgiServerHttpsIsOn() ? "s" : "", newDomain, port, uri, sep, oldDomain); printf("<TR><TD COLSPAN=3 id='redirectTd' onclick=\"javascript:document.getElementById('redirectTd').innerHTML='';\">" "<div style=\"margin: 10px 25%%; border-style:solid; border-width:thin; border-color:#97D897;\">" "<h3 style=\"background-color: #97D897; text-align: left; margin-top:0px; margin-bottom:0px;\">" " You might want to navigate to your nearest mirror - %s" "</h3> " "<ul style=\"margin:5px;\">", newDomain); printf("<li>User settings (sessions and custom tracks) <B>will differ</B> between sites." "<idiv style=\"float:right;\"><a href=\"../goldenPath/help/genomeEuro.html#sessions\">Read more.</a></idiv>"); printf("<li>Take me to <a href=\"%s\">%s</a> </li>", newUri, newDomain); printf("<li>Let me stay here <a href=\"%s\">%s</a>", oldUri, oldDomain ); printf("</div></TD></TR>\n"); exit(0); } hDisconnectCentral(¢ralConn); } } }
char *wikiLinkUserName() /* Return the user name specified in cookies from the browser, or NULL if * the user doesn't appear to be logged in. */ { if (wikiLinkEnabled()) { char *wikiUserName = findCookieData(wikiLinkUserNameCookie()); char *wikiLoggedIn = findCookieData(wikiLinkLoggedInCookie()); if (isNotEmpty(wikiLoggedIn) && isNotEmpty(wikiUserName)) { return cloneString(wikiUserName); } } else errAbort("wikiLinkUserName called when wiki is not enabled (specified " "in hg.conf)."); return NULL; }
static char *getCookieUser() /* get user from hguid cookie */ { char *user = NULL; char *centralCookie = hUserCookie(); if (centralCookie) user = findCookieData(centralCookie); return user; }
void resetVars() /* Reset vars except for position and database. */ { static char *except[] = {"db", "position", NULL}; char *cookieName = hUserCookie(); int sessionId = cgiUsualInt(cartSessionVarName(), 0); char *hguidString = findCookieData(cookieName); int userId = (hguidString == NULL ? 0 : atoi(hguidString)); struct cart *oldCart = cartNew(userId, sessionId, NULL, NULL); cartRemoveExcept(oldCart, except); cartCheckout(&oldCart); cgiVarExcludeExcept(except); }