Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Commit

Permalink
extremely basic instagram auth
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed May 9, 2011
1 parent 90460f7 commit d72a09b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
21 changes: 17 additions & 4 deletions lib/chat_gram/app.rb
Expand Up @@ -4,13 +4,23 @@

module ChatGram
class App < Sinatra::Base
enable :sessions

before do
@instagram = settings.instagram_client || Instagram.client
end

# lol homepage
get '/' do
'hwat'
"hwat (#{session[:login].inspect})"
end

get "/users" do
if settings.model.approved?(session[:login])
"booya sinatra sessions"
else
redirect "/auth"
end
end

# This is the endpoint to provide start the OAuth authorization process.
Expand All @@ -31,9 +41,12 @@ class App < Sinatra::Base
data = @instagram.get_access_token params[:code],
:redirect_uri => callback_url

settings.model.approve(data.user.username, data.access_token)

'\m/'
if settings.model.approve(data.user.username, data.access_token)
session[:login] = data.user.username
redirect "/users"
else
"You're not on the list"
end
rescue Object => e
puts res.inspect
raise
Expand Down
5 changes: 4 additions & 1 deletion lib/chat_gram/model.rb
Expand Up @@ -47,6 +47,8 @@ def initialize(options = {})
#
# Returns true if the user is approved, or false.
def approved?(username)
return false if username.to_s.empty?

user = @db[:users].where(:username => username).first
user && !user[:token].to_s.empty?
end
Expand All @@ -58,7 +60,8 @@ def approved?(username)
#
# Returns true if the user is approved, or false.
def approve(username, token)
return false if token.to_s.empty?
return false if username.to_s.empty? ||
token.to_s.empty?

num = @db[:users].
where(:username => username).
Expand Down

0 comments on commit d72a09b

Please sign in to comment.