stormpath-rails 1.0.0.beta.2 → 1.1.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -19
  3. data/.rspec +0 -1
  4. data/.travis.yml +4 -23
  5. data/Gemfile +18 -0
  6. data/README.md +163 -73
  7. data/Rakefile +18 -3
  8. data/app/assets/stylesheets/stormpath.css.scss +283 -0
  9. data/app/controllers/stormpath/rails/base_controller.rb +10 -0
  10. data/app/controllers/stormpath/rails/omniauth_controller.rb +11 -0
  11. data/app/controllers/stormpath/rails/passwords_controller.rb +56 -0
  12. data/app/controllers/stormpath/rails/sessions_controller.rb +52 -0
  13. data/app/controllers/stormpath/rails/users_controller.rb +65 -0
  14. data/app/helpers/social_helper.rb +13 -0
  15. data/app/views/layouts/stormpath.html.erb +31 -0
  16. data/app/views/passwords/edit.html.erb +0 -0
  17. data/app/views/passwords/email_sent.html.erb +15 -0
  18. data/app/views/passwords/forgot.html.erb +33 -0
  19. data/app/views/passwords/forgot_change.html.erb +38 -0
  20. data/app/views/passwords/forgot_change_failed.html.erb +14 -0
  21. data/app/views/passwords/forgot_complete.html.erb +19 -0
  22. data/app/views/sessions/_facebook_login_form.erb +31 -0
  23. data/app/views/sessions/_form.html.erb +31 -0
  24. data/app/views/sessions/_google_login_form.html.erb +3 -0
  25. data/app/views/sessions/_social_auth.html.erb +7 -0
  26. data/app/views/sessions/new.html.erb +21 -0
  27. data/app/views/users/_form.html.erb +43 -0
  28. data/app/views/users/new.html.erb +10 -0
  29. data/app/views/users/verification_complete.html.erb +20 -0
  30. data/app/views/users/verification_email_sent.html.erb +15 -0
  31. data/app/views/users/verification_failed.html.erb +14 -0
  32. data/app/views/users/verification_resend.html.erb +14 -0
  33. data/bin/console +14 -0
  34. data/bin/rails +12 -0
  35. data/bin/rake +16 -0
  36. data/bin/rspec +16 -0
  37. data/bin/setup +8 -0
  38. data/config/initializers/assets.rb +1 -0
  39. data/config/routes.rb +16 -0
  40. data/lib/generators/stormpath/install/install_generator.rb +114 -0
  41. data/lib/generators/stormpath/install/templates/db/migrate/add_stormpath_to_users.rb +21 -0
  42. data/lib/generators/stormpath/install/templates/db/migrate/create_users.rb +12 -0
  43. data/lib/generators/stormpath/install/templates/stormpath.rb +4 -0
  44. data/lib/generators/stormpath/install/templates/user.rb +3 -0
  45. data/lib/generators/stormpath/routes/routes_generator.rb +23 -0
  46. data/lib/generators/stormpath/routes/templates/routes.rb +5 -0
  47. data/lib/generators/stormpath/views/USAGE +11 -0
  48. data/lib/generators/stormpath/views/views_generator.rb +29 -0
  49. data/lib/stormpath/rails/account.rb +2 -116
  50. data/lib/stormpath/rails/account_status.rb +28 -0
  51. data/lib/stormpath/rails/authentication.rb +72 -0
  52. data/lib/stormpath/rails/authentication_status.rb +22 -0
  53. data/lib/stormpath/rails/client.rb +73 -60
  54. data/lib/stormpath/rails/configuration.rb +56 -0
  55. data/lib/stormpath/rails/controller.rb +13 -0
  56. data/lib/stormpath/rails/engine.rb +6 -0
  57. data/lib/stormpath/rails/session.rb +37 -0
  58. data/lib/stormpath/rails/social.rb +34 -0
  59. data/lib/stormpath/rails/user.rb +25 -0
  60. data/lib/stormpath/rails/user_config/api_key.rb +17 -0
  61. data/lib/stormpath/rails/user_config/application.rb +12 -0
  62. data/lib/stormpath/rails/user_config/facebook.rb +16 -0
  63. data/lib/stormpath/rails/user_config/forgot_password.rb +12 -0
  64. data/lib/stormpath/rails/user_config/google.rb +16 -0
  65. data/lib/stormpath/rails/user_config/id_site.rb +13 -0
  66. data/lib/stormpath/rails/user_config/login.rb +13 -0
  67. data/lib/stormpath/rails/user_config/logout.rb +13 -0
  68. data/lib/stormpath/rails/user_config/register.rb +13 -0
  69. data/lib/stormpath/rails/user_config/verify_email.rb +14 -0
  70. data/lib/stormpath/rails/version.rb +1 -2
  71. data/lib/stormpath/rails.rb +32 -0
  72. data/lib/stormpath/testing/helpers.rb +49 -0
  73. data/lib/stormpath-rails.rb +6 -1
  74. data/stormpath-rails.gemspec +22 -28
  75. metadata +97 -256
  76. data/.ruby-gemset +0 -1
  77. data/.ruby-version +0 -1
  78. data/CHANGES.md +0 -19
  79. data/Guardfile +0 -23
  80. data/LICENSE.txt +0 -22
  81. data/lib/generators/stormpath/rails/migration/migration_generator.rb +0 -17
  82. data/lib/generators/stormpath/rails/templates/update_account_model.rb +0 -10
  83. data/lib/stormpath/rails/railtie.rb +0 -13
  84. data/spec/client_spec.rb +0 -222
  85. data/spec/generators/migration_generator_spec.rb +0 -19
  86. data/spec/integration/active_record_spec.rb +0 -23
  87. data/spec/integration/mongoid_spec.rb +0 -19
  88. data/spec/spec_helper.rb +0 -96
  89. data/spec/support/stormpath_account_shared_examples.rb +0 -212
@@ -0,0 +1,56 @@
1
+ module Stormpath
2
+ module Rails
3
+ class Configuration
4
+ attr_accessor :secret_key, :expand_custom_data, :user_model
5
+
6
+ def initialize
7
+ @expand_custom_data = true
8
+ end
9
+
10
+ def user_model
11
+ @user_model ||= ::User
12
+ end
13
+
14
+ [:login, :logout, :register, :id_site, :api_key, :application, :verify_email,
15
+ :forgot_password, :facebook, :google].each do |action|
16
+ define_method("#{action}=") do |options|
17
+ klass = user_config_class(action)
18
+ instance_variable_set("@#{action}", klass.new(options))
19
+ end
20
+
21
+ define_method("#{action}") do |&block|
22
+ action_value = instance_variable_get("@#{action}")
23
+
24
+ if action_value.nil?
25
+ klass = user_config_class(action)
26
+ instance_variable_set("@#{action}", klass.new())
27
+ end
28
+
29
+ if block
30
+ block.call(instance_variable_get("@#{action}"))
31
+ end
32
+
33
+ instance_variable_get("@#{action}")
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def user_config_class(action)
40
+ UserConfig.const_get(action.to_s.camelize)
41
+ end
42
+ end
43
+
44
+ # Return a single instance of Configuration class
45
+ # @return [Stormpath::Configuration] single instance
46
+ def self.config
47
+ @configuration ||= Configuration.new
48
+ end
49
+
50
+ # Configure the settings for this module
51
+ # @param [lambda] which will be passed isntance of configuration class
52
+ def self.configure
53
+ yield(config)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,13 @@
1
+ require 'stormpath/rails/authentication'
2
+
3
+ module Stormpath
4
+ module Rails
5
+ module Controller
6
+ extend ActiveSupport::Concern
7
+
8
+ include Stormpath::Rails::Authentication
9
+ include Stormpath::Rails::Session
10
+ include Stormpath::Rails::Social
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ module Stormpath
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,37 @@
1
+ module Stormpath
2
+ module Rails
3
+ module Session
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ helper_method :current_user, :signed_in?, :signed_out?
8
+ end
9
+
10
+ private
11
+
12
+ def initialize_session(user)
13
+ session[:user_id] = user.id
14
+ end
15
+
16
+ def reset_session
17
+ session[:user_id] = nil
18
+ end
19
+
20
+ def logout
21
+ reset_session
22
+ end
23
+
24
+ def signed_in?
25
+ !session[:user_id].nil?
26
+ end
27
+
28
+ def signed_out?
29
+ !signed_in?
30
+ end
31
+
32
+ def current_user
33
+ @current_user ||= configuration.user_model.find(session[:user_id]) if session[:user_id]
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,34 @@
1
+ module Stormpath
2
+ module Rails
3
+ module Social
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ helper_method :facebook_login_enabled?, :facebook_app_id,
8
+ :google_login_enabled?, :google_client_id, :social_auth?
9
+ end
10
+
11
+ private
12
+
13
+ def facebook_login_enabled?
14
+ configuration.facebook.enabled?
15
+ end
16
+
17
+ def google_login_enabled?
18
+ configuration.google.enabled?
19
+ end
20
+
21
+ def facebook_app_id
22
+ configuration.facebook.app_id
23
+ end
24
+
25
+ def google_client_id
26
+ configuration.google.client_id
27
+ end
28
+
29
+ def social_auth?
30
+ facebook_login_enabled? || google_login_enabled?
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ module Stormpath
2
+ module Rails
3
+ module User
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ attr_accessor :password
8
+
9
+ validates :email, presence: true, uniqueness: true
10
+ validates_presence_of :given_name
11
+ validates_presence_of :surname
12
+ end
13
+
14
+ module ClassMethods
15
+ def find_user(email)
16
+ find_by email: normalize_email(email)
17
+ end
18
+
19
+ def normalize_email(email)
20
+ email.to_s.downcase.gsub(/\s+/, "")
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ module Stormpath
2
+ module Rails
3
+ module UserConfig
4
+ class ApiKey
5
+ include Virtus.model
6
+
7
+ attribute :file, String
8
+ attribute :id, String
9
+ attribute :secret, String
10
+
11
+ def file_location_provided?
12
+ !self.file.nil?
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module Stormpath
2
+ module Rails
3
+ module UserConfig
4
+ class Application
5
+ include Virtus.model
6
+
7
+ attribute :name, String
8
+ attribute :href, String
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module Stormpath
2
+ module Rails
3
+ module UserConfig
4
+ class Facebook
5
+ include Virtus.model
6
+
7
+ attribute :app_id, String
8
+ attribute :app_secret, String
9
+
10
+ def enabled?
11
+ !(self.app_id.blank? && self.app_secret.blank?)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ module Stormpath
2
+ module Rails
3
+ module UserConfig
4
+ class ForgotPassword
5
+ include Virtus.model
6
+
7
+ attribute :enabled, Boolean, default: false
8
+ attribute :uri, String, default: '/forgot'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module Stormpath
2
+ module Rails
3
+ module UserConfig
4
+ class Google
5
+ include Virtus.model
6
+
7
+ attribute :client_id, String
8
+ attribute :client_secret, String
9
+
10
+ def enabled?
11
+ !(self.client_id.blank? && self.client_secret.blank?)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Stormpath
2
+ module Rails
3
+ module UserConfig
4
+ class IdSite
5
+ include Virtus.model
6
+
7
+ attribute :enabled, Boolean, default: false
8
+ attribute :uri, String, default: '/redirect'
9
+ attribute :next_uri, String, default: '/'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Stormpath
2
+ module Rails
3
+ module UserConfig
4
+ class Login
5
+ include Virtus.model
6
+
7
+ attribute :enabled, Boolean, default: true
8
+ attribute :uri, String, default: '/login'
9
+ attribute :next_uri, String, default: '/'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Stormpath
2
+ module Rails
3
+ module UserConfig
4
+ class Logout
5
+ include Virtus.model
6
+
7
+ attribute :enabled, Boolean, default: true
8
+ attribute :uri, String, default: '/login'
9
+ attribute :next_uri, String, default: '/'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Stormpath
2
+ module Rails
3
+ module UserConfig
4
+ class Register
5
+ include Virtus.model
6
+
7
+ attribute :enabled, Boolean, default: true
8
+ attribute :uri, String, default: '/register'
9
+ attribute :next_uri, String, default: '/'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module Stormpath
2
+ module Rails
3
+ module UserConfig
4
+ class VerifyEmail
5
+ include Virtus.model
6
+
7
+ attribute :enabled, Boolean, default: false
8
+ attribute :uri, String, default: '/verify'
9
+ attribute :next_uri, String
10
+ attribute :view, String
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,6 +1,5 @@
1
1
  module Stormpath
2
2
  module Rails
3
- VERSION = '1.0.0.beta.2'
4
- VERSION_DATE = '2013-08-13'
3
+ VERSION = "1.1.0.beta"
5
4
  end
6
5
  end
@@ -0,0 +1,32 @@
1
+ require 'stormpath-sdk'
2
+ require 'stormpath/rails/engine'
3
+ require 'stormpath/rails/configuration'
4
+ require 'virtus'
5
+
6
+ module Stormpath
7
+ module Rails
8
+ autoload :Client, 'stormpath/rails/client'
9
+ autoload :Authentication, 'stormpath/rails/authentication'
10
+ autoload :Session, 'stormpath/rails/session'
11
+ autoload :Controller, 'stormpath/rails/controller'
12
+ autoload :Account, 'stormpath/rails/account'
13
+ autoload :Version, 'stormpath/rails/version'
14
+ autoload :User, 'stormpath/rails/user'
15
+ autoload :AuthenticationStatus, 'stormpath/rails/authentication_status'
16
+ autoload :AccountStatus, 'stormpath/rails/account_status'
17
+ autoload :Social, 'stormpath/rails/social'
18
+
19
+ module UserConfig
20
+ autoload :ApiKey, 'stormpath/rails/user_config/api_key'
21
+ autoload :Application, 'stormpath/rails/user_config/application'
22
+ autoload :ForgotPassword, 'stormpath/rails/user_config/forgot_password'
23
+ autoload :IdSite, 'stormpath/rails/user_config/id_site'
24
+ autoload :VerifyEmail, 'stormpath/rails/user_config/verify_email'
25
+ autoload :Facebook, 'stormpath/rails/user_config/facebook'
26
+ autoload :Google, 'stormpath/rails/user_config/google'
27
+ autoload :Login, 'stormpath/rails/user_config/login'
28
+ autoload :Logout, 'stormpath/rails/user_config/logout'
29
+ autoload :Register, 'stormpath/rails/user_config/register'
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,49 @@
1
+ module Stormpath
2
+ module Testing
3
+ module Helpers
4
+ def sign_in
5
+ create_test_account
6
+ @controller.send(:authenticate, test_user)
7
+ @controller.send(:initialize_session, test_user)
8
+ test_user
9
+ end
10
+
11
+ def create_test_account
12
+ create_store_mapping
13
+ @test_account_result ||= Stormpath::Rails::Client.create_stormpath_account(test_user)
14
+ end
15
+
16
+ def delete_test_account
17
+ if @test_account_result && @test_account_result.success?
18
+ @test_account_result.response.delete
19
+ end
20
+ end
21
+
22
+ def test_user
23
+ factory = Stormpath::Rails.config.user_model.to_s.underscore.to_sym
24
+ @test_user ||= FactoryGirl.create(factory)
25
+ @test_user.attributes = @test_user.attributes.merge!("password" => @test_user.password)
26
+ @test_user
27
+ end
28
+
29
+ def create_test_directory
30
+ unless @test_directory
31
+ @test_directory ||= Stormpath::Rails::Client.client.directories.create(name: 'test-directory')
32
+ end
33
+ end
34
+
35
+ def delete_test_directory
36
+ @test_directory.delete if @test_directory
37
+ end
38
+
39
+ def create_store_mapping
40
+ @store_mapping ||= Stormpath::Rails::Client.client.account_store_mappings.create(
41
+ application: Stormpath::Rails::Client.application,
42
+ account_store: create_test_directory,
43
+ is_default_account_store: true,
44
+ is_default_group_store: true
45
+ )
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1 +1,6 @@
1
- Dir[File.join(File.dirname(__FILE__), "stormpath/**/*.rb")].sort.each {|f| require f}
1
+ require 'stormpath/rails'
2
+
3
+ module Stormpath
4
+ module Rails
5
+ end
6
+ end
@@ -1,36 +1,30 @@
1
+ # coding: utf-8
1
2
  lib = File.expand_path('../lib', __FILE__)
2
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
4
  require 'stormpath/rails/version'
4
5
 
5
- Gem::Specification.new do |gem|
6
- gem.name = 'stormpath-rails'
7
- gem.version = Stormpath::Rails::VERSION
8
- gem.date = Stormpath::Rails::VERSION_DATE
9
- gem.authors = ['Denis Grankin']
10
- gem.email = ['liquidautumn@gmail.com']
11
- gem.homepage = 'http://www.stormpath.com'
12
- gem.description = %q{Stormpath Rails integration}
13
- gem.summary = %q{Stormpath SDK API Wrapper}
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "stormpath-rails"
8
+ spec.version = Stormpath::Rails::VERSION
9
+ spec.authors = ["Nenad Nikolic"]
10
+ spec.email = ["nenad.nikolic@infinum.hr"]
14
11
 
15
- gem.add_dependency 'activesupport'
16
- gem.add_dependency 'stormpath-sdk', '1.0.0.beta.2'
12
+ spec.summary = %q{TODO: Write a short summary, because Rubygems requires one.}
13
+ spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = "TODO: Put your gem's website or public repo URL here."
17
15
 
18
- gem.files = `git ls-files`.split($/)
19
- gem.test_files = gem.files.grep(%r{^(spec|features)/})
20
- gem.require_paths = ['lib']
16
+ spec.summary = %q{Stormpath Rails integration}
17
+ spec.description = %q{Stormpath Rails integration}
18
+ spec.homepage = 'http://www.stormpath.com'
21
19
 
22
- gem.add_development_dependency('rails', '~> 3.2.13')
23
- gem.add_development_dependency('rake', '~> 10.0.2')
24
- gem.add_development_dependency('rspec', '~> 2.12.0')
25
- gem.add_development_dependency('generator_spec')
26
- gem.add_development_dependency('activerecord')
27
- gem.add_development_dependency('sqlite3')
28
- gem.add_development_dependency('mongoid')
29
- gem.add_development_dependency('railties')
30
- gem.add_development_dependency('guard-rspec', '~> 2.2.1')
31
- gem.add_development_dependency('simplecov', '~> 0.7.1')
32
- gem.add_development_dependency('webmock')
33
- gem.add_development_dependency('vcr')
34
- gem.add_development_dependency('pry')
35
- gem.add_development_dependency('pry-debugger')
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency 'stormpath-sdk', '>= 1.0.0.beta.8'
26
+ spec.add_dependency 'virtus'
27
+ spec.add_dependency 'rails', '>= 3.1'
28
+
29
+ spec.add_development_dependency "rake", "~> 10.0"
36
30
  end