aihs_devise 1.2.rc

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 (160) hide show
  1. data/CHANGELOG.rdoc +506 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +335 -0
  4. data/app/controllers/devise/confirmations_controller.rb +33 -0
  5. data/app/controllers/devise/oauth_callbacks_controller.rb +4 -0
  6. data/app/controllers/devise/passwords_controller.rb +41 -0
  7. data/app/controllers/devise/registrations_controller.rb +109 -0
  8. data/app/controllers/devise/sessions_controller.rb +24 -0
  9. data/app/controllers/devise/unlocks_controller.rb +34 -0
  10. data/app/helpers/devise_helper.rb +19 -0
  11. data/app/mailers/devise/mailer.rb +88 -0
  12. data/app/views/devise/confirmations/new.html.erb +12 -0
  13. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  14. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  15. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  16. data/app/views/devise/passwords/edit.html.erb +16 -0
  17. data/app/views/devise/passwords/new.html.erb +12 -0
  18. data/app/views/devise/registrations/edit.html.erb +25 -0
  19. data/app/views/devise/registrations/new.html.erb +18 -0
  20. data/app/views/devise/sessions/new.html.haml +18 -0
  21. data/app/views/devise/shared/_links.erb +25 -0
  22. data/app/views/devise/unlocks/new.html.erb +12 -0
  23. data/config/locales/en.yml +46 -0
  24. data/lib/devise.rb +372 -0
  25. data/lib/devise/controllers/helpers.rb +228 -0
  26. data/lib/devise/controllers/internal_helpers.rb +113 -0
  27. data/lib/devise/controllers/scoped_views.rb +33 -0
  28. data/lib/devise/controllers/url_helpers.rb +39 -0
  29. data/lib/devise/encryptors/authlogic_sha512.rb +19 -0
  30. data/lib/devise/encryptors/base.rb +20 -0
  31. data/lib/devise/encryptors/clearance_sha1.rb +17 -0
  32. data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  33. data/lib/devise/encryptors/sha1.rb +25 -0
  34. data/lib/devise/encryptors/sha512.rb +25 -0
  35. data/lib/devise/failure_app.rb +126 -0
  36. data/lib/devise/hooks/activatable.rb +11 -0
  37. data/lib/devise/hooks/forgetable.rb +12 -0
  38. data/lib/devise/hooks/rememberable.rb +45 -0
  39. data/lib/devise/hooks/timeoutable.rb +22 -0
  40. data/lib/devise/hooks/trackable.rb +9 -0
  41. data/lib/devise/mapping.rb +105 -0
  42. data/lib/devise/models.rb +66 -0
  43. data/lib/devise/models/authenticatable.rb +143 -0
  44. data/lib/devise/models/confirmable.rb +160 -0
  45. data/lib/devise/models/database_authenticatable.rb +94 -0
  46. data/lib/devise/models/encryptable.rb +65 -0
  47. data/lib/devise/models/lockable.rb +168 -0
  48. data/lib/devise/models/oauthable.rb +49 -0
  49. data/lib/devise/models/recoverable.rb +83 -0
  50. data/lib/devise/models/registerable.rb +21 -0
  51. data/lib/devise/models/rememberable.rb +122 -0
  52. data/lib/devise/models/timeoutable.rb +43 -0
  53. data/lib/devise/models/token_authenticatable.rb +72 -0
  54. data/lib/devise/models/trackable.rb +30 -0
  55. data/lib/devise/models/validatable.rb +64 -0
  56. data/lib/devise/modules.rb +30 -0
  57. data/lib/devise/oauth.rb +41 -0
  58. data/lib/devise/oauth/config.rb +33 -0
  59. data/lib/devise/oauth/helpers.rb +18 -0
  60. data/lib/devise/oauth/internal_helpers.rb +182 -0
  61. data/lib/devise/oauth/test_helpers.rb +29 -0
  62. data/lib/devise/oauth/url_helpers.rb +35 -0
  63. data/lib/devise/orm/active_record.rb +38 -0
  64. data/lib/devise/orm/mongoid.rb +31 -0
  65. data/lib/devise/path_checker.rb +18 -0
  66. data/lib/devise/rails.rb +68 -0
  67. data/lib/devise/rails/routes.rb +260 -0
  68. data/lib/devise/rails/warden_compat.rb +41 -0
  69. data/lib/devise/schema.rb +96 -0
  70. data/lib/devise/strategies/authenticatable.rb +150 -0
  71. data/lib/devise/strategies/base.rb +15 -0
  72. data/lib/devise/strategies/database_authenticatable.rb +21 -0
  73. data/lib/devise/strategies/rememberable.rb +51 -0
  74. data/lib/devise/strategies/token_authenticatable.rb +53 -0
  75. data/lib/devise/test_helpers.rb +100 -0
  76. data/lib/devise/version.rb +3 -0
  77. data/lib/generators/active_record/devise_generator.rb +28 -0
  78. data/lib/generators/active_record/templates/migration.rb +30 -0
  79. data/lib/generators/devise/devise_generator.rb +17 -0
  80. data/lib/generators/devise/install_generator.rb +24 -0
  81. data/lib/generators/devise/orm_helpers.rb +24 -0
  82. data/lib/generators/devise/views_generator.rb +63 -0
  83. data/lib/generators/mongoid/devise_generator.rb +17 -0
  84. data/lib/generators/templates/README +25 -0
  85. data/lib/generators/templates/devise.rb +168 -0
  86. data/test/controllers/helpers_test.rb +205 -0
  87. data/test/controllers/internal_helpers_test.rb +56 -0
  88. data/test/controllers/url_helpers_test.rb +59 -0
  89. data/test/devise_test.rb +65 -0
  90. data/test/encryptors_test.rb +30 -0
  91. data/test/failure_app_test.rb +148 -0
  92. data/test/integration/authenticatable_test.rb +424 -0
  93. data/test/integration/confirmable_test.rb +104 -0
  94. data/test/integration/database_authenticatable_test.rb +38 -0
  95. data/test/integration/http_authenticatable_test.rb +64 -0
  96. data/test/integration/lockable_test.rb +109 -0
  97. data/test/integration/oauthable_test.rb +258 -0
  98. data/test/integration/recoverable_test.rb +134 -0
  99. data/test/integration/registerable_test.rb +180 -0
  100. data/test/integration/rememberable_test.rb +179 -0
  101. data/test/integration/timeoutable_test.rb +89 -0
  102. data/test/integration/token_authenticatable_test.rb +99 -0
  103. data/test/integration/trackable_test.rb +64 -0
  104. data/test/mailers/confirmation_instructions_test.rb +84 -0
  105. data/test/mailers/reset_password_instructions_test.rb +72 -0
  106. data/test/mailers/unlock_instructions_test.rb +66 -0
  107. data/test/mapping_test.rb +95 -0
  108. data/test/models/confirmable_test.rb +221 -0
  109. data/test/models/database_authenticatable_test.rb +82 -0
  110. data/test/models/encryptable_test.rb +65 -0
  111. data/test/models/lockable_test.rb +204 -0
  112. data/test/models/oauthable_test.rb +21 -0
  113. data/test/models/recoverable_test.rb +155 -0
  114. data/test/models/rememberable_test.rb +271 -0
  115. data/test/models/timeoutable_test.rb +28 -0
  116. data/test/models/token_authenticatable_test.rb +37 -0
  117. data/test/models/trackable_test.rb +5 -0
  118. data/test/models/validatable_test.rb +99 -0
  119. data/test/models_test.rb +77 -0
  120. data/test/oauth/config_test.rb +44 -0
  121. data/test/oauth/url_helpers_test.rb +47 -0
  122. data/test/orm/active_record.rb +9 -0
  123. data/test/orm/mongoid.rb +10 -0
  124. data/test/rails_app/app/active_record/admin.rb +6 -0
  125. data/test/rails_app/app/active_record/shim.rb +2 -0
  126. data/test/rails_app/app/active_record/user.rb +8 -0
  127. data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
  128. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  129. data/test/rails_app/app/controllers/application_controller.rb +9 -0
  130. data/test/rails_app/app/controllers/home_controller.rb +12 -0
  131. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
  132. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
  133. data/test/rails_app/app/controllers/users_controller.rb +18 -0
  134. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  135. data/test/rails_app/app/mongoid/admin.rb +9 -0
  136. data/test/rails_app/app/mongoid/shim.rb +24 -0
  137. data/test/rails_app/app/mongoid/user.rb +10 -0
  138. data/test/rails_app/config/application.rb +35 -0
  139. data/test/rails_app/config/boot.rb +13 -0
  140. data/test/rails_app/config/environment.rb +5 -0
  141. data/test/rails_app/config/environments/development.rb +19 -0
  142. data/test/rails_app/config/environments/production.rb +33 -0
  143. data/test/rails_app/config/environments/test.rb +33 -0
  144. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  145. data/test/rails_app/config/initializers/devise.rb +172 -0
  146. data/test/rails_app/config/initializers/inflections.rb +2 -0
  147. data/test/rails_app/config/initializers/secret_token.rb +2 -0
  148. data/test/rails_app/config/routes.rb +54 -0
  149. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +31 -0
  150. data/test/rails_app/db/schema.rb +52 -0
  151. data/test/rails_app/lib/shared_admin.rb +9 -0
  152. data/test/rails_app/lib/shared_user.rb +48 -0
  153. data/test/routes_test.rb +189 -0
  154. data/test/support/assertions.rb +24 -0
  155. data/test/support/helpers.rb +60 -0
  156. data/test/support/integration.rb +88 -0
  157. data/test/support/webrat/integrations/rails.rb +24 -0
  158. data/test/test_helper.rb +23 -0
  159. data/test/test_helpers_test.rb +101 -0
  160. metadata +350 -0
@@ -0,0 +1,24 @@
1
+ class Devise::SessionsController < ApplicationController
2
+ prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
3
+ include Devise::Controllers::InternalHelpers
4
+
5
+ # GET /resource/sign_in
6
+ def new
7
+ clean_up_passwords(build_resource)
8
+ render_with_scope :new
9
+ end
10
+
11
+ # POST /resource/sign_in
12
+ def create
13
+ resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
14
+ set_flash_message :notice, :signed_in
15
+ sign_in_and_redirect(resource_name, resource)
16
+ end
17
+
18
+ # GET /resource/sign_out
19
+ def destroy
20
+ signed_in = signed_in?(resource_name)
21
+ sign_out_and_redirect(resource_name)
22
+ set_flash_message :notice, :signed_out if signed_in
23
+ end
24
+ end
@@ -0,0 +1,34 @@
1
+ class Devise::UnlocksController < ApplicationController
2
+ prepend_before_filter :require_no_authentication
3
+ include Devise::Controllers::InternalHelpers
4
+
5
+ # GET /resource/unlock/new
6
+ def new
7
+ build_resource({})
8
+ render_with_scope :new
9
+ end
10
+
11
+ # POST /resource/unlock
12
+ def create
13
+ self.resource = resource_class.send_unlock_instructions(params[resource_name])
14
+
15
+ if resource.errors.empty?
16
+ set_flash_message :notice, :send_instructions
17
+ redirect_to new_session_path(resource_name)
18
+ else
19
+ render_with_scope :new
20
+ end
21
+ end
22
+
23
+ # GET /resource/unlock?unlock_token=abcdef
24
+ def show
25
+ self.resource = resource_class.unlock_access_by_token(params[:unlock_token])
26
+
27
+ if resource.errors.empty?
28
+ set_flash_message :notice, :unlocked
29
+ sign_in_and_redirect(resource_name, resource)
30
+ else
31
+ render_with_scope :new
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ module DeviseHelper
2
+ def devise_error_messages!
3
+ return "" if resource.errors.empty?
4
+
5
+ messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
6
+ sentence = I18n.t("errors.messages.not_saved",
7
+ :count => resource.errors.count,
8
+ :resource => resource_name)
9
+
10
+ html = <<-HTML
11
+ <div id="error_explanation">
12
+ <h2>#{sentence}</h2>
13
+ <ul>#{messages}</ul>
14
+ </div>
15
+ HTML
16
+
17
+ html.html_safe
18
+ end
19
+ end
@@ -0,0 +1,88 @@
1
+ class Devise::Mailer < ::ActionMailer::Base
2
+ include Devise::Controllers::ScopedViews
3
+ attr_reader :scope_name, :resource
4
+
5
+ def confirmation_instructions(record)
6
+ setup_mail(record, :confirmation_instructions)
7
+ end
8
+
9
+ def reset_password_instructions(record)
10
+ setup_mail(record, :reset_password_instructions)
11
+ end
12
+
13
+ def unlock_instructions(record)
14
+ setup_mail(record, :unlock_instructions)
15
+ end
16
+
17
+ private
18
+
19
+ # Configure default email options
20
+ def setup_mail(record, action)
21
+ initialize_from_record(record)
22
+ mail headers_for(action)
23
+ end
24
+
25
+ def initialize_from_record(record)
26
+ @scope_name = Devise::Mapping.find_scope!(record)
27
+ @resource = instance_variable_set("@#{devise_mapping.name}", record)
28
+ end
29
+
30
+ def devise_mapping
31
+ @devise_mapping ||= Devise.mappings[scope_name]
32
+ end
33
+
34
+ def headers_for(action)
35
+ headers = {
36
+ :subject => translate(devise_mapping, action),
37
+ :from => mailer_sender(devise_mapping),
38
+ :to => resource.email,
39
+ :template_path => template_paths
40
+ }
41
+
42
+ if resource.respond_to?(:headers_for)
43
+ headers.merge!(resource.headers_for(action))
44
+ end
45
+
46
+ unless headers.key?(:reply_to)
47
+ headers[:reply_to] = headers[:from]
48
+ end
49
+
50
+ headers
51
+ end
52
+
53
+ def mailer_sender(mapping)
54
+ if Devise.mailer_sender.is_a?(Proc)
55
+ Devise.mailer_sender.call(mapping.name)
56
+ else
57
+ Devise.mailer_sender
58
+ end
59
+ end
60
+
61
+ def template_paths
62
+ template_path = [self.class.mailer_name]
63
+ template_path.unshift "#{@devise_mapping.plural}/mailer" if self.class.scoped_views?
64
+ template_path
65
+ end
66
+
67
+ # Setup a subject doing an I18n lookup. At first, it attemps to set a subject
68
+ # based on the current mapping:
69
+ #
70
+ # en:
71
+ # devise:
72
+ # mailer:
73
+ # confirmation_instructions:
74
+ # user_subject: '...'
75
+ #
76
+ # If one does not exist, it fallbacks to ActionMailer default:
77
+ #
78
+ # en:
79
+ # devise:
80
+ # mailer:
81
+ # confirmation_instructions:
82
+ # subject: '...'
83
+ #
84
+ def translate(mapping, key)
85
+ I18n.t(:"#{mapping.name}_subject", :scope => [:devise, :mailer, key],
86
+ :default => [:subject, key.to_s.humanize])
87
+ end
88
+ end
@@ -0,0 +1,12 @@
1
+ <h2>Resend confirmation instructions</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <p><%= f.label :email %><br />
7
+ <%= f.email_field :email %></p>
8
+
9
+ <p><%= f.submit "Resend confirmation instructions" %></p>
10
+ <% end %>
11
+
12
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,5 @@
1
+ <p>Welcome <%= @resource.email %>!</p>
2
+
3
+ <p>You can confirm your account through the link below:</p>
4
+
5
+ <p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
@@ -0,0 +1,8 @@
1
+ <p>Hello <%= @resource.email %>!</p>
2
+
3
+ <p>Someone has requested a link to change your password, and you can do this through the link below.</p>
4
+
5
+ <p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
6
+
7
+ <p>If you didn't request this, please ignore this email.</p>
8
+ <p>Your password won't change until you access the link above and create a new one.</p>
@@ -0,0 +1,7 @@
1
+ <p>Hello <%= @resource.email %>!</p>
2
+
3
+ <p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
4
+
5
+ <p>Click the link below to unlock your account:</p>
6
+
7
+ <p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>
@@ -0,0 +1,16 @@
1
+ <h2>Change your password</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
4
+ <%= devise_error_messages! %>
5
+ <%= f.hidden_field :reset_password_token %>
6
+
7
+ <p><%= f.label :password, "New password" %><br />
8
+ <%= f.password_field :password %></p>
9
+
10
+ <p><%= f.label :password_confirmation, "Confirm new password" %><br />
11
+ <%= f.password_field :password_confirmation %></p>
12
+
13
+ <p><%= f.submit "Change my password" %></p>
14
+ <% end %>
15
+
16
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,12 @@
1
+ <h2>Forgot your password?</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <p><%= f.label :email %><br />
7
+ <%= f.email_field :email %></p>
8
+
9
+ <p><%= f.submit "Send me reset password instructions" %></p>
10
+ <% end %>
11
+
12
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,25 @@
1
+ <h2>Edit <%= resource_name.to_s.humanize %></h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <p><%= f.label :email %><br />
7
+ <%= f.email_field :email %></p>
8
+
9
+ <p><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
10
+ <%= f.password_field :password %></p>
11
+
12
+ <p><%= f.label :password_confirmation %><br />
13
+ <%= f.password_field :password_confirmation %></p>
14
+
15
+ <p><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
16
+ <%= f.password_field :current_password %></p>
17
+
18
+ <p><%= f.submit "Update" %></p>
19
+ <% end %>
20
+
21
+ <h3>Cancel my account</h3>
22
+
23
+ <p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
24
+
25
+ <%= link_to "Back", :back %>
@@ -0,0 +1,18 @@
1
+ <h2>Sign up</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <p><%= f.label :email %><br />
7
+ <%= f.email_field :email %></p>
8
+
9
+ <p><%= f.label :password %><br />
10
+ <%= f.password_field :password %></p>
11
+
12
+ <p><%= f.label :password_confirmation %><br />
13
+ <%= f.password_field :password_confirmation %></p>
14
+
15
+ <p><%= f.submit "Sign up" %></p>
16
+ <% end %>
17
+
18
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,18 @@
1
+ =content_for :header, "Sign In"
2
+
3
+ =semantic_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f|
4
+ -f.inputs do
5
+ = f.input :email
6
+
7
+ = f.input :password
8
+
9
+ -if devise_mapping.rememberable?
10
+
11
+ = f.input :remember_me, :as => :boolean
12
+
13
+ %br{:style => "clear:left;"}
14
+ .button_container
15
+ = f.submit "Sign in"
16
+
17
+
18
+ = render :partial => "devise/shared/links"
@@ -0,0 +1,25 @@
1
+ <%- if controller_name != 'sessions' %>
2
+ <%= link_to "Sign in", new_session_path(resource_name) %><br />
3
+ <% end -%>
4
+
5
+ <%- if devise_mapping.registerable? && controller_name != 'registrations' %>
6
+ <%= link_to "Sign up", new_registration_path(resource_name) %><br />
7
+ <% end -%>
8
+
9
+ <%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
10
+ <%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
11
+ <% end -%>
12
+
13
+ <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
14
+ <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
15
+ <% end -%>
16
+
17
+ <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
18
+ <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
19
+ <% end -%>
20
+
21
+ <%- if devise_mapping.oauthable? %>
22
+ <%- resource_class.oauth_providers.each do |provider| %>
23
+ <%= link_to "Sign in with #{provider.to_s.titleize}", oauth_authorize_url(resource_name, provider) %><br />
24
+ <% end -%>
25
+ <% end -%>
@@ -0,0 +1,12 @@
1
+ <h2>Resend unlock instructions</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <p><%= f.label :email %><br />
7
+ <%= f.email_field :email %></p>
8
+
9
+ <p><%= f.submit "Resend unlock instructions" %></p>
10
+ <% end %>
11
+
12
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,46 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ not_found: "not found"
5
+ already_confirmed: "was already confirmed"
6
+ not_locked: "was not locked"
7
+ not_saved:
8
+ one: "1 error prohibited this %{resource} from being saved:"
9
+ other: "%{count} errors prohibited this %{resource} from being saved:"
10
+
11
+ devise:
12
+ failure:
13
+ unauthenticated: 'You need to sign in or sign up before continuing.'
14
+ unconfirmed: 'You have to confirm your account before continuing.'
15
+ locked: 'Your account is locked.'
16
+ invalid: 'Invalid email or password.'
17
+ invalid_token: 'Invalid authentication token.'
18
+ timeout: 'Your session expired, please sign in again to continue.'
19
+ inactive: 'Your account was not activated yet.'
20
+ sessions:
21
+ signed_in: 'Signed in successfully.'
22
+ signed_out: 'Signed out successfully.'
23
+ passwords:
24
+ send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
25
+ updated: 'Your password was changed successfully. You are now signed in.'
26
+ confirmations:
27
+ send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
28
+ confirmed: 'Your account was successfully confirmed. You are now signed in.'
29
+ registrations:
30
+ signed_up: 'Welcome! You have signed up successfully.'
31
+ inactive_signed_up: 'You have signed up successfully. However, we could not sign you in because your account is %{reason}.'
32
+ updated: 'You updated your account successfully.'
33
+ destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
34
+ unlocks:
35
+ send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
36
+ unlocked: 'Your account was successfully unlocked. You are now signed in.'
37
+ oauth_callbacks:
38
+ success: 'Successfully authorized from %{kind} account.'
39
+ failure: 'Could not authorize you from %{kind} because "%{reason}".'
40
+ mailer:
41
+ confirmation_instructions:
42
+ subject: 'Confirmation instructions'
43
+ reset_password_instructions:
44
+ subject: 'Reset password instructions'
45
+ unlock_instructions:
46
+ subject: 'Unlock Instructions'
@@ -0,0 +1,372 @@
1
+ require 'active_support/core_ext/numeric/time'
2
+ require 'active_support/dependencies'
3
+ require 'orm_adapter'
4
+ require 'set'
5
+
6
+ module Devise
7
+ autoload :FailureApp, 'devise/failure_app'
8
+ autoload :Oauth, 'devise/oauth'
9
+ autoload :PathChecker, 'devise/path_checker'
10
+ autoload :Schema, 'devise/schema'
11
+ autoload :TestHelpers, 'devise/test_helpers'
12
+
13
+ module Controllers
14
+ autoload :Helpers, 'devise/controllers/helpers'
15
+ autoload :InternalHelpers, 'devise/controllers/internal_helpers'
16
+ autoload :ScopedViews, 'devise/controllers/scoped_views'
17
+ autoload :UrlHelpers, 'devise/controllers/url_helpers'
18
+ end
19
+
20
+ module Encryptors
21
+ autoload :Base, 'devise/encryptors/base'
22
+ autoload :AuthlogicSha512, 'devise/encryptors/authlogic_sha512'
23
+ autoload :ClearanceSha1, 'devise/encryptors/clearance_sha1'
24
+ autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
25
+ autoload :Sha512, 'devise/encryptors/sha512'
26
+ autoload :Sha1, 'devise/encryptors/sha1'
27
+ end
28
+
29
+ module Strategies
30
+ autoload :Base, 'devise/strategies/base'
31
+ autoload :Authenticatable, 'devise/strategies/authenticatable'
32
+ end
33
+
34
+ # Constants which holds devise configuration for extensions. Those should
35
+ # not be modified by the "end user" (this is why they are constants).
36
+ ALL = []
37
+ CONTROLLERS = ActiveSupport::OrderedHash.new
38
+ ROUTES = ActiveSupport::OrderedHash.new
39
+ STRATEGIES = ActiveSupport::OrderedHash.new
40
+ URL_HELPERS = ActiveSupport::OrderedHash.new
41
+
42
+ # True values used to check params
43
+ TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
44
+
45
+ # Declare encryptors length which are used in migrations.
46
+ ENCRYPTORS_LENGTH = {
47
+ :sha1 => 40,
48
+ :sha512 => 128,
49
+ :clearance_sha1 => 40,
50
+ :restful_authentication_sha1 => 40,
51
+ :authlogic_sha512 => 128
52
+ }
53
+
54
+ # Custom domain for cookies. Not set by default
55
+ mattr_accessor :cookie_options
56
+ @@cookie_options = {}
57
+
58
+ # The number of times to encrypt password.
59
+ mattr_accessor :stretches
60
+ @@stretches = 10
61
+
62
+ # Keys used when authenticating an user.
63
+ mattr_accessor :authentication_keys
64
+ @@authentication_keys = [ :email ]
65
+
66
+ # Request keys used when authenticating an user.
67
+ mattr_accessor :request_keys
68
+ @@request_keys = []
69
+
70
+ # If http authentication is enabled by default.
71
+ mattr_accessor :http_authenticatable
72
+ @@http_authenticatable = false
73
+
74
+ # If http headers should be returned for ajax requests. True by default.
75
+ mattr_accessor :http_authenticatable_on_xhr
76
+ @@http_authenticatable_on_xhr = true
77
+
78
+ # If params authenticatable is enabled by default.
79
+ mattr_accessor :params_authenticatable
80
+ @@params_authenticatable = true
81
+
82
+ # The realm used in Http Basic Authentication.
83
+ mattr_accessor :http_authentication_realm
84
+ @@http_authentication_realm = "Application"
85
+
86
+ # Email regex used to validate email formats. Adapted from authlogic.
87
+ mattr_accessor :email_regexp
88
+ @@email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
89
+
90
+ # Range validation for password length
91
+ mattr_accessor :password_length
92
+ @@password_length = 6..20
93
+
94
+ # The time the user will be remembered without asking for credentials again.
95
+ mattr_accessor :remember_for
96
+ @@remember_for = 2.weeks
97
+
98
+ # If true, a valid remember token can be re-used between multiple browsers.
99
+ mattr_accessor :remember_across_browsers
100
+ @@remember_across_browsers = true
101
+
102
+ # If true, extends the user's remember period when remembered via cookie.
103
+ mattr_accessor :extend_remember_period
104
+ @@extend_remember_period = false
105
+
106
+ # If true, uses salt as remember token and does not create it in the database.
107
+ # By default is false for backwards compatibility.
108
+ mattr_accessor :use_salt_as_remember_token
109
+ @@use_salt_as_remember_token = false
110
+
111
+ # Time interval you can access your account before confirming your account.
112
+ mattr_accessor :confirm_within
113
+ @@confirm_within = 0.days
114
+
115
+ # Time interval to timeout the user session without activity.
116
+ mattr_accessor :timeout_in
117
+ @@timeout_in = 30.minutes
118
+
119
+ # Used to encrypt password. Please generate one with rake secret.
120
+ mattr_accessor :pepper
121
+ @@pepper = nil
122
+
123
+ # Used to define the password encryption algorithm.
124
+ mattr_accessor :encryptor
125
+ @@encryptor = nil
126
+
127
+ # Tells if devise should apply the schema in ORMs where devise declaration
128
+ # and schema belongs to the same class (as Datamapper and Mongoid).
129
+ mattr_accessor :apply_schema
130
+ @@apply_schema = true
131
+
132
+ # Scoped views. Since it relies on fallbacks to render default views, it's
133
+ # turned off by default.
134
+ mattr_accessor :scoped_views
135
+ @@scoped_views = false
136
+
137
+ # Defines which strategy can be used to lock an account.
138
+ # Values: :failed_attempts, :none
139
+ mattr_accessor :lock_strategy
140
+ @@lock_strategy = :failed_attempts
141
+
142
+ # Defines which strategy can be used to unlock an account.
143
+ # Values: :email, :time, :both
144
+ mattr_accessor :unlock_strategy
145
+ @@unlock_strategy = :both
146
+
147
+ # Number of authentication tries before locking an account
148
+ mattr_accessor :maximum_attempts
149
+ @@maximum_attempts = 20
150
+
151
+ # Time interval to unlock the account if :time is defined as unlock_strategy.
152
+ mattr_accessor :unlock_in
153
+ @@unlock_in = 1.hour
154
+
155
+ # The default scope which is used by warden.
156
+ mattr_accessor :default_scope
157
+ @@default_scope = nil
158
+
159
+ # Address which sends Devise e-mails.
160
+ mattr_accessor :mailer_sender
161
+ @@mailer_sender = nil
162
+
163
+ # Authentication token params key name of choice. E.g. /users/sign_in?some_key=...
164
+ mattr_accessor :token_authentication_key
165
+ @@token_authentication_key = :auth_token
166
+
167
+ # If true, authentication through token does not store user in session
168
+ mattr_accessor :stateless_token
169
+ @@stateless_token = false
170
+
171
+ # Which formats should be treated as navigational.
172
+ mattr_accessor :navigational_formats
173
+ @@navigational_formats = [:html]
174
+
175
+ # When set to true, signing out an user signs out all other scopes.
176
+ mattr_accessor :sign_out_all_scopes
177
+ @@sign_out_all_scopes = true
178
+
179
+ # The default method used while signing out
180
+ mattr_accessor :sign_out_via
181
+ @@sign_out_via = :get
182
+
183
+ # Oauth providers
184
+ mattr_accessor :oauth_providers
185
+ @@oauth_providers = []
186
+
187
+ # PRIVATE CONFIGURATION
188
+
189
+ # Store scopes mappings.
190
+ mattr_reader :mappings
191
+ @@mappings = ActiveSupport::OrderedHash.new
192
+
193
+ # Oauth configurations.
194
+ mattr_reader :oauth_configs
195
+ @@oauth_configs = ActiveSupport::OrderedHash.new
196
+
197
+ # Define a set of modules that are called when a mapping is added.
198
+ mattr_reader :helpers
199
+ @@helpers = Set.new
200
+ @@helpers << Devise::Controllers::Helpers
201
+
202
+ # Define a set of modules that are called when a provider is added.
203
+ mattr_reader :oauth_helpers
204
+ @@oauth_helpers = Set.new
205
+
206
+ # Private methods to interface with Warden.
207
+ mattr_accessor :warden_config
208
+ @@warden_config = nil
209
+ @@warden_config_block = nil
210
+
211
+ # Default way to setup Devise. Run rails generate devise_install to create
212
+ # a fresh initializer with all configuration values.
213
+ def self.setup
214
+ yield self
215
+ end
216
+
217
+ def self.cookie_domain=(value)
218
+ ActiveSupport::Deprecation.warn "Devise.cookie_domain=(value) is deprecated. "
219
+ "Please use Devise.cookie_options = { :domain => value } instead."
220
+ self.cookie_options[:domain] = value
221
+ end
222
+
223
+ # Get the mailer class from the mailer reference object.
224
+ def self.mailer
225
+ @@mailer_ref.get
226
+ end
227
+
228
+ # Set the mailer reference object to access the mailer.
229
+ def self.mailer=(class_name)
230
+ @@mailer_ref = ActiveSupport::Dependencies.ref(class_name)
231
+ end
232
+ self.mailer = "Devise::Mailer"
233
+
234
+ # Small method that adds a mapping to Devise.
235
+ def self.add_mapping(resource, options)
236
+ mapping = Devise::Mapping.new(resource, options)
237
+ @@mappings[mapping.name] = mapping
238
+ @@default_scope ||= mapping.name
239
+ @@helpers.each { |h| h.define_helpers(mapping) }
240
+ mapping
241
+ end
242
+
243
+ # Make Devise aware of an 3rd party Devise-module (like invitable). For convenience.
244
+ #
245
+ # == Options:
246
+ #
247
+ # +model+ - String representing the load path to a custom *model* for this module (to autoload.)
248
+ # +controller+ - Symbol representing the name of an exisiting or custom *controller* for this module.
249
+ # +route+ - Symbol representing the named *route* helper for this module.
250
+ # +strategy+ - Symbol representing if this module got a custom *strategy*.
251
+ #
252
+ # All values, except :model, accept also a boolean and will have the same name as the given module
253
+ # name.
254
+ #
255
+ # == Examples:
256
+ #
257
+ # Devise.add_module(:party_module)
258
+ # Devise.add_module(:party_module, :strategy => true, :controller => :sessions)
259
+ # Devise.add_module(:party_module, :model => 'party_module/model')
260
+ #
261
+ def self.add_module(module_name, options = {})
262
+ ALL << module_name
263
+ options.assert_valid_keys(:strategy, :model, :controller, :route)
264
+
265
+ if strategy = options[:strategy]
266
+ STRATEGIES[module_name] = (strategy == true ? module_name : strategy)
267
+ end
268
+
269
+ if controller = options[:controller]
270
+ CONTROLLERS[module_name] = (controller == true ? module_name : controller)
271
+ end
272
+
273
+ if route = options[:route]
274
+ case route
275
+ when TrueClass
276
+ key, value = module_name, []
277
+ when Symbol
278
+ key, value = route, []
279
+ when Hash
280
+ key, value = route.keys.first, route.values.flatten
281
+ else
282
+ raise ArgumentError, ":route should be true, a Symbol or a Hash"
283
+ end
284
+
285
+ URL_HELPERS[key] ||= []
286
+ URL_HELPERS[key].concat(value)
287
+ URL_HELPERS[key].uniq!
288
+
289
+ ROUTES[module_name] = key
290
+ end
291
+
292
+ if options[:model]
293
+ path = (options[:model] == true ? "devise/models/#{module_name}" : options[:model])
294
+ Devise::Models.send(:autoload, module_name.to_s.camelize.to_sym, path)
295
+ end
296
+
297
+ Devise::Mapping.add_module module_name
298
+ end
299
+
300
+ # Sets warden configuration using a block that will be invoked on warden
301
+ # initialization.
302
+ #
303
+ # Devise.initialize do |config|
304
+ # config.confirm_within = 2.days
305
+ #
306
+ # config.warden do |manager|
307
+ # # Configure warden to use other strategies, like oauth.
308
+ # manager.oauth(:twitter)
309
+ # end
310
+ # end
311
+ def self.warden(&block)
312
+ @@warden_config_block = block
313
+ end
314
+
315
+ # Specify an oauth provider.
316
+ #
317
+ # config.oauth :github, APP_ID, APP_SECRET,
318
+ # :site => 'https://github.com/',
319
+ # :authorize_path => '/login/oauth/authorize',
320
+ # :access_token_path => '/login/oauth/access_token',
321
+ # :scope => %w(user public_repo)
322
+ #
323
+ def self.oauth(provider, *args)
324
+ @@helpers << Devise::Oauth::UrlHelpers
325
+ @@oauth_helpers << Devise::Oauth::InternalHelpers
326
+
327
+ @@oauth_providers << provider
328
+ @@oauth_providers.uniq!
329
+
330
+ @@oauth_helpers.each { |h| h.define_oauth_helpers(provider) }
331
+ @@oauth_configs[provider] = Devise::Oauth::Config.new(*args)
332
+ end
333
+
334
+ # Include helpers in the given scope to AC and AV.
335
+ def self.include_helpers(scope)
336
+ ActiveSupport.on_load(:action_controller) do
337
+ include scope::Helpers
338
+ include scope::UrlHelpers
339
+ end
340
+
341
+ ActiveSupport.on_load(:action_view) do
342
+ include scope::UrlHelpers
343
+ end
344
+ end
345
+
346
+ # A method used internally to setup warden manager from the Rails initialize
347
+ # block.
348
+ def self.configure_warden! #:nodoc:
349
+ @@warden_configured ||= begin
350
+ warden_config.failure_app = Devise::FailureApp
351
+ warden_config.default_scope = Devise.default_scope
352
+
353
+ Devise.mappings.each_value do |mapping|
354
+ warden_config.scope_defaults mapping.name, :strategies => mapping.strategies
355
+ end
356
+
357
+ @@warden_config_block.try :call, Devise.warden_config
358
+ true
359
+ end
360
+ end
361
+
362
+ # Generate a friendly string randomically to be used as token.
363
+ def self.friendly_token
364
+ ActiveSupport::SecureRandom.base64(44).tr('+/=', 'xyz')
365
+ end
366
+ end
367
+
368
+ require 'warden'
369
+ require 'devise/mapping'
370
+ require 'devise/models'
371
+ require 'devise/modules'
372
+ require 'devise/rails'