diff --git a/README b/README index 655fb96..60cd8d7 100644 --- a/README +++ b/README @@ -1,4 +1,63 @@ -RECIPES -["analytics", "core", "deployment", "devise", "email", "extras", "frontend", "gems", "git", "init", "learn_rails", "locale", "omniauth", "pages", "rails_bootstrap", "rails_devise", "rails_devise_pundit", "rails_devise_roles", "rails_foundation", "rails_mailinglist_activejob", "rails_omniauth", "rails_signup_download", "rails_stripe_checkout", "railsapps", "readme", "roles", "setup", "tests"] -PREFERENCES -{:git=>true, :apps4=>"rails-signup-download", :announcements=>"none", :authentication=>"devise", :authorization=>"roles", :better_errors=>true, :devise_modules=>false, :form_builder=>false, :local_env_file=>false, :pry=>false, :quiet_assets=>true, :secrets=>["mailchimp_list_id", "mailchimp_api_key"], :pages=>"users", :locale=>"none", :rubocop=>false, :dev_webserver=>"webrick", :prod_webserver=>"webrick", :database=>"sqlite", :templates=>"erb", :tests=>"rspec", :continuous_testing=>"none", :frontend=>"bootstrap3", :email=>"gmail", :dashboard=>"none"} \ No newline at end of file +Rails Stripe Coupons +================ + +Rails Composer, open source, supported by subscribers. +Please join RailsApps to support development of Rails Composer. +Need help? Ask on Stack Overflow with the tag 'railsapps.' +Problems? Submit an issue: https://github.com/RailsApps/rails_apps_composer/issues +Your application contains diagnostics in this README file. +Please provide a copy of this README file when reporting any issues. + + +option Build a starter application? +choose Enter your selection: [rails-signup-download] +option Get on the mailing list for Rails Composer news? +choose Enter your selection: [none] +option Web server for development? +choose Enter your selection: [webrick] +option Web server for production? +choose Enter your selection: [webrick] +option Database used in development? +choose Enter your selection: [sqlite] +option Template engine? +choose Enter your selection: [erb] +option Test framework? +choose Enter your selection: [rspec] +option Continuous testing? +choose Enter your selection: [none] +option Front-end framework? +choose Enter your selection: [bootstrap3] +option Add support for sending email? +choose Enter your selection: [gmail] +option Authentication? +choose Enter your selection: [devise] +option Devise modules? +choose Enter your selection: [false] +option OmniAuth provider? +choose Enter your selection: [] +option Authorization? +choose Enter your selection: [roles] +option Use a form builder gem? +choose Enter your selection: [false] +option Add pages? +choose Enter your selection: [users] +option Set a locale? +choose Enter your selection: [none] +option Install page-view analytics? +choose Enter your selection: [none] +option Add a deployment mechanism? +choose Enter your selection: [none] +option Set a robots.txt file to ban spiders? +choose Enter your selection: [] +option Create a GitHub repository? (y/n) +choose Enter your selection: [] +option Add gem and file for environment variables? +choose Enter your selection: [false] +option Reduce assets logger noise during development? +choose Enter your selection: [true] +option Improve error reporting with 'better_errors' during development? +choose Enter your selection: [true] +option Use 'pry' as console replacement during development and test? +choose Enter your selection: [false] +option Use or create a project-specific rvm gemset? +choose Enter your selection: [true] diff --git a/README.md b/README.md new file mode 100644 index 0000000..ab4daae --- /dev/null +++ b/README.md @@ -0,0 +1,48 @@ +Rails Stripe Coupons +================ + +This application was generated with the [rails_apps_composer](https://github.com/RailsApps/rails_apps_composer) gem +provided by the [RailsApps Project](http://railsapps.github.io/). + +Rails Composer is open source and supported by subscribers. Please join RailsApps to support development of Rails Composer. + +Problems? Issues? +----------- + +Need help? Ask on Stack Overflow with the tag 'railsapps.' + +Your application contains diagnostics in the README file. Please provide a copy of the README file when reporting any issues. + +If the application doesn't work as expected, please [report an issue](https://github.com/RailsApps/rails_apps_composer/issues) +and include the diagnostics. + +Ruby on Rails +------------- + +This application requires: + +- Ruby 2.2.0 +- Rails 4.2.0 + +Learn more about [Installing Rails](http://railsapps.github.io/installing-rails.html). + +Getting Started +--------------- + +Documentation and Support +------------------------- + +Issues +------------- + +Similar Projects +---------------- + +Contributing +------------ + +Credits +------- + +License +------- diff --git a/README.rdoc b/README.rdoc deleted file mode 100644 index dd4e97e..0000000 --- a/README.rdoc +++ /dev/null @@ -1,28 +0,0 @@ -== README - -This README would normally document whatever steps are necessary to get the -application up and running. - -Things you may want to cover: - -* Ruby version - -* System dependencies - -* Configuration - -* Database creation - -* Database initialization - -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... - - -Please feel free to use a different markup language if you do not plan to run -rake doc:app. diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000..d807090 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,28 @@ +class ProductsController < ApplicationController + before_filter :authenticate_user! + before_filter :identify_product + + def show + send_file @path, :disposition => "attachment; filename=#{@file}" + end + + private + def identify_product + valid_characters = "^[0-9a-zA-Z]*$".freeze + unless params[:id].blank? + @product_id = params[:id] + @product_id = @product_id.tr("^#{valid_characters}", '') + else + raise "Filename missing" + end + unless params[:format].blank? + @format = params[:format] + @format = @format.tr("^#{valid_characters}", '') + else + raise "File extension missing" + end + @path = "app/views/products/#{@product_id}.#{@format}" + @file = "#{@product_id}.#{@format}" + end + +end diff --git a/app/jobs/mailing_list_signup_job.rb b/app/jobs/mailing_list_signup_job.rb new file mode 100644 index 0000000..5ae4a96 --- /dev/null +++ b/app/jobs/mailing_list_signup_job.rb @@ -0,0 +1,8 @@ +class MailingListSignupJob < ActiveJob::Base + + def perform(user) + logger.info "signing up #{user.email}" + user.subscribe + end + +end diff --git a/app/models/user.rb b/app/models/user.rb index 9e36969..9498f1a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,7 @@ class User < ActiveRecord::Base enum role: [:user, :vip, :admin] after_initialize :set_default_role, :if => :new_record? + after_create :sign_up_for_mailing_list def set_default_role self.role ||= :user @@ -10,4 +11,21 @@ def set_default_role # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable + + def sign_up_for_mailing_list + MailingListSignupJob.perform_later(self) + end + + def subscribe + mailchimp = Gibbon::API.new(Rails.application.secrets.mailchimp_api_key) + result = mailchimp.lists.subscribe({ + :id => Rails.application.secrets.mailchimp_list_id, + :email => {:email => self.email}, + :double_optin => false, + :update_existing => true, + :send_welcome => true + }) + Rails.logger.info("Subscribed #{self.email} to MailChimp") if result + end + end diff --git a/app/views/products/product.pdf b/app/views/products/product.pdf new file mode 100644 index 0000000..dc92b8d Binary files /dev/null and b/app/views/products/product.pdf differ diff --git a/app/views/visitors/index.html.erb b/app/views/visitors/index.html.erb index 5854d00..38d0b7f 100644 --- a/app/views/visitors/index.html.erb +++ b/app/views/visitors/index.html.erb @@ -1,2 +1,13 @@
<%= link_to 'Users:', users_path %> <%= User.count %> registered
+<% if user_signed_in? %> + <% if current_user.admin? %> +<%= link_to 'User count:', users_path %> <%= User.count %>
+ <% else %> +