monban 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +149 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +65 -0
  6. data/Rakefile +6 -0
  7. data/lib/generators/monban/controllers/controllers_generator.rb +30 -0
  8. data/lib/generators/monban/scaffold/scaffold_generator.rb +42 -0
  9. data/lib/generators/monban/templates/app/controllers/sessions_controller.rb +30 -0
  10. data/lib/generators/monban/templates/app/controllers/users_controller.rb +26 -0
  11. data/lib/generators/monban/templates/app/models/user.rb +7 -0
  12. data/lib/generators/monban/templates/app/views/sessions/new.html.erb +13 -0
  13. data/lib/generators/monban/templates/app/views/users/new.html.erb +13 -0
  14. data/lib/generators/monban/templates/db/migrate/create_users.rb +10 -0
  15. data/lib/generators/monban/templates/scaffold_readme +4 -0
  16. data/lib/monban.rb +38 -0
  17. data/lib/monban/configuration.rb +27 -0
  18. data/lib/monban/controller_helpers.rb +56 -0
  19. data/lib/monban/controller_helpers/authentication.rb +26 -0
  20. data/lib/monban/controller_helpers/sign_in.rb +12 -0
  21. data/lib/monban/controller_helpers/sign_out.rb +11 -0
  22. data/lib/monban/controller_helpers/sign_up.rb +23 -0
  23. data/lib/monban/field_map.rb +38 -0
  24. data/lib/monban/railtie.rb +9 -0
  25. data/lib/monban/strategies/password_strategy.rb +15 -0
  26. data/lib/monban/version.rb +3 -0
  27. data/lib/monban/warden_setup.rb +11 -0
  28. data/monban.gemspec +29 -0
  29. data/spec/features/visitor/visitor_signs_up_spec.rb +12 -0
  30. data/spec/monban/controller_helpers/authentication_spec.rb +25 -0
  31. data/spec/monban/controller_helpers/sign_in_spec.rb +12 -0
  32. data/spec/monban/controller_helpers/sign_out_spec.rb +11 -0
  33. data/spec/monban/controller_helpers/sign_up_spec.rb +17 -0
  34. data/spec/monban/controller_helpers_spec.rb +124 -0
  35. data/spec/monban/field_map_spec.rb +18 -0
  36. data/spec/monban_spec.rb +7 -0
  37. data/spec/rails_app/Rakefile +7 -0
  38. data/spec/rails_app/app/assets/images/rails.png +0 -0
  39. data/spec/rails_app/app/assets/javascripts/application.js +13 -0
  40. data/spec/rails_app/app/assets/stylesheets/application.css +13 -0
  41. data/spec/rails_app/app/controllers/application_controller.rb +4 -0
  42. data/spec/rails_app/app/controllers/posts_controller.rb +7 -0
  43. data/spec/rails_app/app/controllers/sessions_controller.rb +18 -0
  44. data/spec/rails_app/app/controllers/users_controller.rb +15 -0
  45. data/spec/rails_app/app/helpers/application_helper.rb +2 -0
  46. data/spec/rails_app/app/models/user.rb +4 -0
  47. data/spec/rails_app/app/views/layouts/application.html.erb +14 -0
  48. data/spec/rails_app/app/views/users/new.html.erb +5 -0
  49. data/spec/rails_app/config.ru +4 -0
  50. data/spec/rails_app/config/application.rb +58 -0
  51. data/spec/rails_app/config/boot.rb +6 -0
  52. data/spec/rails_app/config/database.yml +25 -0
  53. data/spec/rails_app/config/environment.rb +5 -0
  54. data/spec/rails_app/config/environments/development.rb +29 -0
  55. data/spec/rails_app/config/environments/production.rb +54 -0
  56. data/spec/rails_app/config/environments/test.rb +29 -0
  57. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  58. data/spec/rails_app/config/initializers/inflections.rb +15 -0
  59. data/spec/rails_app/config/initializers/secret_token.rb +7 -0
  60. data/spec/rails_app/config/routes.rb +8 -0
  61. data/spec/rails_app/db/seeds.rb +7 -0
  62. data/spec/rails_app/public/404.html +26 -0
  63. data/spec/rails_app/public/422.html +26 -0
  64. data/spec/rails_app/public/500.html +25 -0
  65. data/spec/rails_app/public/favicon.ico +0 -0
  66. data/spec/rails_app/script/rails +6 -0
  67. data/spec/spec_helper.rb +7 -0
  68. metadata +299 -0
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ module Monban
4
+ describe FieldMap do
5
+ it 'returns the params without a field map' do
6
+ params = double()
7
+ field_map = FieldMap.new(params, nil)
8
+ expect(field_map.to_fields).to eq(params)
9
+ end
10
+
11
+ it 'returns mapped params with a field map' do
12
+ params = { email_or_username: 'foo' }
13
+ map = { email_or_username: [:email, :username] }
14
+ field_map = FieldMap.new(params, map)
15
+ expect(field_map.to_fields).to eq(["email = ? OR username = ?", 'foo', 'foo'])
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Monban' do
4
+ it "stores the warden config" do
5
+ expect(Monban.warden_config).to be_a Warden::Config
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ RailsApp::Application.load_tasks
@@ -0,0 +1,13 @@
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
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
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_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ class ApplicationController < ActionController::Base
2
+ include Monban::ControllerHelpers
3
+ protect_from_forgery
4
+ end
@@ -0,0 +1,7 @@
1
+ class PostsController < ApplicationController
2
+ before_filter :require_login
3
+
4
+ def index
5
+ render nothing: true
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ class SessionsController < ApplicationController
2
+ def new; end
3
+
4
+ def create
5
+ user = User.find_by_email(params[:session][:email])
6
+
7
+ if authenticate(user, params[:session][:password])
8
+ sign_in user
9
+ else
10
+ redirect_to root_path, notice: "Invalid email or password"
11
+ end
12
+ end
13
+
14
+ def destroy
15
+ sign_out
16
+ redirect_to root_path
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ class UsersController < ApplicationController
2
+ def new
3
+ @user = User.new
4
+ end
5
+
6
+ def create
7
+ @user = sign_up(params[:user])
8
+ if @user
9
+ sign_in(@user)
10
+ redirect_to posts_path
11
+ else
12
+ render :new
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,4 @@
1
+ require 'active_hash'
2
+ class User < ActiveHash::Base
3
+ attr_accessor :email, :password_digest, :password
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>RailsApp</title>
5
+ <%= stylesheet_link_tag "application", :media => "all" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,5 @@
1
+ <%= form_for @user do |f| %>
2
+ <%= f.text_field :email %>
3
+ <%= f.text_field :password %>
4
+ <%= f.submit 'go' %>
5
+ <% end %>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run RailsApp::Application
@@ -0,0 +1,58 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ # require "action_mailer/railtie"
7
+ # require "active_resource/railtie"
8
+ # require "sprockets/railtie"
9
+ # require "rails/test_unit/railtie"
10
+
11
+ if defined?(Bundler)
12
+ # If you precompile assets before deploying to production, use this line
13
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
14
+ # If you want your assets lazily compiled in production, use this line
15
+ # Bundler.require(:default, :assets, Rails.env)
16
+ end
17
+
18
+ require 'monban'
19
+
20
+ module RailsApp
21
+ class Application < Rails::Application
22
+ # Settings in config/environments/* take precedence over those specified here.
23
+ # Application configuration should go into files in config/initializers
24
+ # -- all .rb files in that directory are automatically loaded.
25
+
26
+ # Custom directories with classes and modules you want to be autoloadable.
27
+ # config.autoload_paths += %W(#{config.root}/extras)
28
+
29
+ # Only load the plugins named here, in the order given (default is alphabetical).
30
+ # :all can be used as a placeholder for all plugins not explicitly named.
31
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
32
+
33
+ # Activate observers that should always be running.
34
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
35
+
36
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
37
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
38
+ # config.time_zone = 'Central Time (US & Canada)'
39
+
40
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
41
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
42
+ # config.i18n.default_locale = :de
43
+
44
+ # Configure the default encoding used in templates for Ruby 1.9.
45
+ config.encoding = "utf-8"
46
+
47
+ # Configure sensitive parameters which will be filtered from the log file.
48
+ config.filter_parameters += [:password]
49
+
50
+ # Enable escaping HTML in JSON.
51
+ config.active_support.escape_html_entities_in_json = true
52
+
53
+ # Use SQL instead of Active Record's schema dumper when creating the database.
54
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
55
+ # like if you have constraints or database-specific column types
56
+ # config.active_record.schema_format = :sql
57
+ end
58
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ RailsApp::Application.initialize!
@@ -0,0 +1,29 @@
1
+ RailsApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Print deprecation notices to the Rails logger
17
+ config.active_support.deprecation = :log
18
+
19
+ # Only use best-standards-support built into browsers
20
+ config.action_dispatch.best_standards_support = :builtin
21
+
22
+ # Raise exception on mass assignment protection for Active Record models
23
+ config.active_record.mass_assignment_sanitizer = :strict
24
+
25
+ # Log the query plan for queries taking more than this (works
26
+ # with SQLite, MySQL, and PostgreSQL)
27
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
28
+
29
+ end
@@ -0,0 +1,54 @@
1
+ RailsApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+
11
+ # Disable Rails's static asset server (Apache or nginx will already do this)
12
+ config.serve_static_assets = false
13
+
14
+
15
+ # Specifies the header that your server uses for sending files
16
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
17
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
18
+
19
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
20
+ # config.force_ssl = true
21
+
22
+ # See everything in the log (default is :info)
23
+ # config.log_level = :debug
24
+
25
+ # Prepend all log lines with the following tags
26
+ # config.log_tags = [ :subdomain, :uuid ]
27
+
28
+ # Use a different logger for distributed setups
29
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
30
+
31
+ # Use a different cache store in production
32
+ # config.cache_store = :mem_cache_store
33
+
34
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
35
+ # config.action_controller.asset_host = "http://assets.example.com"
36
+
37
+
38
+ # Disable delivery errors, bad email addresses will be ignored
39
+ # config.action_mailer.raise_delivery_errors = false
40
+
41
+ # Enable threaded mode
42
+ # config.threadsafe!
43
+
44
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
45
+ # the I18n.default_locale when a translation can not be found)
46
+ config.i18n.fallbacks = true
47
+
48
+ # Send deprecation notices to registered listeners
49
+ config.active_support.deprecation = :notify
50
+
51
+ # Log the query plan for queries taking more than this (works
52
+ # with SQLite, MySQL, and PostgreSQL)
53
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
54
+ end
@@ -0,0 +1,29 @@
1
+ RailsApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Configure static asset server for tests with Cache-Control for performance
11
+ config.serve_static_assets = true
12
+ config.static_cache_control = "public, max-age=3600"
13
+
14
+ # Log error messages when you accidentally call methods on nil
15
+ config.whiny_nils = true
16
+
17
+ # Show full error reports and disable caching
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ # Raise exceptions instead of rendering exception templates
22
+ config.action_dispatch.show_exceptions = false
23
+
24
+ # Disable request forgery protection in test environment
25
+ config.action_controller.allow_forgery_protection = false
26
+
27
+ # Print deprecation notices to the stderr
28
+ config.active_support.deprecation = :stderr
29
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,15 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
11
+ #
12
+ # These inflection rules are supported but not enabled by default:
13
+ # ActiveSupport::Inflector.inflections do |inflect|
14
+ # inflect.acronym 'RESTful'
15
+ # end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ RailsApp::Application.config.secret_token = '840b3262c6147ca69157ebd545ff37817922cd1315d688d7ec3a864629ae89398604efeca261c8e40273b0306dbcf5c7f609f7b0dd4d12d213f1d6bd3dc169db'
@@ -0,0 +1,8 @@
1
+ RailsApp::Application.routes.draw do
2
+ resources :posts, only: [:index]
3
+ resources :users, only: [:create]
4
+ get "sign_in" => "sessions#new"
5
+ post "sign_in" => "sessions#create"
6
+ delete "sign_out" => "sessions#destroy"
7
+ get "sign_up" => "users#new"
8
+ end
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7
+ # Mayor.create(name: 'Emanuel', city: cities.first)
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>