johnhenry 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +34 -0
  4. data/app/assets/images/johnhenry/home/welcome/ga-screenshot.jpg +0 -0
  5. data/app/assets/images/johnhenry/home/welcome/logo-bootstrap-html-css.jpg +0 -0
  6. data/app/assets/images/johnhenry/home/welcome/logo-heroku.jpg +0 -0
  7. data/app/assets/images/johnhenry/home/welcome/logo-stripe-users.jpg +0 -0
  8. data/app/assets/images/johnhenry/home/welcome/sign-in-screenshot.jpg +0 -0
  9. data/app/assets/images/johnhenry/home/welcome/sign-up-screenshot.jpg +0 -0
  10. data/app/assets/images/johnhenry/home/welcome/tree-bark.png +0 -0
  11. data/app/assets/images/johnhenry/spinner-primary.gif +0 -0
  12. data/app/assets/javascripts/johnhenry/application.js +16 -0
  13. data/app/assets/javascripts/johnhenry/form-require-validation.js +27 -0
  14. data/app/assets/javascripts/johnhenry/layout.js +6 -0
  15. data/app/assets/javascripts/johnhenry/payment-form.js +33 -0
  16. data/app/assets/stylesheets/johnhenry/application.css +21 -0
  17. data/app/assets/stylesheets/johnhenry/home.css.scss +27 -0
  18. data/app/assets/stylesheets/johnhenry/payment-form.css.scss +5 -0
  19. data/app/assets/stylesheets/johnhenry/payments.css.scss +3 -0
  20. data/app/controllers/johnhenry/application_controller.rb +39 -0
  21. data/app/controllers/johnhenry/home_controller.rb +25 -0
  22. data/app/controllers/johnhenry/payments_controller.rb +146 -0
  23. data/app/controllers/johnhenry/registrations_controller.rb +26 -0
  24. data/app/controllers/johnhenry/sessions_controller.rb +5 -0
  25. data/app/helpers/johnhenry/application_helper.rb +4 -0
  26. data/app/models/payment.rb +3 -0
  27. data/app/models/user.rb +6 -0
  28. data/app/views/johnhenry/devise/confirmations/new.html.haml +9 -0
  29. data/app/views/johnhenry/devise/mailer/confirmation_instructions.html.haml +4 -0
  30. data/app/views/johnhenry/devise/mailer/reset_password_instructions.html.haml +6 -0
  31. data/app/views/johnhenry/devise/mailer/unlock_instructions.html.haml +5 -0
  32. data/app/views/johnhenry/devise/passwords/edit.html.haml +14 -0
  33. data/app/views/johnhenry/devise/passwords/new.html.haml +9 -0
  34. data/app/views/johnhenry/devise/registrations/edit.html.haml +30 -0
  35. data/app/views/johnhenry/devise/registrations/new.html.haml +6 -0
  36. data/app/views/johnhenry/devise/sessions/new.html.haml +6 -0
  37. data/app/views/johnhenry/devise/shared/_links.haml +21 -0
  38. data/app/views/johnhenry/devise/unlocks/new.html.haml +9 -0
  39. data/app/views/johnhenry/home/welcome.html.haml +119 -0
  40. data/app/views/johnhenry/payments/_form.html.haml +19 -0
  41. data/app/views/johnhenry/payments/edit.html.haml +7 -0
  42. data/app/views/johnhenry/payments/index.html.haml +22 -0
  43. data/app/views/johnhenry/payments/index.json.jbuilder +4 -0
  44. data/app/views/johnhenry/payments/new.html.haml +5 -0
  45. data/app/views/johnhenry/payments/show.html.haml +19 -0
  46. data/app/views/johnhenry/payments/show.json.jbuilder +1 -0
  47. data/app/views/johnhenry/shared/_payment_form.html.haml +74 -0
  48. data/app/views/johnhenry/shared/_signin_form.html.haml +37 -0
  49. data/app/views/johnhenry/shared/_signup_form.html.haml +48 -0
  50. data/app/views/layouts/johnhenry/application.html.haml +65 -0
  51. data/config/initializers/devise.rb +258 -0
  52. data/config/routes.rb +12 -0
  53. data/db/development.sqlite3 +0 -0
  54. data/db/migrate/20140104011356_add_users_and_payments.rb +33 -0
  55. data/lib/Gemfile +19 -0
  56. data/lib/johnhenry.rb +4 -0
  57. data/lib/johnhenry/engine.rb +5 -0
  58. data/lib/johnhenry/version.rb +3 -0
  59. data/lib/tasks/johnhenry_tasks.rake +129 -0
  60. data/test/dummy/README.rdoc +28 -0
  61. data/test/dummy/Rakefile +6 -0
  62. data/test/dummy/app/assets/javascripts/application.js +13 -0
  63. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  64. data/test/dummy/app/controllers/application_controller.rb +5 -0
  65. data/test/dummy/app/helpers/application_helper.rb +2 -0
  66. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  67. data/test/dummy/bin/bundle +3 -0
  68. data/test/dummy/bin/rails +4 -0
  69. data/test/dummy/bin/rake +4 -0
  70. data/test/dummy/config.ru +4 -0
  71. data/test/dummy/config/application.rb +23 -0
  72. data/test/dummy/config/boot.rb +5 -0
  73. data/test/dummy/config/database.yml +25 -0
  74. data/test/dummy/config/environment.rb +5 -0
  75. data/test/dummy/config/environments/development.rb +29 -0
  76. data/test/dummy/config/environments/production.rb +80 -0
  77. data/test/dummy/config/environments/test.rb +36 -0
  78. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  79. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  80. data/test/dummy/config/initializers/inflections.rb +16 -0
  81. data/test/dummy/config/initializers/mime_types.rb +5 -0
  82. data/test/dummy/config/initializers/secret_token.rb +12 -0
  83. data/test/dummy/config/initializers/session_store.rb +3 -0
  84. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  85. data/test/dummy/config/locales/en.yml +23 -0
  86. data/test/dummy/config/routes.rb +4 -0
  87. data/test/dummy/public/404.html +58 -0
  88. data/test/dummy/public/422.html +58 -0
  89. data/test/dummy/public/500.html +57 -0
  90. data/test/dummy/public/favicon.ico +0 -0
  91. data/test/integration/navigation_test.rb +10 -0
  92. data/test/test_helper.rb +15 -0
  93. metadata +311 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2555d040af6adedcbd13fae9ff54334139724d2f
4
+ data.tar.gz: 17eca4ab9fb6475a52ca238556462b53acc69e16
5
+ SHA512:
6
+ metadata.gz: 1754eeb19ee657cb283891942817acf3032100e7c6c1dc8fa01fc5362b4aa8b2828a6345f0c75e76bdf8844555e9877a64a1c2778ea328a100215655287147a5
7
+ data.tar.gz: 519ebd21d97f938080fc8e1a8560a1ee029160225174b3772dc9f4b284294c2b8a7eb4d1fc20dd3d3aafd1be1885042c5530e691f9e10c2a959bdf3415a29b59
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'JohnHenry'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,16 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require bootstrap
16
+ //= require_tree .
@@ -0,0 +1,27 @@
1
+ $(function() {
2
+ $('form.require-validation').bind('submit', function(e) {
3
+ var $form = $(e.target).closest('form'),
4
+ inputSelector = ['input[type=email]', 'input[type=password]',
5
+ 'input[type=text]', 'input[type=file]',
6
+ 'textarea'].join(', '),
7
+ $inputs = $form.find('.required').find(inputSelector),
8
+ $errorMessage = $form.find('div.error'),
9
+ $submitButton = $form.find('button, input[type=submit]'),
10
+ $submitSpinner = $submitButton.find('img');
11
+
12
+ $submitSpinner.removeClass('hide');
13
+ $errorMessage.addClass('hide');
14
+ $('.has-error').removeClass('has-error');
15
+
16
+ $inputs.each(function(i, el) {
17
+ var $input = $(el);
18
+ if ($input.val() === '') {
19
+ $input.parent().addClass('has-error');
20
+ $errorMessage.removeClass('hide');
21
+ $form.find('button, input[type=submit]').find('img').addClass('hide');
22
+ e.preventDefault(); // cancel on first error
23
+ valid = false;
24
+ }
25
+ });
26
+ });
27
+ });
@@ -0,0 +1,6 @@
1
+ $(function() {
2
+ $('a.dismiss-flash').on('click', function(ev) {
3
+ ev.preventDefault();
4
+ $(ev.target).closest('.container').empty();
5
+ });
6
+ });
@@ -0,0 +1,33 @@
1
+ $(function() {
2
+ var $form = $("#payment-form");
3
+
4
+ $form.on('submit', function(e) {
5
+ if (!$form.data('cc-on-file')) {
6
+ e.preventDefault();
7
+ Stripe.setPublishableKey($form.data('stripe-publishable-key'));
8
+ Stripe.createToken({
9
+ number: $('.card-number').val(),
10
+ cvc: $('.card-cvc').val(),
11
+ exp_month: $('.card-expiry-month').val(),
12
+ exp_year: $('.card-expiry-year').val()
13
+ }, stripeResponseHandler);
14
+ }
15
+ });
16
+
17
+ function stripeResponseHandler(status, response) {
18
+ if (response.error) {
19
+ $form
20
+ .find('.error')
21
+ .removeClass('hide')
22
+ .find('.alert')
23
+ .text(response.error.message);
24
+ } else {
25
+ // token contains id, last4, and card type
26
+ var token = response['id'];
27
+ // insert the token into the form so it gets submitted to the server
28
+ $form.find('input[type=text]').empty();
29
+ $form.append("<input type='hidden' name='payment[stripe_token]' value='" + token + "'/>");
30
+ $form.get(0).submit();
31
+ }
32
+ }
33
+ })
@@ -0,0 +1,21 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require bootstrap
13
+ *= require_tree .
14
+ */
15
+ .container .alert,
16
+ nav.navbar {
17
+ margin-bottom: 0;
18
+ }
19
+ .stretch {
20
+ width: 100%;
21
+ }
@@ -0,0 +1,27 @@
1
+ // Place all the styles related to the home controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
4
+ #hero-unit {
5
+ width: 100%;
6
+ min-height: 400px;
7
+ .well {
8
+ font-size: 18px;
9
+ }
10
+ label,
11
+ .alert {
12
+ font-size: 14px;
13
+ }
14
+ }
15
+ #common-modules,
16
+ #google-analytics,
17
+ #stripe,
18
+ #heroku,
19
+ #bootstrap {
20
+ p, li {
21
+ font-size: 26px;
22
+ margin-bottom: 15px;
23
+ }
24
+ }
25
+ body > .container:nth-child(n+3) {
26
+ margin-top: 80px;
27
+ }
@@ -0,0 +1,5 @@
1
+ #payment-form {
2
+ .submit-button {
3
+ margin-top: 10px;
4
+ }
5
+ }
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the Payments controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,39 @@
1
+ class Johnhenry::ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ before_filter :set_meta_tag_defaults
5
+
6
+ DEFAULT_TITLE = 'Example Title'
7
+ DEFAULT_DESCRIPTION =
8
+ 'This is the example description and should be overridden.'
9
+ def set_meta_tag_defaults
10
+ {
11
+ title: DEFAULT_TITLE,
12
+ description: DEFAULT_DESCRIPTION,
13
+ language: 'english',
14
+ viewport: 'width=device-width, initial-scale=1, maximum-scale=1',
15
+ robots: 'index, follow',
16
+ og: {
17
+ title: DEFAULT_TITLE,
18
+ description: DEFAULT_DESCRIPTION,
19
+ image: 'http://placekitten.com/400/400',
20
+ type: 'website' }
21
+ }.tap do |meta_tags|
22
+ # Set as ENV variables FB_ADMINS and FB_APP_ID
23
+ %w(fb:admins fb:app_id).each do |fb_key|
24
+ env_key = fb_key.upcase.sub(':', '_')
25
+ if ENV[env_key].present?
26
+ meta_tags[fb_key] = ENV[env_key]
27
+ end
28
+ end
29
+
30
+ if defined?(set_meta)
31
+ set_meta meta_tags
32
+ end
33
+ end
34
+ end
35
+
36
+ def admin_ids
37
+ [1]
38
+ end
39
+ end
@@ -0,0 +1,25 @@
1
+ class Johnhenry::HomeController < Johnhenry::ApplicationController
2
+ before_filter :set_home_meta_tags
3
+
4
+ def welcome
5
+ title = 'New to Ruby on Rails? Launch a site like this in 10 minutes'
6
+ description = <<-EOS.squish
7
+ In under 10 minutes, watch your first web site go live to the internet!
8
+ Save weeks of development time by building your next app on top of Rails
9
+ 4 Payment: ready to deploy on Heroku, included common front-end modules
10
+ already built, accept payments with Stripe, Google Analytics integration
11
+ and more!
12
+ EOS
13
+ if defined?(set_meta)
14
+ set_meta title: title, description: description,
15
+ og: { title: title, description: description }
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def set_home_meta_tags
22
+ set_meta description: 'This will override the default description.',
23
+ title: 'This title is overridden by set_meta in the controller action.'
24
+ end
25
+ end
@@ -0,0 +1,146 @@
1
+ require 'github/markup'
2
+
3
+ class Johnhenry::PaymentsController < Johnhenry::ApplicationController
4
+ before_action :set_payment, only: [:show, :edit, :update, :destroy]
5
+ before_filter :must_have_session, only: [:index, :show]
6
+
7
+ # GET /payments
8
+ # GET /payments.json
9
+ def index
10
+ @payments = Payment.where(user_id: current_user.id)
11
+ end
12
+
13
+ # GET /payments/1
14
+ # GET /payments/1.json
15
+ def show
16
+ filename = File.join(File.dirname(File.expand_path(__FILE__)),
17
+ '../../../README.md')
18
+ @readme = GitHub::Markup.render(filename, File.read(filename))
19
+ end
20
+
21
+ # GET /payments/new
22
+ def new
23
+ @payment = Payment.new
24
+ end
25
+
26
+ # GET /payments/1/edit
27
+ def edit
28
+ end
29
+
30
+ # POST /payments
31
+ # POST /payments.json
32
+ def create
33
+ if !signed_in?
34
+ if params[:email].present?
35
+ #TODO DRY with other new user generation
36
+ password = Devise.friendly_token.first(10)
37
+ user = User.create! email: params[:email],
38
+ password: password,
39
+ password_confirmation: password
40
+ sign_in(user)
41
+ else
42
+ return redirect_to '/', alert: 'You need an account to do that.'
43
+ end
44
+ end
45
+
46
+ begin
47
+ charge_user!(payment_params['stripe_token'], 7)
48
+ rescue => exc
49
+ Rails.logger.error(exc.message)
50
+ Rails.logger.error(exc.inspect)
51
+ return redirect_to '/', alert: 'Payment could not be processed.'
52
+ end
53
+
54
+ txn_info = {
55
+ user_id: current_user.id,
56
+ stripe_customer_id: current_user.stripe_customer_id,
57
+ amount: 7.0
58
+ }
59
+ @payment = Payment.new(payment_params.merge(txn_info))
60
+
61
+ respond_to do |format|
62
+ if @payment.save
63
+ format.html { redirect_to @payment, notice: 'Payment was successfully made.' }
64
+ format.json { render action: 'show', status: :created, location: @payment }
65
+ else
66
+ format.html { render action: 'new' }
67
+ format.json { render json: @payment.errors, status: :unprocessable_entity }
68
+ end
69
+ end
70
+ end
71
+
72
+ def charge_user!(stripe_token, amount)
73
+ Rails.logger.info "Charging #{ current_user.id } : _stripe_token: #{ stripe_token }"
74
+
75
+ # create customer_id if it's a new stripe_token
76
+ unless current_user.stripe_customer_id
77
+ customer = Stripe::Customer.create(
78
+ card: stripe_token,
79
+ description: current_user.email || "user_id_#{ current_user.id }"
80
+ )
81
+ Rails.logger.info "Created customer: #{ customer.inspect }"
82
+ current_user.update_attributes stripe_customer_id: customer.id
83
+ end
84
+
85
+ Rails.logger.info(
86
+ "About to charge customer_id: #{ current_user.stripe_customer_id }")
87
+ charge = Stripe::Charge.create(
88
+ amount: amount * 100, # convert from dollars to cents
89
+ currency: 'usd',
90
+ customer: current_user.stripe_customer_id
91
+ )
92
+ Rails.logger.info "Charged #{ charge.inspect }"
93
+ end
94
+
95
+
96
+ # PATCH/PUT /payments/1
97
+ # PATCH/PUT /payments/1.json
98
+ def update
99
+ respond_to do |format|
100
+ if @payment.update(payment_params)
101
+ format.html { redirect_to @payment, notice: 'Payment was successfully updated.' }
102
+ format.json { head :no_content }
103
+ else
104
+ format.html { render action: 'edit' }
105
+ format.json { render json: @payment.errors, status: :unprocessable_entity }
106
+ end
107
+ end
108
+ end
109
+
110
+ # DELETE /payments/1
111
+ # DELETE /payments/1.json
112
+ def destroy
113
+ @payment.destroy
114
+ respond_to do |format|
115
+ format.html { redirect_to payments_url }
116
+ format.json { head :no_content }
117
+ end
118
+ end
119
+
120
+ private
121
+ # Use callbacks to share common setup or constraints between actions.
122
+ def set_payment
123
+ @payment = Payment.find(params[:id])
124
+ if !allowed_user?(@payment)
125
+ flash[:alert] = "You don't have permission to see that payment."
126
+ return redirect_to '/'
127
+ end
128
+ end
129
+
130
+ # Never trust parameters from the scary internet, only allow the white list through.
131
+ def payment_params
132
+ params.require(:payment).permit(:user_id, :stripe_token, :stripe_customer_id, :email)
133
+ end
134
+
135
+ def allowed_user?(payment)
136
+ return false unless signed_in?
137
+ (admin_ids + [payment.user_id]).compact.include?(current_user.try(:id))
138
+ end
139
+
140
+ def must_have_session
141
+ if !signed_in?
142
+ flash[:alert] = "You need an account to view your payments."
143
+ return redirect_to '/'
144
+ end
145
+ end
146
+ end