ember_auth_rails 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +47 -0
  3. data/Gemfile.lock +219 -0
  4. data/Guardfile +33 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +65 -0
  7. data/Rakefile +67 -0
  8. data/VERSION +1 -0
  9. data/app/assets/images/ember_auth_rails/.gitkeep +0 -0
  10. data/app/assets/javascripts/ember_auth_rails/.gitkeep +0 -0
  11. data/app/assets/stylesheets/ember_auth_rails/.gitkeep +0 -0
  12. data/app/controllers/.gitkeep +0 -0
  13. data/app/controllers/ember_users_controller.rb +32 -0
  14. data/app/controllers/registrations_controller.rb +3 -0
  15. data/app/controllers/sessions_controller.rb +43 -0
  16. data/app/helpers/.gitkeep +0 -0
  17. data/app/helpers/ember_auth_helper.rb +2 -0
  18. data/app/mailers/.gitkeep +0 -0
  19. data/app/models/.gitkeep +0 -0
  20. data/app/models/ember_auth_rails/user_mod.rb +17 -0
  21. data/app/models/user.rb +3 -0
  22. data/app/serializers/user_serializer.rb +3 -0
  23. data/app/views/.gitkeep +0 -0
  24. data/config/initializers/devise.rb +241 -0
  25. data/config/routes.rb +15 -0
  26. data/db/migrate/20130601155410_devise_create_users.rb +46 -0
  27. data/db/migrate/20130601155411_user_auth_token.rb +9 -0
  28. data/ember_auth_rails.gemspec +176 -0
  29. data/lib/ember_auth_rails.rb +7 -0
  30. data/lib/ember_auth_rails/engine.rb +16 -0
  31. data/lib/ember_auth_rails/version.rb +3 -0
  32. data/lib/tasks/ember_auth_rails_tasks.rake +4 -0
  33. data/script/rails +8 -0
  34. data/spec/controllers/ember_users_controller_spec.rb +28 -0
  35. data/spec/controllers/sessions_controller_spec.rb +45 -0
  36. data/spec/controllers/widgets_controller_spec.rb +27 -0
  37. data/spec/dummy/.env +2 -0
  38. data/spec/dummy/README.rdoc +261 -0
  39. data/spec/dummy/Rakefile +7 -0
  40. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  41. data/spec/dummy/app/assets/javascripts/widgets.js +2 -0
  42. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  43. data/spec/dummy/app/assets/stylesheets/widgets.css +4 -0
  44. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  45. data/spec/dummy/app/controllers/widgets_controller.rb +8 -0
  46. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  47. data/spec/dummy/app/helpers/widgets_helper.rb +2 -0
  48. data/spec/dummy/app/mailers/.gitkeep +0 -0
  49. data/spec/dummy/app/models/.gitkeep +0 -0
  50. data/spec/dummy/app/models/widget.rb +4 -0
  51. data/spec/dummy/app/serializers/widget_serializer.rb +3 -0
  52. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  53. data/spec/dummy/app/views/widgets/index.html.haml +1 -0
  54. data/spec/dummy/config.ru +4 -0
  55. data/spec/dummy/config/application.rb +59 -0
  56. data/spec/dummy/config/boot.rb +10 -0
  57. data/spec/dummy/config/database.yml +25 -0
  58. data/spec/dummy/config/environment.rb +5 -0
  59. data/spec/dummy/config/environments/development.rb +37 -0
  60. data/spec/dummy/config/environments/production.rb +67 -0
  61. data/spec/dummy/config/environments/test.rb +37 -0
  62. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  63. data/spec/dummy/config/initializers/inflections.rb +15 -0
  64. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  65. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  66. data/spec/dummy/config/initializers/session_store.rb +8 -0
  67. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  68. data/spec/dummy/config/locales/en.yml +5 -0
  69. data/spec/dummy/config/routes.rb +61 -0
  70. data/spec/dummy/db/migrate/20130703135528_create_users.multiauth_engine.rb +47 -0
  71. data/spec/dummy/db/migrate/20130703135529_create_identities.multiauth_engine.rb +14 -0
  72. data/spec/dummy/db/migrate/20130703136445_user_auth_token.ember_auth_rails_engine.rb +10 -0
  73. data/spec/dummy/db/migrate/20130703142306_create_widgets.rb +10 -0
  74. data/spec/dummy/db/schema.rb +54 -0
  75. data/spec/dummy/db/seeds.rb +10 -0
  76. data/spec/dummy/lib/assets/.gitkeep +0 -0
  77. data/spec/dummy/log/.gitkeep +0 -0
  78. data/spec/dummy/public/404.html +26 -0
  79. data/spec/dummy/public/422.html +26 -0
  80. data/spec/dummy/public/500.html +25 -0
  81. data/spec/dummy/public/favicon.ico +0 -0
  82. data/spec/dummy/script/rails +6 -0
  83. data/spec/spec_helper.rb +33 -0
  84. data/spec/support/devise.rb +3 -0
  85. data/spec/support/make_user.rb +21 -0
  86. data/test/ember_auth_rails_test.rb +7 -0
  87. data/test/integration/navigation_test.rb +10 -0
  88. data/test/test_helper.rb +15 -0
  89. metadata +383 -0
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
File without changes
@@ -0,0 +1,32 @@
1
+ class EmberUsersController < ApplicationController
2
+ before_filter :authenticate_user!
3
+
4
+ def get_user_by_ident(ident)
5
+ raise "no user ident" unless ident.present?
6
+ if ident.to_s.length >= 10
7
+ User.where(:authentication_token => ident).first
8
+ else
9
+ User.find(ident)
10
+ end
11
+ end
12
+
13
+ def show
14
+ Rails.logger.info "EmberUsers#show getting user #{params[:id]}"
15
+ @user = get_user_by_ident(params[:id])
16
+ raise "no user found for #{params[:id]}" unless @user
17
+ render :json => @user
18
+ end
19
+
20
+ def update
21
+ pu = params[:user] || {}
22
+ @user = get_user_by_ident(params[:id])
23
+ new_password = pu[:password]
24
+ raise "no password" unless new_password.present?
25
+ @user.password = new_password
26
+ if @user.save
27
+ render :json => @user
28
+ else
29
+ render :json => {:error => "Password " + @user.errors.values.flatten.join(", ")}
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ class RegistrationsController < Devise::RegistrationsController
2
+ respond_to :json
3
+ end
@@ -0,0 +1,43 @@
1
+ class SessionsController < Devise::SessionsController
2
+ def index
3
+ render :text => "Sup Index"
4
+ end
5
+ def show
6
+ render :text => "Sup Show"
7
+ end
8
+
9
+ before_filter "setup_user_params!"
10
+
11
+ def setup_user_params!
12
+ if params[:email]
13
+ params[:user] ||= {}
14
+ params[:user][:email] ||= params[:email]
15
+ params[:user][:password] ||= params[:password]
16
+ end
17
+ end
18
+ def create
19
+ authenticate_user!
20
+ resource = current_user
21
+ if current_user
22
+ render :json => {:auth_token => current_user.authentication_token, :user_id => current_user.id, :success => true}
23
+ else
24
+ pu = params[:user] || {}
25
+ render :status => 404, :json => {:status => "errorWHEEE", :email => pu[:email], :password => pu[:password]}
26
+ end
27
+ end
28
+
29
+ def destroy
30
+ raise "no user" unless current_user
31
+ res = sign_out current_user
32
+ render :json => {:success => true}
33
+ end
34
+
35
+ def failure
36
+ raise 'in failure'
37
+ return render:json => {:success => false, :errors => ["Login failed."]}
38
+ end
39
+
40
+ def options
41
+ head :ok
42
+ end
43
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ module EmberAuthHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1,17 @@
1
+ module EmberAuthRails
2
+ module UserMod
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ devise :database_authenticatable, :registerable,
7
+ :recoverable, :rememberable, :trackable, :validatable,
8
+ :token_authenticatable
9
+
10
+ validates_presence_of :email
11
+
12
+ before_save :ensure_authentication_token
13
+
14
+ attr_accessible :email, :password, :authentication_token
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ include EmberAuthRails::UserMod
3
+ end
@@ -0,0 +1,3 @@
1
+ class UserSerializer < ActiveModel::Serializer
2
+ attributes :id, :email, :authentication_token
3
+ end
File without changes
@@ -0,0 +1,241 @@
1
+ # Use this hook to configure devise mailer, warden hooks and so forth.
2
+ # Many of these configuration options can be set straight in your model.
3
+ Devise.setup do |config|
4
+ config.sign_out_via = :get
5
+ # ==> Mailer Configuration
6
+ # Configure the e-mail address which will be shown in Devise::Mailer,
7
+ # note that it will be overwritten if you use your own mailer class with default "from" parameter.
8
+ config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
9
+
10
+ # Configure the class responsible to send e-mails.
11
+ # config.mailer = "Devise::Mailer"
12
+
13
+ # ==> ORM configuration
14
+ # Load and configure the ORM. Supports :active_record (default) and
15
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
16
+ # available as additional gems.
17
+ require 'devise/orm/active_record'
18
+
19
+ # ==> Configuration for any authentication mechanism
20
+ # Configure which keys are used when authenticating a user. The default is
21
+ # just :email. You can configure it to use [:username, :subdomain], so for
22
+ # authenticating a user, both parameters are required. Remember that those
23
+ # parameters are used only when authenticating and not when retrieving from
24
+ # session. If you need permissions, you should implement that in a before filter.
25
+ # You can also supply a hash where the value is a boolean determining whether
26
+ # or not authentication should be aborted when the value is not present.
27
+ # config.authentication_keys = [ :email ]
28
+
29
+ # Configure parameters from the request object used for authentication. Each entry
30
+ # given should be a request method and it will automatically be passed to the
31
+ # find_for_authentication method and considered in your model lookup. For instance,
32
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
33
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
34
+ # config.request_keys = []
35
+
36
+ # Configure which authentication keys should be case-insensitive.
37
+ # These keys will be downcased upon creating or modifying a user and when used
38
+ # to authenticate or find a user. Default is :email.
39
+ config.case_insensitive_keys = [ :email ]
40
+
41
+ # Configure which authentication keys should have whitespace stripped.
42
+ # These keys will have whitespace before and after removed upon creating or
43
+ # modifying a user and when used to authenticate or find a user. Default is :email.
44
+ config.strip_whitespace_keys = [ :email ]
45
+
46
+ # Tell if authentication through request.params is enabled. True by default.
47
+ # It can be set to an array that will enable params authentication only for the
48
+ # given strategies, for example, `config.params_authenticatable = [:database]` will
49
+ # enable it only for database (email + password) authentication.
50
+ # config.params_authenticatable = true
51
+
52
+ # Tell if authentication through HTTP Basic Auth is enabled. False by default.
53
+ # It can be set to an array that will enable http authentication only for the
54
+ # given strategies, for example, `config.http_authenticatable = [:token]` will
55
+ # enable it only for token authentication.
56
+ # config.http_authenticatable = false
57
+
58
+ # If http headers should be returned for AJAX requests. True by default.
59
+ # config.http_authenticatable_on_xhr = true
60
+
61
+ # The realm used in Http Basic Authentication. "Application" by default.
62
+ # config.http_authentication_realm = "Application"
63
+
64
+ # It will change confirmation, password recovery and other workflows
65
+ # to behave the same regardless if the e-mail provided was right or wrong.
66
+ # Does not affect registerable.
67
+ # config.paranoid = true
68
+
69
+ # By default Devise will store the user in session. You can skip storage for
70
+ # :http_auth and :token_auth by adding those symbols to the array below.
71
+ # Notice that if you are skipping storage for all authentication paths, you
72
+ # may want to disable generating routes to Devise's sessions controller by
73
+ # passing :skip => :sessions to `devise_for` in your config/routes.rb
74
+ config.skip_session_storage = [:http_auth]
75
+
76
+ # ==> Configuration for :database_authenticatable
77
+ # For bcrypt, this is the cost for hashing the password and defaults to 10. If
78
+ # using other encryptors, it sets how many times you want the password re-encrypted.
79
+ #
80
+ # Limiting the stretches to just one in testing will increase the performance of
81
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
82
+ # a value less than 10 in other environments.
83
+ config.stretches = Rails.env.test? ? 1 : 10
84
+
85
+ # Setup a pepper to generate the encrypted password.
86
+ # config.pepper = "92d353b99f1d7047c3ada471b385033781457a93530222c5687e1cf082796cd8536c76b45c0b40d99de277f8d10d8e6836dcaba909b523638e8f83de4c1451a4"
87
+
88
+ # ==> Configuration for :confirmable
89
+ # A period that the user is allowed to access the website even without
90
+ # confirming his account. For instance, if set to 2.days, the user will be
91
+ # able to access the website for two days without confirming his account,
92
+ # access will be blocked just in the third day. Default is 0.days, meaning
93
+ # the user cannot access the website without confirming his account.
94
+ # config.allow_unconfirmed_access_for = 2.days
95
+
96
+ # A period that the user is allowed to confirm their account before their
97
+ # token becomes invalid. For example, if set to 3.days, the user can confirm
98
+ # their account within 3 days after the mail was sent, but on the fourth day
99
+ # their account can't be confirmed with the token any more.
100
+ # Default is nil, meaning there is no restriction on how long a user can take
101
+ # before confirming their account.
102
+ # config.confirm_within = 3.days
103
+
104
+ # If true, requires any email changes to be confirmed (exactly the same way as
105
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
106
+ # db field (see migrations). Until confirmed new email is stored in
107
+ # unconfirmed email column, and copied to email column on successful confirmation.
108
+ config.reconfirmable = true
109
+
110
+ # Defines which key will be used when confirming an account
111
+ # config.confirmation_keys = [ :email ]
112
+
113
+ # ==> Configuration for :rememberable
114
+ # The time the user will be remembered without asking for credentials again.
115
+ # config.remember_for = 2.weeks
116
+
117
+ # If true, extends the user's remember period when remembered via cookie.
118
+ # config.extend_remember_period = false
119
+
120
+ # Options to be passed to the created cookie. For instance, you can set
121
+ # :secure => true in order to force SSL only cookies.
122
+ # config.rememberable_options = {}
123
+
124
+ # ==> Configuration for :validatable
125
+ # Range for password length. Default is 8..128.
126
+ config.password_length = 8..128
127
+
128
+ # Email regex used to validate email formats. It simply asserts that
129
+ # an one (and only one) @ exists in the given string. This is mainly
130
+ # to give user feedback and not to assert the e-mail validity.
131
+ # config.email_regexp = /\A[^@]+@[^@]+\z/
132
+
133
+ # ==> Configuration for :timeoutable
134
+ # The time you want to timeout the user session without activity. After this
135
+ # time the user will be asked for credentials again. Default is 30 minutes.
136
+ # config.timeout_in = 30.minutes
137
+
138
+ # If true, expires auth token on session timeout.
139
+ # config.expire_auth_token_on_timeout = false
140
+
141
+ # ==> Configuration for :lockable
142
+ # Defines which strategy will be used to lock an account.
143
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
144
+ # :none = No lock strategy. You should handle locking by yourself.
145
+ # config.lock_strategy = :failed_attempts
146
+
147
+ # Defines which key will be used when locking and unlocking an account
148
+ # config.unlock_keys = [ :email ]
149
+
150
+ # Defines which strategy will be used to unlock an account.
151
+ # :email = Sends an unlock link to the user email
152
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
153
+ # :both = Enables both strategies
154
+ # :none = No unlock strategy. You should handle unlocking by yourself.
155
+ # config.unlock_strategy = :both
156
+
157
+ # Number of authentication tries before locking an account if lock_strategy
158
+ # is failed attempts.
159
+ # config.maximum_attempts = 20
160
+
161
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
162
+ # config.unlock_in = 1.hour
163
+
164
+ # ==> Configuration for :recoverable
165
+ #
166
+ # Defines which key will be used when recovering the password for an account
167
+ # config.reset_password_keys = [ :email ]
168
+
169
+ # Time interval you can reset your password with a reset password key.
170
+ # Don't put a too small interval or your users won't have the time to
171
+ # change their passwords.
172
+ config.reset_password_within = 6.hours
173
+
174
+ # ==> Configuration for :encryptable
175
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
176
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
177
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
178
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
179
+ # REST_AUTH_SITE_KEY to pepper)
180
+ # config.encryptor = :sha512
181
+
182
+ # ==> Configuration for :token_authenticatable
183
+ # Defines name of the authentication token params key
184
+ # config.token_authentication_key = :auth_token
185
+
186
+ # ==> Scopes configuration
187
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
188
+ # "users/sessions/new". It's turned off by default because it's slower if you
189
+ # are using only default views.
190
+ # config.scoped_views = false
191
+
192
+ # Configure the default scope given to Warden. By default it's the first
193
+ # devise role declared in your routes (usually :user).
194
+ # config.default_scope = :user
195
+
196
+ # Set this configuration to false if you want /users/sign_out to sign out
197
+ # only the current scope. By default, Devise signs out all scopes.
198
+ # config.sign_out_all_scopes = true
199
+
200
+ # ==> Navigation configuration
201
+ # Lists the formats that should be treated as navigational. Formats like
202
+ # :html, should redirect to the sign in page when the user does not have
203
+ # access, but formats like :xml or :json, should return 401.
204
+ #
205
+ # If you have any extra navigational formats, like :iphone or :mobile, you
206
+ # should add them to the navigational formats lists.
207
+ #
208
+ # The "*/*" below is required to match Internet Explorer requests.
209
+ # config.navigational_formats = ["*/*", :html]
210
+
211
+ # The default HTTP method used to sign out a resource. Default is :delete.
212
+ config.sign_out_via = :delete
213
+
214
+ # ==> OmniAuth
215
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
216
+ # up on your models and hooks.
217
+ # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
218
+
219
+ # ==> Warden configuration
220
+ # If you want to use other strategies, that are not supported by Devise, or
221
+ # change the failure app, you can configure them inside the config.warden block.
222
+ #
223
+ # config.warden do |manager|
224
+ # manager.intercept_401 = false
225
+ # manager.default_strategies(:scope => :user).unshift :some_external_strategy
226
+ # end
227
+
228
+ # ==> Mountable engine configurations
229
+ # When using Devise inside an engine, let's call it `MyEngine`, and this engine
230
+ # is mountable, there are some extra configurations to be taken into account.
231
+ # The following options are available, assuming the engine is mounted as:
232
+ #
233
+ # mount MyEngine, at: "/my_engine"
234
+ #
235
+ # The router that invoked `devise_for`, in the example above, would be:
236
+ # config.router_name = :my_engine
237
+ #
238
+ # When using omniauth, Devise cannot automatically set Omniauth path,
239
+ # so you need to do it manually. For the users scope, it would be:
240
+ # config.omniauth_path_prefix = "/my_engine/users/auth"
241
+ end
@@ -0,0 +1,15 @@
1
+ Rails.application.routes.draw do
2
+ resources :ember_users
3
+ devise_for :users, :controllers => {
4
+ :sessions => 'sessions',
5
+ :registrations => 'registrations',
6
+ :omniauth_callbacks => "users/omniauth_callbacks"
7
+ }
8
+
9
+ devise_scope :user do
10
+ get 'logout' => 'sessions#destroy'
11
+ end
12
+
13
+ get "users/:id", to: "ember_users#show"
14
+ get "users/:id.json", to: "ember_users#show"
15
+ end
@@ -0,0 +1,46 @@
1
+ class DeviseCreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table(:users) do |t|
4
+ ## Database authenticatable
5
+ t.string :email, :null => false, :default => ""
6
+ t.string :encrypted_password, :null => false, :default => ""
7
+
8
+ ## Recoverable
9
+ t.string :reset_password_token
10
+ t.datetime :reset_password_sent_at
11
+
12
+ ## Rememberable
13
+ t.datetime :remember_created_at
14
+
15
+ ## Trackable
16
+ t.integer :sign_in_count, :default => 0
17
+ t.datetime :current_sign_in_at
18
+ t.datetime :last_sign_in_at
19
+ t.string :current_sign_in_ip
20
+ t.string :last_sign_in_ip
21
+
22
+ ## Confirmable
23
+ # t.string :confirmation_token
24
+ # t.datetime :confirmed_at
25
+ # t.datetime :confirmation_sent_at
26
+ # t.string :unconfirmed_email # Only if using reconfirmable
27
+
28
+ ## Lockable
29
+ # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
30
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
31
+ # t.datetime :locked_at
32
+
33
+ ## Token authenticatable
34
+ # t.string :authentication_token
35
+
36
+
37
+ t.timestamps
38
+ end
39
+
40
+ add_index :users, :email, :unique => true
41
+ add_index :users, :reset_password_token, :unique => true
42
+ # add_index :users, :confirmation_token, :unique => true
43
+ # add_index :users, :unlock_token, :unique => true
44
+ # add_index :users, :authentication_token, :unique => true
45
+ end
46
+ end
@@ -0,0 +1,9 @@
1
+ class UserAuthToken < ActiveRecord::Migration
2
+ def up
3
+ add_column :users, :authentication_token, :string
4
+ User.all.each { |x| x.save! }
5
+ end
6
+
7
+ def down
8
+ end
9
+ end