update with changes from Production branch

This commit is contained in:
Lee Lawlor
2014-02-17 12:05:39 -05:00
parent 5b640cf9d8
commit a4937fb2e5
384 changed files with 14690 additions and 2242 deletions

11
lib/api_keys.rb Normal file
View File

@ -0,0 +1,11 @@
module ApiKeys
def api_index (channel_id)
if current_user && !current_user.channels.find_by_id(channel_id).nil?
@channel = current_user.channels.find(channel_id)
end
if current_user && current_user.id == @channel.user_id
@write_key = @channel.api_keys.write_keys.first
@read_keys = @channel.api_keys.read_keys
end
end
end

View File

@ -1,14 +1,18 @@
module KeyUtilities
# generates a database unique api key
def generate_api_key(size = 16)
def generate_api_key(size = 16, type = 'channel')
alphanumerics = ('0'..'9').to_a + ('A'..'Z').to_a
k = (0..(size - 1)).map {alphanumerics[Kernel.rand(36)]}.join
new_key = (1..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
new_key = generate_api_key if type == 'channel' and ApiKey.find_by_api_key(new_key)
new_key = generate_api_key(16, 'user') if type == 'user' and User.find_by_api_key(new_key)
new_key = generate_api_key(16, 'twitter') if type == 'twitter' and TwitterAccount.find_by_api_key(new_key)
new_key = generate_api_key(16, 'thinghttp') if type == 'thinghttp' and Thinghttp.find_by_api_key(new_key)
new_key = generate_api_key(16, 'talkback') if type == 'talkback' and Talkback.find_by_api_key(new_key)
return new_key
end
end