Module: Sinatra::Hancock::Sessions::Helpers

Defined in:
lib/sinatra/hancock/sessions.rb

Instance Method Summary collapse

Instance Method Details

#ensure_authenticatedObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sinatra/hancock/sessions.rb', line 15

def ensure_authenticated
  if trust_root = session['hancock_server_return_to'] || params['return_to']
    if ::Hancock::Consumer.allowed?(trust_root)
      if session_user
        redirect "#{trust_root}?id=#{session_user.id}"
      else
        session['hancock_server_return_to'] = trust_root
      end
    else
      forbidden!
    end
  end
  throw(:halt, [401, haml(:unauthenticated)]) unless session_user
end

#session_userObject



10
11
12
13
# File 'lib/sinatra/hancock/sessions.rb', line 10

def session_user
  session['hancock_server_user_id'].nil? ? 
    nil : ::Hancock::User.get(session['hancock_server_user_id'])
end