Module: Sinatra::Hancock::Sessions

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

Defined Under Namespace

Modules: Helpers

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sinatra/hancock/sessions.rb', line 31

def self.registered(app)
  app.send(:include, Sinatra::Hancock::Sessions::Helpers)
  app.template(:unauthenticated) { sessions_template('unauthenticated') }
  app.get '/sso/login' do
    ensure_authenticated
    redirect '/'
  end
  app.post '/sso/login' do
    @user = ::Hancock::User.authenticate(params['email'], params['password'])
    if @user
      session['hancock_server_user_id'] = @user.id
    end
    ensure_authenticated
    redirect session['hancock_server_return_to'] || '/'
  end

  app.get '/sso/logout' do
    session.clear
    redirect '/'
  end
end

.sessions_template(file) ⇒ Object



4
5
6
7
# File 'lib/sinatra/hancock/sessions.rb', line 4

def self.sessions_template(file)
  template = File.expand_path(File.dirname(__FILE__)+'/views/sessions')
  File.read("#{template}/#{file}.haml")
end