Permalink
Browse files

Extracted actual [web-to-lead] code from Fat Free CRM

  • Loading branch information...
1 parent 86c4cd9 commit 5d424629c47bcf4409725275e1be409ddefb04ca @michaeldv michaeldv committed Feb 4, 2009
Showing with 59 additions and 10 deletions.
  1. +0 −8 README
  2. +28 −0 README.rdoc
  3. +10 −1 init.rb
  4. +0 −1 lib/crm_sample_plugin.rb
  5. +21 −0 lib/crm_web_to_lead.rb
View
8 README
@@ -1,8 +0,0 @@
-Sample web-to-lead capture plugin for Fat Free CRM
-Copyright (c) 2009 by Michael Dvorkin, released under the MIT license
-
-This sample plugin shows how to implement Fat Free CRM controller filter
-callback hook to capture lead information submitted from remote form.
-
-Fat Free CRM -- http://github.com/michaeldv/fat_free_crm/tree/master
-
View
@@ -0,0 +1,28 @@
+=== Web-To-Lead Capture Plugin for Fat Free CRM
+
+This sample plugin shows how to implement Fat Free CRM application
+controller callback hook to capture lead information submitted from
+remote form. For more information about Fat Free CRM visit
+http://github.com/michaeldv/fat_free_crm/tree/master
+
+Remote form should POST two hidden fields to identify the user who'll
+own the lead:
+
+ <input type="hidden" name="authorization" value="<<< password_hash Here >>>"
+ <input type="hidden" name="token" value="<<< password_token here >>>"
+
+You can test the submission by posting the form using +curl+:
+
+ $ curl -d "first_name=John&last_name=&Doe&authorization=?&token=?" localhost:3000/leads/create
+
+Replace question marks with the actual values of +password_hash+ and
++password_token+ as set in +users+ table. Successful lead submission
+gets logged in Rails log file.
+
+Enjoy!
+
+---
+Copyright (c) 2009 by Michael Dvorkin, released under the MIT license.
+
+
+
View
11 init.rb
@@ -1 +1,10 @@
-# Include hook code here
+RAILS_DEFAULT_LOGGER.info ">> Adding web-to-lead Fat Free CRM plugin..."
+
+FatFreeCRM::Plugin. << :web_to_lead do # Same as FatFreeCRM::Plugin.add(:web_to_lead) do
+ name "Web-to-lead Capture Fat Free CRM Plugin"
+ author "Michael Dvorkin"
+ version "1.0"
+ description "Create Fat Free CRM leads from the data submitted via remote web form."
+end
+
+require "crm_web_to_lead.rb"
View
@@ -1 +0,0 @@
-# CrmSamplePlugin
View
@@ -0,0 +1,21 @@
+class AppCallback < FatFreeCRM::Callback::Base
+
+ # Implement application's before_filter hook.
+ #----------------------------------------------------------------------------
+ def app_before_filter(controller, context = {})
+
+ # Only trap leads/create.
+ return unless controller.controller_name == "leads" && controller.action_name == "create"
+
+ # Remote form should POST two hidden fields to identify the user who'll own the lead:
+ #
+ # <input type="hidden" name="authorization" value="<<< User's password_hash Here >>>"
+ # <input type="hidden" name="token" value="<<< User's password_token Here >>>"
+ #
+ if controller.request.post? && !controller.params[:authorization].blank? && !controller.params[:token].blank?
+ @current_user = User.find_by_password_hash_and_password_salt(controller.params[:authorization], controller.params[:token])
+ controller.logger.info ">>> web-to-lead: creating lead for user " + @current_user.inspect
+ end
+ end
+
+end

0 comments on commit 5d42462

Please sign in to comment.