Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add gem for Rails support

  • Loading branch information...
commit 1c47559c2f30b49e5e625599dc81b2f33ae48217 1 parent c7b155f
@joefiorini joefiorini authored
View
9 support/rails/.gitignore
@@ -0,0 +1,9 @@
+.bundle/
+log/*.log
+pkg/
+test/dummy/db/*.sqlite3
+test/dummy/db/*.sqlite3-journal
+test/dummy/log/*.log
+test/dummy/tmp/
+test/dummy/.sass-cache
+vendor/bundle
View
14 support/rails/Gemfile
@@ -0,0 +1,14 @@
+source "https://rubygems.org"
+
+# Declare your gem's dependencies in ember_devise_simple_auth.gemspec.
+# Bundler will treat runtime dependencies like base dependencies, and
+# development dependencies will be added by default to the :development group.
+gemspec
+
+# Declare any dependencies that are still in development here instead of in
+# your gemspec. These might include edge Rails or gems from your path or
+# Git. Remember to move these dependencies to your gemspec before releasing
+# your gem to rubygems.org.
+
+# To use debugger
+# gem 'debugger'
View
88 support/rails/Gemfile.lock
@@ -0,0 +1,88 @@
+PATH
+ remote: .
+ specs:
+ ember_devise_simple_auth (0.0.1)
+ rails (~> 4.0.2)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actionmailer (4.0.3)
+ actionpack (= 4.0.3)
+ mail (~> 2.5.4)
+ actionpack (4.0.3)
+ activesupport (= 4.0.3)
+ builder (~> 3.1.0)
+ erubis (~> 2.7.0)
+ rack (~> 1.5.2)
+ rack-test (~> 0.6.2)
+ activemodel (4.0.3)
+ activesupport (= 4.0.3)
+ builder (~> 3.1.0)
+ activerecord (4.0.3)
+ activemodel (= 4.0.3)
+ activerecord-deprecated_finders (~> 1.0.2)
+ activesupport (= 4.0.3)
+ arel (~> 4.0.0)
+ activerecord-deprecated_finders (1.0.3)
+ activesupport (4.0.3)
+ i18n (~> 0.6, >= 0.6.4)
+ minitest (~> 4.2)
+ multi_json (~> 1.3)
+ thread_safe (~> 0.1)
+ tzinfo (~> 0.3.37)
+ arel (4.0.2)
+ atomic (1.1.15)
+ builder (3.1.4)
+ erubis (2.7.0)
+ hike (1.2.3)
+ i18n (0.6.9)
+ mail (2.5.4)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.25.1)
+ minitest (4.7.5)
+ multi_json (1.8.4)
+ polyglot (0.3.4)
+ rack (1.5.2)
+ rack-test (0.6.2)
+ rack (>= 1.0)
+ rails (4.0.3)
+ actionmailer (= 4.0.3)
+ actionpack (= 4.0.3)
+ activerecord (= 4.0.3)
+ activesupport (= 4.0.3)
+ bundler (>= 1.3.0, < 2.0)
+ railties (= 4.0.3)
+ sprockets-rails (~> 2.0.0)
+ railties (4.0.3)
+ actionpack (= 4.0.3)
+ activesupport (= 4.0.3)
+ rake (>= 0.8.7)
+ thor (>= 0.18.1, < 2.0)
+ rake (10.1.1)
+ sprockets (2.11.0)
+ hike (~> 1.2)
+ multi_json (~> 1.0)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sprockets-rails (2.0.1)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ sprockets (~> 2.8)
+ sqlite3 (1.3.9)
+ thor (0.18.1)
+ thread_safe (0.2.0)
+ atomic (>= 1.1.7, < 2)
+ tilt (1.4.1)
+ treetop (1.4.15)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.38)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ ember_devise_simple_auth!
+ sqlite3
View
20 support/rails/MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright 2014 YOURNAME
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
22 support/rails/README.md
@@ -0,0 +1,22 @@
+# EmberDeviseSimpleAuth
+
+Rails support for the [ember-devise-simple-auth](http://github.com/d-i/ember-devise-simple-auth) plugin.
+
+## What it does
+
+This gem enhances the stock `Devise::SessionsController` to be slightly more ajax friendly. This means two things:
+
+1. Supports json responses by adding `respond_to :json`
+2. Renders new CSRF tokens in response headers ([see why?][why_csrf_tokens])
+
+## Why it does this
+
+### Why support JSON?
+
+APIs speak JSON better than HTML. It's just that simple.
+
+### Why CSRF tokens?
+
+Devise _really_, _really_ wants to do redirects after you sign in and sign out. This is because Rails creates new CSRF tokens every time you POST/DELETE. Most JavaScript solutions with Rails already write the CSRF token to a meta tag. This gem renders those new tokens in response headers when they change on sign in/sign out. On the Ember side, the plugin will take those headers and rewrite them to the meta tag.
+
+[&copy;2014 D-I](http://www.d-i.co)
View
34 support/rails/Rakefile
@@ -0,0 +1,34 @@
+begin
+ require 'bundler/setup'
+rescue LoadError
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
+end
+
+require 'rdoc/task'
+
+RDoc::Task.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'EmberDeviseSimpleAuth'
+ rdoc.options << '--line-numbers'
+ rdoc.rdoc_files.include('README.rdoc')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
+load 'rails/tasks/engine.rake'
+
+
+
+Bundler::GemHelper.install_tasks
+
+require 'rake/testtask'
+
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = false
+end
+
+
+task default: :test
View
25 support/rails/app/controllers/ember_devise_simple_auth/sessions_controller.rb
@@ -0,0 +1,25 @@
+class EmberDeviseSimpleAuth::SessionsController < Devise::SessionsController
+ respond_to :html, :json
+
+ after_action :set_csrf_headers, only: [:create, :destroy]
+
+ before_filter :authenticate_user!, only: [:show]
+
+ def show
+ authenticate_user! force: true
+ render json: current_user
+ end
+
+ protected
+
+ def set_csrf_headers
+ if request.xhr?
+ response.headers['X-CSRF-Token'] = "#{form_authenticity_token}"
+ response.headers['X-CSRF-Param'] = "#{request_forgery_protection_token}"
+ end
+ end
+
+end
+
+
+
View
8 support/rails/bin/rails
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
+
+ENGINE_ROOT = File.expand_path('../..', __FILE__)
+ENGINE_PATH = File.expand_path('../../lib/ember_devise_simple_auth/engine', __FILE__)
+
+require 'rails/all'
+require 'rails/engine/commands'
View
22 support/rails/ember_devise_simple_auth.gemspec
@@ -0,0 +1,22 @@
+$:.push File.expand_path("../lib", __FILE__)
+
+# Maintain your gem's version:
+require "ember_devise_simple_auth/version"
+
+# Describe your gem and declare its dependencies:
+Gem::Specification.new do |s|
+ s.name = "ember_devise_simple_auth"
+ s.version = EmberDeviseSimpleAuth::VERSION
+ s.authors = ["TODO: Your name"]
+ s.email = ["TODO: Your email"]
+ s.homepage = "TODO"
+ s.summary = "TODO: Summary of EmberDeviseSimpleAuth."
+ s.description = "TODO: Description of EmberDeviseSimpleAuth."
+
+ s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
+ s.test_files = Dir["test/**/*"]
+
+ s.add_dependency "rails", "~> 4.0.2"
+
+ s.add_development_dependency "sqlite3"
+end
View
4 support/rails/lib/ember_devise_simple_auth.rb
@@ -0,0 +1,4 @@
+require "ember_devise_simple_auth/engine"
+
+module EmberDeviseSimpleAuth
+end
View
5 support/rails/lib/ember_devise_simple_auth/engine.rb
@@ -0,0 +1,5 @@
+module EmberDeviseSimpleAuth
+ class Engine < ::Rails::Engine
+ isolate_namespace EmberDeviseSimpleAuth
+ end
+end
View
3  support/rails/lib/ember_devise_simple_auth/version.rb
@@ -0,0 +1,3 @@
+module EmberDeviseSimpleAuth
+ VERSION = "0.0.1"
+end
View
8 support/rails/lib/generators/ember_devise_simple_auth/USAGE
@@ -0,0 +1,8 @@
+Description:
+ Explain the generator
+
+Example:
+ rails generate install Thing
+
+ This will create:
+ what/will/it/create
View
19 support/rails/lib/generators/ember_devise_simple_auth/install_generator.rb
@@ -0,0 +1,19 @@
+module EmberDeviseSimpleAuth
+ class InstallGenerator < Rails::Generators::Base
+ source_root File.expand_path('../templates', __FILE__)
+
+ def install_devise_routes
+
+ route_addition = "devise_scope :user do"
+ route_addition << %Q(\n get "/sessions/current" => "ember_devise_simple_auth/sessions#show")
+ route_addition << %Q(\n end\n)
+ route route_addition
+
+ gsub_file "config/routes.rb",
+ "devise_for :users",
+ "devise_for :users, controllers: { sessions: 'ember_devise_simple_auth/sessions' }"
+
+ end
+
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.