EricBourland

userCC.cfm / Eric Bourland

Feb 18th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.94 KB | None | 0 0
  1. <!-----
  2. Name: editCC.cfm
  3. Author: Eric Bourland
  4. Description: view, update CC information
  5. Created: February 2013
  6. Revised: February 2013
  7. ColdFusion Version 9
  8. MS SQL Server 2005
  9. ----->
  10.  
  11. <!--- set a default value "" for UserID in scope URL --->
  12. <cfparam name="url.UserID" default="">
  13.  
  14. <!--- define the UserID in scope FORM, then set form.UserID equal to the UserID passed in the URL --->
  15. <cfparam name="form.UserID" default="#url.UserID#">
  16.  
  17. <!--- set default values for other user-editable fields --->
  18.  
  19. <cfparam name="form.FirstName" default="">
  20. <cfparam name="form.MiddleInitial" default="">
  21. <cfparam name="form.LastName" default="">
  22. <cfparam name="form.UserRoleID" default="">
  23. <cfparam name="form.DateModified" default="">
  24. <cfparam name="form.CheckEnclosed" default="">
  25. <cfparam name="form.AuthorizeCharge" default="">
  26. <cfparam name="form.CreditCard" default="">
  27. <cfparam name="form.CreditCardNumber" default="">
  28. <cfparam name="form.ExpirationDate" default="">
  29. <cfparam name="form.PrintedCardHolderName" default="">
  30. <cfparam name="form.CreditCardZIPCode" default="">
  31. <cfparam name="form.CVV" default="">
  32.  
  33.  
  34. <!--- in user-editable fields, set up protection against XSS --->
  35. <cfloop collection="#FORM#" item="field">
  36. <cfset FORM[ field ] = ReReplaceNoCase (FORM[ field ], "<script.*?>.*?</script>", "", "all")>
  37. </cfloop>
  38.  
  39.  
  40. <!--- query editUser tells ColdFusion which record to edit--->
  41. <cfquery datasource="#application.datasource#" name="editUser">
  42. SELECT UserID
  43. ,FirstName
  44. ,MiddleInitial
  45. ,LastName
  46. ,UserRoleID
  47. ,CheckEnclosed
  48. ,AuthorizeCharge
  49. ,CreditCard
  50. ,CreditCardNumber
  51. ,ExpirationDate
  52. ,PrintedCardHolderName
  53. ,CreditCardZIPCode
  54. ,CVV
  55. ,DateCreated
  56. ,DateModified
  57.  
  58. FROM #request.membersTable#
  59. WHERE UserID = <cfqueryparam cfsqltype="cf_sql_integer" value="#val(form.UserID)#">
  60. </cfquery>
  61.  
  62.  
  63. <!---- begin CFTRY; catch errors ---->
  64. <cftry>
  65.  
  66. <!---- populate cftry with error message ---->
  67. <cfset variables.error = "">
  68.  
  69. <!--- BEGIN: Save action --->
  70.  
  71. <!--- begin form.doSave --->
  72.  
  73. <cfif IsDefined("FORM.doSave")>
  74.  
  75.  
  76. <!--- encryption --->
  77.  
  78. <!--- if a value is entered in form.CreditCardNumber, then proceed with encryption --->
  79. <cfif len(form.CreditCardNumber)>
  80.  
  81. <!--- set default value for variable "result" in case no value is entered for CreditCardNumber --->
  82. <cfparam name="result" default="">
  83.  
  84. <!--- generate a key suitable for "AES" --->
  85. <cfset theKey = GenerateSecretKey("AES", 256)>
  86. <!--- now do the actual encryption using the "AES" algorithm --->
  87. <cfset result = encrypt(form.CreditCardNumber, theKey, "AES", "UU")>
  88. </cfif>
  89.  
  90.  
  91. <!--- decryption --->
  92.  
  93. <!--- set default value for variable "form.decrypted" in case no value is present in column CreditCardNumber --->
  94. <cfparam name="form.decrypted" default="">
  95.  
  96. <!--- does editUser.CreditCardNumber have a value? --->
  97. <cfif len(editUser.CreditCardNumber)>
  98.  
  99. <!--- if so, apply decrypt function --->
  100. <cfset decrypted = decrypt(form.CreditCardNumber, theKey, "AES", "UU")>
  101. </cfif>
  102.  
  103.  
  104.  
  105. <!--- Assume that a UserID Exists; the action is UPDATE --->
  106. <cfif val(form.UserID)>
  107. <cfquery name="UpdateUser" datasource="#application.datasource#">
  108. UPDATE #REQUEST.membersTable#
  109. SET FirstName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#Trim(Left(form.FirstName,255))#">,
  110. MiddleInitial = <cfqueryparam cfsqltype="cf_sql_varchar" value="#Trim(Left(form.MiddleInitial,5))#">,
  111. LastName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#Trim(Left(form.LastName,255))#">,
  112. CheckEnclosed = <cfqueryparam cfsqltype="cf_sql_bit" value="#val(CheckEnclosed)#">,
  113. AuthorizeCharge = <cfqueryparam cfsqltype="cf_sql_bit" value="#val(AuthorizeCharge)#">,
  114. CreditCard = <cfqueryparam cfsqltype="cf_sql_varchar" value="#Trim(Left(form.CreditCard,20))#">,
  115. <cfif len(form.CreditCardNumber)>CreditCardNumber = <cfqueryparam cfsqltype="cf_sql_varchar" value="#result#">,</cfif>
  116. ExpirationDate = <cfqueryparam cfsqltype="cf_sql_varchar" value="#Trim(Left(form.ExpirationDate,10))#">,
  117. PrintedCardHolderName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#Trim(Left(form.PrintedCardHolderName,128))#">,
  118. CreditCardZIPCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#Trim(Left(form.CreditCardZIPCode,128))#">,
  119. CVV = <cfqueryparam cfsqltype="cf_sql_varchar" value="#Trim(Left(form.CVV,12))#">,
  120. DateModified = <cfqueryparam cfsqltype="cf_sql_timestamp" value="#now()#">
  121. WHERE UserID = <cfqueryparam cfsqltype="cf_sql_integer" value="#val(form.UserID)#">
  122. </cfquery>
  123.  
  124.  
  125. <!--- END queries to update or insert database records --->
  126.  
  127. <!--- END cfif val(form.UserID) -- if a record needed to be updated, then it was done --->
  128. </cfif>
  129.  
  130.  
  131. <!--- done? relocate --->
  132.  
  133.  
  134. <cflocation url="/admin/manageUsers.cfm" addtoken="no">
  135.  
  136.  
  137.  
  138. <!--- END: Save action --->
  139.  
  140. <!--- END form.doSave --->
  141. </cfif>
  142.  
  143. <!--- END queries to update or insert database records --->
  144.  
  145.  
  146. <!--- this CFCATCH will trap errors -- the ones you threw or just regular database issues --->
  147. <cfcatch type="Any">
  148. <cfset variables.error = cfcatch.message>
  149. <cfrethrow>
  150. </cfcatch>
  151.  
  152. <!--- END CFTRY --->
  153. </cftry>
  154.  
  155.  
  156.  
  157. <!--- fetch the data from the database only when there are no errors; let the form variables pass back from the data table into the form to display ---->
  158.  
  159. <cfif len(variables.error) eq 0>
  160.  
  161. <cfloop index="aCol" list="#editUser.columnList#">
  162. <cfset "form.#aCol#" = editUser[aCol][editUser.currentRow]>
  163. </cfloop>
  164.  
  165. </cfif>
  166.  
  167. <!----- if record already exists (it will have a UserID) then update record; otherwise, add new record ----->
  168.  
  169. <!--- include HTML page head --->
  170. <cfinclude template="/admin/admin_header.cfm">
  171.  
  172. <!--- include navigation --->
  173. <cfinclude template="/admin/adminNav.cfm">
  174.  
  175.  
  176. <hr />
  177.  
  178. <!--- if there an error, display error in human-readable form --->
  179.  
  180. <cfif len(variables.error)>
  181. <cfoutput>
  182. <div class="errorbox">#variables.error#</div>
  183. </cfoutput>
  184.  
  185. <br />
  186.  
  187. <div class="align-center">
  188. <input type=button value="Go Back" onClick="history.go(-1)">
  189. </div>
  190.  
  191. <cfabort>
  192. </cfif>
  193.  
  194.  
  195.  
  196. <cfparam name="url.cftoken" default="">
  197.  
  198. <cfif len(url.cftoken)>
  199.  
  200. <div class="notice success width150px align-center">Update Succeeded.</div>
  201.  
  202. </cfif>
  203.  
  204.  
  205. <script language="JavaScript" type="application/javascript">
  206. <!-- Begin
  207. function popUp(URL) {
  208. day = new Date();
  209. id = day.getTime();
  210. eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=440,height=500,left = 383,top = 84');");
  211. }
  212. // End -->
  213. </script>
  214.  
  215.  
  216. <!--- Add or Update User Form begins here --->
  217. <cfform method="post" enctype="multipart/form-data" scriptsrc="#request.CFFORM_JS_Lib#">
  218.  
  219.  
  220. <!--- Embed UserID (PK) to assign a value to it --->
  221. <cfoutput>
  222. <input type="hidden" name="UserID" value="#form.UserID#" />
  223. </cfoutput>
  224.  
  225.  
  226.  
  227. <p><span class="icon red small" data-icon="V"></span> <em>indicates a required field.</em></p>
  228.  
  229.  
  230. <table>
  231. <tr>
  232. <td colspan="2"><h2>Membership Payment Information for <cfoutput>#FirstName# #MiddleInitial# #LastName#</cfoutput></h2></td></tr>
  233.  
  234. <tr>
  235. <td colspan="2">
  236.  
  237.  
  238. <p><span class="icon medium red" data-icon="`"></span> <strong>Payment information is submitted through a secured connection and stored in encrypted format in a secure database. Your payment information is never displayed on this screen. The security of your data is very important to us.</strong></p>
  239.  
  240.  
  241. <p><cfinput type="Checkbox" name="CheckEnclosed" value="1" checked="#val(editUser.CheckEnclosed)#" tabindex="15" /> Enclosed is a check, payable to <cfoutput>#REQUEST.CompanyName#</cfoutput>.</p>
  242.  
  243.  
  244. <p><cfinput type="Checkbox" name="AuthorizeCharge" value="1" checked="#val(editUser.AuthorizeCharge)#" tabindex="16" /> I authorize <cfoutput>#REQUEST.CompanyName#</cfoutput> to charge my:</p>
  245.  
  246.  
  247. <!--- this query selects Credit Cards from table LookupCC --->
  248. <cfquery datasource="#APPLICATION.dataSource#" name="GetCC">
  249. SELECT CreditCardName
  250. FROM LookupCC
  251. </cfquery>
  252.  
  253.  
  254. <p class="float-left" style="margin-left:20px">
  255. <cfselect tabindex="17" size="1" name="CreditCard" display="CreditCardName" multiple="no" query="GetCC" queryPosition="below" selected="#editUser.CreditCard#" id="CreditCard">
  256. <option value="SelectCard">Select a Credit Card</option>
  257. </cfselect></p>
  258.  
  259.  
  260. <table>
  261. <tr>
  262. <td>Credit Card Number (decrypted):</td>
  263. <td><cfinput TYPE="text" SIZE="30" NAME="CreditCardNumber" value="#decrypted#" tabindex="19" /></td>
  264. <td>Expiration Date:</td>
  265. <td><cfinput TYPE="text" SIZE="15" NAME="ExpirationDate" value="#editUser.ExpirationDate#" tabindex="20" /></td>
  266. </tr>
  267. <tr>
  268. <td>Printed Cardholder Name:</td>
  269. <td><cfinput TYPE="text" SIZE="30" NAME="PrintedCardHolderName" value="#editUser.PrintedCardHolderName#" tabindex="21" /></td>
  270. <td>Credit Card ZIP Code:</td>
  271. <td><cfinput TYPE="text" SIZE="15" NAME="CreditCardZIPCode" value="#editUser.CreditCardZIPCode#" tabindex="22" /></td>
  272. </tr>
  273. <tr>
  274. <td>Signature (if printing and mailing):</td>
  275. <td>__________________________</td>
  276. <td>CVV#/3-digit #:</td>
  277. <td><cfinput TYPE="text" SIZE="15" NAME="CVV" value="#editUser.CVV#" tabindex="23" /></td>
  278. </tr>
  279. </table>
  280.  
  281. </td>
  282.  
  283. </tr>
  284.  
  285.  
  286.  
  287. </table>
  288.  
  289.  
  290.  
  291.  
  292.  
  293. <!--- submit form to ColdFusion for processing; this is the DoSave function, which will add or edit a record --->
  294.  
  295. <div class="align-center"> <cfoutput>
  296.  
  297. <button name="doSave" type="submit" class="medium orange" tabindex="27">Update</button>
  298.  
  299. </cfoutput>
  300. </div>
  301.  
  302. </cfform>
  303.  
  304.  
  305.  
  306. <!--- Page footer --->
  307. <cfinclude template="/admin/admin_footer.cfm">
Advertisement
Add Comment
Please, Sign In to add comment