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( + "

GSID HIV Data Browser

" + "

" + "

" + "

Error emailing password to: %s

" + "Click here to return.
" + , email + ); + } +else + { + hPrintf( + "

GSID HIV Data Browser

" + "

" + "

" + "

Password has been emailed to: %s

" + "Click here to return.
" + , 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( "

UCSC Genome Browser

\n" "

\n" "

\n" "

User %s successfully added.

\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( "
" "\n" "

UCSC Genome Browser

" "\n" "

Having trouble signing in?

" "\n" "
" "\n" +"

%s

" +"\n" +, errMsg ? errMsg : "" +); +hPrintf( "

" +"
" +"
" "
" -"
" -"
" -"
" +"
" "\n" "
" "\n" ); hPrintf( "
" "" -"" +"" "
" "\n" "
" -" " +" " "  Cancel" "
" "" "" +, 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( "
" "\n" "

UCSC Genome Browser

" @@ -829,35 +906,32 @@ sqlFreeResult(&sr); /* TODO: check user name exist and activated */ /* ..... */ if (checkPwd(password,m->password)) { unsigned int userID=m->idx; hPrintf("

Login successful for user %s with id %d.\n

\n" ,userName,userID); displayLoginSuccess(userName,userID); return; } else { - //hPrintf("

Invalid User/Password

\n"); - errMsg = cloneString("Invalid User/Password."); - + errMsg = cloneString("Invalid user name or password."); displayLoginPage(conn); - // hPrintf("Return to signup.
\n"); return; } gbMembersFree(&m); } /******* END dispalyLogin *************************/ void displayLoginSuccess(char *userName, int userID) /* display login success msg, and set cookie */ { // char *hgLoginHost = hgLoginLinkHost(); hPrintf( "

UCSC Genome Browser

" @@ -1042,42 +1116,50 @@ "Click here to return.
" ); } */ else if (cartVarExists(cart, "update")) { updatePasswordsFile(conn); hPrintf( "

UCSC Genome Browser

" "

" "

" "

Successfully updated the authentication file.

" "Click here to return.
" ); } +/******************************************************************* +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.");