Skip to content

Commit

Permalink
Improve setup of an authentication key.
Browse files Browse the repository at this point in the history
  • Loading branch information
MitinPavel committed Jul 1, 2012
1 parent d05dff3 commit ed4cdf5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
8 changes: 8 additions & 0 deletions lib/current_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ def identifier_for(user)
end
end
module_function :identifier_for

def read_authentication_key
key_file_path = File.expand_path 'config/current_user/key', Rails.root
if File.exist? key_file_path
File.open(key_file_path) { |f| f.readline }
end
end
module_function :read_authentication_key
end
12 changes: 4 additions & 8 deletions lib/generators/templates/current_user.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
::CurrentUser.setup do |config|

# Setup an authentication key
# If you want just remove the code block belong and
# setup the key: config.authentication_key = '4242424242424242'
key_file_path = File.expand_path 'config/current_user/key', Rails.root
if File.exist? key_file_path
key = File.open(key_file_path) { |f| f.readline }
config.authentication_key = key
end
# Setup an authentication key.
# If you want to have a custom key, it might look like:
# config.authentication_key = '4242424242424242'
config.authentication_key = ::CurrentUser.read_authentication_key

# Setup how users might be distinguished via UI.
# It might be a symbol, a string or a lambda.
Expand Down
20 changes: 7 additions & 13 deletions test/dummy/config/initializers/current_user.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
::CurrentUser.setup do |config|

# Setup an authentication key
# If you want just remove the code block belong and
# setup the key: config.authentication_key = '4242424242424242'
key_file_path = File.expand_path 'config/current_user/key', Rails.root
if File.exist? key_file_path
key = File.open(key_file_path) { |f| f.readline }
config.authentication_key = key
end
# Setup an authentication key.
# If you want to have a custom key, it might look like:
# config.authentication_key = '4242424242424242'
config.authentication_key = ::CurrentUser.read_authentication_key

# Setup how users might be distinguished via UI.
# It might be a symbol, a string or a lambda.
# If it is a symbol or a string, there should be
# a database column with the same name.
# If 'identifier' is lambda it might be written as:
# config.identifier = lambda { |u| "User with email '#{u.email}'" }
# For the last case it might be:
# config.identifier = -> { |u| "User with email #{u.email}" }
config.identifier = :email
end
end

0 comments on commit ed4cdf5

Please sign in to comment.