d072119705aa4c302f23241ba540bde253a373ac chinhli Fri Apr 27 15:10:00 2012 -0700 Finish initial mail out function with accountHelp form. diff --git src/hg/hgLogin/hgLogin.c src/hg/hgLogin/hgLogin.c index fd05cfb..c706c62 100644 --- src/hg/hgLogin/hgLogin.c +++ src/hg/hgLogin/hgLogin.c @@ -27,30 +27,65 @@ char msg[2048] = ""; char *excludeVars[] = { "submit", "Submit", "debug", "fixMembers", "update", "hgLogin_password", "hgLogin_password2", "hgLogin_newPassword1", "hgLogin_newPassword2", NULL }; /* The excludeVars are not saved to the cart. (We also exclude * any variables that start "near.do.") */ /* ---- Global variables. ---- */ struct cart *cart; /* This holds cgi and other variables between clicks. */ char *database; /* Name of genome database - hg15, mm3, or the like. */ struct hash *oldCart; /* Old cart hash. */ char *errMsg; /* Error message to show user when form data rejected */ +/* -------- utilities functions --- */ + +void sendMail() +{ +char cmd[256]; +char email[256]="chinhli@soe.ucsc.edu"; +char msg[256]="UCSC"; +safef(cmd,sizeof(cmd), +"echo 'Hello from your favoriate browser at: %s' | mail -s \"Greeting form UCSC Genome Browser\" %s" +, msg, email); +int result = system(cmd); +if (result == -1) + { + hPrintf( + "<h2>GSID HIV Data Browser</h2>" + "<p align=\"left\">" + "</p>" + "<h3>Error emailing password to: %s</h3>" + "Click <a href=hgLogin?hgLogin.do.signupPage=1>here</a> to return.<br>" + , email + ); + } +else + { + hPrintf( + "<h2>GSID HIV Data Browser</h2>" + "<p align=\"left\">" + "</p>" + "<h3>Password has been emailed to: %s</h3>" + "Click <a href=hgLogin?hgLogin.do.signupPage=1>here</a> to return.<br>" + , email + ); + } + +} /* -------- password functions ---- */ void cryptWikiWay(char *password, char *salt, char* result) // encrypt password as mediawiki does: ':B:'.$salt.':'. md5($salt.'-'.md5($password ) { int i; unsigned char result1[MD5_DIGEST_LENGTH]; unsigned char result2[MD5_DIGEST_LENGTH]; char firstMD5[MD5_DIGEST_LENGTH*2 + 1]; char secondMD5[MD5_DIGEST_LENGTH*2 + 1]; i = MD5_DIGEST_LENGTH; // /*DEBUG*/ printf("MD5_DIGEST_LENGT is -- %d\n",i); MD5((unsigned char *) password, strlen(password), result1); // output /****************************************************** DEBUG @@ -684,64 +719,106 @@ hPrintf( "<h2>UCSC Genome Browser</h2>\n" "<p align=\"left\">\n" "</p>\n" "<h3>User %s successfully added.</h3>\n" , user ); /* TODO: cleanup the hgLogin_xxxx vars in the cart */ backToHgSession(2); } void displayAccHelpPage(struct sqlConnection *conn) /* draw the account help page */ { - +char *email = cartUsualString(cart, "hgLogin_email", ""); hPrintf( "<div id=\"accountHelpBox\" class=\"centeredContainer formBox\">" "\n" "<h2>UCSC Genome Browser</h2>" "\n" "<h3>Having trouble signing in?</h3>" "\n" "<form method=post action=\"hgLogin\" name=\"accountLoginForm\" id=\"acctHelpForm\">" "\n" +"<p><span style='color:red;'>%s</span><p>" +"\n" +, errMsg ? errMsg : "" +); +hPrintf( "<div class=\"inputGroup\">" +"<div class=\"acctHelpSection\"><input name=\"helpWith\" type=\"radio\" value=\"username\" id=\"username\" checked>" +"<label for=\"username\" class=\"radioLabel\">I forgot my <b>username</b>. Please email it to me.</label></div>" "<div class=\"acctHelpSection\"><input name=\"helpWith\" type=\"radio\" value=\"password\" id=\"password\">" -"<label for=\"password\" class=\"radioLabel\">I forgot my <b>username</b>. Please email it to me.</label></div>" -"<div class=\"acctHelpSection\"><input name=\"helpWith\" type=\"radio\" value=\"username\" id=\"userName\">" -"<label for=\"userName\" class=\"radioLabel\">I forgot my <b>password</b>. Send me a new one.</label></div>" +"<label for=\"password\" class=\"radioLabel\">I forgot my <b>password</b>. Send me a new one.</label></div>" "\n" "</div>" "\n" ); hPrintf( "<div class=\"inputGroup\">" "<label for=\"emailPassword\">Email address</label>" -"<input type=\"text\" name=\"hgLogin_email\" size=\"30\" id=\"emailPassword\">" +"<input type=\"text\" name=\"hgLogin_email\" value=\"%s\" size=\"30\" id=\"emailPassword\">" "</div>" "\n" "<div class=\"formControls\">" -" <input type=\"submit\" name=\"hgLogin.do.displayLogin\" value=\"Continue\" class=\"largeButton\">" +" <input type=\"submit\" name=\"hgLogin.do.accountHelp\" value=\"Continue\" class=\"largeButton\">" " <a href=\"javascript:history.go(-1)\">Cancel</a>" "</div>" "</form>" "</div><!-- END - accountHelpBox -->" +, email ); } +void accountHelp(struct sqlConnection *conn) +/* email user username(s) or new password */ +{ +struct sqlResult *sr; +char **row; +char query[256]; +char *email = cartUsualString(cart, "hgLogin_email", ""); +if (sameString(email,"")) + { + freez(&errMsg); + errMsg = cloneString("Email address cannot be blank."); + displayAccHelpPage(conn); + return; + } +/* TODO: validate the email address is in right format */ +/* Username selcted? */ +char *helpWith = cartUsualString(cart, "helpWith", ""); +if (sameString(helpWith,"username")) + { + sendMail(); + freez(&errMsg); + errMsg = cloneString("Forgot user name selected!"); + displayAccHelpPage(conn); + return; + } +if (sameString(helpWith,"password")) + { + freez(&errMsg); + errMsg = cloneString("Forgot password selected!"); + displayAccHelpPage(conn); + return; + } +displayAccHelpPage(conn); +return; +} + /* ----- account login/display functions ---- */ void displayLoginPage(struct sqlConnection *conn) /* draw the account login page */ { char *username = cartUsualString(cart, "hgLogin_userName", ""); /* for password security, use cgi hash instead of cart */ // char *password = cgiUsualString("hgLogin_password", ""); hPrintf( "<div id=\"loginBox\" class=\"centeredContainer formBox\">" "\n" "<h2>UCSC Genome Browser</h2>" @@ -829,35 +906,32 @@ sqlFreeResult(&sr); /* TODO: check user name exist and activated */ /* ..... */ if (checkPwd(password,m->password)) { unsigned int userID=m->idx; hPrintf("<h2>Login successful for user %s with id %d.\n</h2>\n" ,userName,userID); displayLoginSuccess(userName,userID); return; } else { - //hPrintf("<h1>Invalid User/Password</h1>\n"); - errMsg = cloneString("Invalid User/Password."); - + errMsg = cloneString("Invalid user name or password."); displayLoginPage(conn); - // hPrintf("Return to <a href=\"hgLogin\">signup</A>.<br>\n"); return; } gbMembersFree(&m); } /******* END dispalyLogin *************************/ void displayLoginSuccess(char *userName, int userID) /* display login success msg, and set cookie */ { // char *hgLoginHost = hgLoginLinkHost(); hPrintf( "<h2>UCSC Genome Browser</h2>" @@ -1042,42 +1116,50 @@ "Click <a href=hgLogin?hgLogin.do.signupPage=1>here</a> to return.<br>" ); } */ else if (cartVarExists(cart, "update")) { updatePasswordsFile(conn); hPrintf( "<h2>UCSC Genome Browser</h2>" "<p align=\"left\">" "</p>" "<h3>Successfully updated the authentication file.</h3>" "Click <a href=hgLogin?hgLogin.do.signupPage=1>here</a> to return.<br>" ); } +/******************************************************************* +else if (cartVarExists(cart, "hgLogin.do.lostUserNamePage")) + lostUserNamedPage(conn); +else if (cartVarExists(cart, "hgLogin.do.lostUserName")) + lostUserName(conn); +********************************************************************/ else if (cartVarExists(cart, "hgLogin.do.lostPasswordPage")) lostPasswordPage(conn); else if (cartVarExists(cart, "hgLogin.do.lostPassword")) lostPassword(conn); else if (cartVarExists(cart, "hgLogin.do.changePasswordPage")) changePasswordPage(conn); else if (cartVarExists(cart, "hgLogin.do.changePassword")) changePassword(conn); else if (cartVarExists(cart, "hgLogin.do.displayUserInfo")) displayUserInfo(conn); else if (cartVarExists(cart, "hgLogin.do.displayAccHelpPage")) displayAccHelpPage(conn); +else if (cartVarExists(cart, "hgLogin.do.accountHelp")) + accountHelp(conn); else if (cartVarExists(cart, "hgLogin.do.displayLoginPage")) displayLoginPage(conn); else if (cartVarExists(cart, "hgLogin.do.displayLogin")) displayLogin(conn); else if (cartVarExists(cart, "hgLogin.do.displayLogout")) displayLogoutSuccess(); else if (cartVarExists(cart, "hgLogin.do.signup")) signup(conn); else signupPage(conn); hDisconnectCentral(&conn); cartRemovePrefix(cart, "hgLogin.do.");