Improve channel, user and api_key models with basic scopes, correct references and protect attributes.
Simplify channels & user controllers and models, moving code to the models. Remove catch-all route and ensure all actions are specified, fixing url paths. Change clone to dup in feed_controller as using clone seems to affect the cloned object (problem only in ruby 1.9.3?)
This commit is contained in:
14
lib/key_utilities.rb
Normal file
14
lib/key_utilities.rb
Normal file
@ -0,0 +1,14 @@
|
||||
module KeyUtilities
|
||||
|
||||
# generates a database unique api key
|
||||
def generate_api_key(size = 16)
|
||||
alphanumerics = ('0'..'9').to_a + ('A'..'Z').to_a
|
||||
k = (0..size).map {alphanumerics[Kernel.rand(36)]}.join
|
||||
|
||||
# if key exists in database, regenerate key
|
||||
k = generate_api_key if ApiKey.find_by_api_key(k)
|
||||
|
||||
# output the key
|
||||
k
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user