PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/asp/include/issue-verification-token.asp

http://loginsystem-rd.googlecode.com/
ASP | 167 lines | 117 code | 7 blank | 43 comment | 21 complexity | 2795d4a77690fb6741f7b15a4e697c5f MD5 | raw file
  1. <%
  2. '* alpha 0.5a debug
  3. '* $Id: issue-verification-token.asp 356 2010-05-23 03:06:55Z rdivilbiss $
  4. '*******************************************************************************************************************
  5. '* Page Name: Issue Verification Token
  6. '* On Entry: None
  7. '* Input : userid, email
  8. '* Output : new verification token emailed to account owner
  9. '* On Exit : message
  10. '******************************************************************************************************************
  11. ' no browser caching of this page !! to be used on all pages
  12. Response.Expires=-1
  13. Response.ExpiresAbsolute = Now() - 1
  14. ' do not allow proxy servers to cache this page !! to be used on all pages
  15. Response.AddHeader "pragma","no-cache"
  16. Response.CacheControl="private"
  17. Response.CacheControl="no-cache"
  18. Response.CacheControl="no-store"
  19. '*******************************************************************************************************************
  20. '* Diminsion all page variables and initialize default values
  21. '*******************************************************************************************************************
  22. Dim userid, name, email, id, locked, token, dateLocked, mailBody, cmdTxt, message, dbMsg
  23. userid=""
  24. name=""
  25. email=""
  26. id=""
  27. locked=""
  28. token=""
  29. dateLocked=""
  30. mailBody=""
  31. cmdTxt=""
  32. message = lg_phrase_issue_new_token
  33. name=""
  34. dbMsg=""
  35. if lg_debug Then dbMsg = "DEBUG BEGIN<br />" & vbLF End If
  36. '*******************************************************************************************************************
  37. '* If SSL required and not using SSL, redirect to https
  38. '*******************************************************************************************************************
  39. If lg_useSSL and NOT Request.ServerVariables("SERVER_PORT_SECURE")="1" Then
  40. Response.Redirect("https://" & lg_domain & lg_loginPath & lg_filename)
  41. End If
  42. '*******************************************************************************************************************
  43. '* If the form was posted, process the form
  44. '*******************************************************************************************************************
  45. If LCase(Request.ServerVariables("HTTP_METHOD")) = "post" Then
  46. if lg_debug Then dbMsg = "METHOD=POST<br />" & vbLF End If
  47. message=""
  48. userid = getField("userid,rXsafepq")
  49. email = getField("email,rXemail")
  50. if lg_debug Then dbMsg = "userid = "& userid &"<br />" & vbLF End If
  51. if lg_debug Then dbMsg = "email = "& email &"<br />" & vbLF End If
  52. '*****************************************************************************
  53. '* Check for required fields
  54. '*****************************************************************************
  55. If userid="" Then
  56. message = lg_phrase_userid_empty
  57. if lg_debug Then dbMsg = "message = "& message &"<br />" & vbLF End If
  58. End If
  59. If email="" Then
  60. message = lg_phrase_email_empty
  61. if lg_debug Then dbMsg = "message = "& message &"<br />" & vbLF End If
  62. End If
  63. If message="" Then
  64. '*******************************************************************************************************************
  65. '* If all required fields exist, verify there is a valid account and it is locked
  66. '* The account is locked when a peron registers. The account must still be locked in order to
  67. '* receive a new verification token.
  68. '*******************************************************************************************************************
  69. if lg_debug Then dbMsg = "All required fields, process form<br />" & vbLF End If
  70. If lg_database="access" Then
  71. cmdTxt = "SELECT [id], [userid], [name], [email], [locked] FROM users WHERE ([userid]=?) AND ([email]=?);"
  72. Else
  73. cmdTxt = "SELECT id, userid, name, email, locked FROM users WHERE (userid=?) AND (email=?);"
  74. End If
  75. openCommand lg_term_command_string,lg_term_issue_verification_token&" 1"
  76. addParam "@u",adVarChar,adParamInput,CLng(Len(userid)),userid,lg_term_issue_verification_token&" 2"
  77. addParam "@e",adVarChar,adParamInput,CLng(Len(email)),email,lg_term_issue_verification_token&" 3"
  78. getRS db_rs, cmdTxt,lg_term_issue_verification_token&" 4"
  79. If Not(db_rs.bof AND db_rs.eof) Then
  80. id = db_rs("id")
  81. locked = db_rs("locked")
  82. name = db_rs("name")
  83. if lg_debug Then dbMsg = "db ID = "& id &"<br />" & vbLF End If
  84. if lg_debug Then dbMsg = "db Locked = "& locked &"<br />" & vbLF End If
  85. if lg_debug Then dbMsg = "db Name = "& name &"<br />" & vbLF End If
  86. If locked<>"1" Then
  87. '*****************************************************************************
  88. '* The account was not locked. Can not issue a token.
  89. '*****************************************************************************
  90. message = lg_phrase_issue_new_token_error & " 1"
  91. if lg_debug Then dbMsg = "message = "& message &"<br />" & vbLF End If
  92. End If
  93. Else
  94. '*****************************************************************************
  95. '* No account matching the posted information
  96. '*****************************************************************************
  97. message = lg_phrase_no_matching_registration
  98. if lg_debug Then dbMsg = "message = "& message &"<br />" & vbLF End If
  99. End If
  100. closeRS
  101. closeCommand
  102. End If
  103. If message="" Then
  104. '*******************************************************************************************************************
  105. '* We have a valid, locked account, issue a new token and update the user table
  106. '*******************************************************************************************************************
  107. locked="1"
  108. dateLocked = dbNow
  109. token = Left(HashEncode(getGUID),40)
  110. if lg_debug Then dbMsg = "Valid and locked account. Issue token. Update table.<br />" & vbLF End If
  111. if lg_debug Then dbMsg = "Locked = "& locked &"<br />" & vbLF End If
  112. if lg_debug Then dbMsg = "dateLocked = "& dateLocked &"<br />" & vbLF End If
  113. if lg_debug Then dbMsg = "token = "& token &"<br />" & vbLF End If
  114. If lg_database="access" Then
  115. cmdTxt = "UPDATE users SET [token] = ?, [locked] = ?, [dateLocked] = ? WHERE ([id]=?);"
  116. Else
  117. cmdTxt = "UPDATE users SET token = ?, locked = ?, dateLocked = ? WHERE (id=?);"
  118. End If
  119. openCommand lg_term_command_string,lg_term_issue_verification_token&" 5"
  120. addParam "@token",adVarChar,adParamInput,CLng(40),token,lg_term_issue_verification_token&" 6"
  121. addParam "@locked",adVarChar,adParamInput,CLng(1),locked,lg_term_issue_verification_token&" 7"
  122. addParam "@dateLocked",adDate,adParamInput,CLng(8),dateLocked,lg_term_issue_verification_token&" 8"
  123. addParam "@id",adInteger,adParamInput,CLng(4),CInt(id),lg_term_issue_verification_token&" 9"
  124. execCmd cmdTxt
  125. if lg_debug Then dbMsg = "numAffected = "& numAffected &"<br />" & vbLF End If
  126. If numAffected = 1 Then
  127. '*******************************************************************************************************************
  128. '* We updated the record, so send verification email with new account unlock token to user
  129. '*******************************************************************************************************************
  130. message = lg_phrase_issue_new_token_success
  131. if lg_debug Then dbMsg = "message = "& message &"<br />" & vbLF End If
  132. mailBody = mailBody & "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">"
  133. mailBody = mailBody & "<HTML><HEAD><META http-equiv=Content-Type content=""text/html; charset=us-ascii"">"
  134. mailBody = mailBody & "</HEAD><BODY><DIV><FONT face=Arial size=2>"& lg_phrase_registration_mail0 &"<br /><br />"
  135. mailBody = mailBody & lg_term_to &" "& name & "<br /><br />"
  136. mailBody = mailBody & lg_phrase_registration_mail1 &" "& lg_domain &". " & lg_phrase_registration_mail2 & "<br />"
  137. mailBody = mailBody & lg_phrase_registration_mail3 & ".<br /><br />"
  138. mailBody = mailBody & "<a href=""http://" & lg_domain & lg_loginPath & lg_verify_page & "?token=" & token & "&id=1"">"& lg_phrase_registration_mail4 &"</a><br /><br />"
  139. mailBody = mailBody & lg_phrase_registration_mail5 & lg_domain & lg_loginPath & lg_verify_page & "<br />"
  140. mailBody = mailBody & lg_phrase_registration_mail6 & "<br /><br />"
  141. mailBody = mailBody & token & "<br /><br />"
  142. mailBody = mailBody & lg_phrase_registration_mail7 & "<br />"
  143. mailBody = mailBody & "this link: <a href=""http://" & lg_domain & lg_loginPath & lg_register_delete_page & "?email="& email &""">"& lg_term_remove_registration &"</a><br /><br />"
  144. mailBody = mailBody & lg_phrase_registration_mail9 & lg_domain & lg_contact_form & """>"& lg_phrase_contact_webmaster &"</a><br /><br />"
  145. mailBody = mailBody & lg_copyright &"<br />"
  146. mailBody = mailBody & "</FONT></DIV></BODY></HTML>"
  147. if lg_debug Then dbMsg = "mailBody = "& mailBody &"<br />" & vbLF End If
  148. sendmail lg_webmaster_email, email, lg_term_new & " " & lg_term_register_confirmation, mailBody
  149. sendmail lg_webmaster_email, lg_webmaster_email, lg_phrase_attention_webmaster &" "&lg_term_new & " " & lg_term_register_confirmation, mailBody
  150. if lg_debug Then dbMsg = dbMsg & "Email notifications sent.<br />" & vbLF End If
  151. Else
  152. '*****************************************************************************
  153. '* There was an error updating the record and no new token was issued.
  154. '*****************************************************************************
  155. message = lg_phrase_issue_new_token_error & " 2"
  156. if lg_debug Then dbMsg = "message = "& message &"<br />" & vbLF End If
  157. End If
  158. End If
  159. End If
  160. %>