Module: SinatraOmniAuth::Helpers

Defined in:
lib/sinatra/omniauth.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_user!Object



117
118
119
120
121
122
# File 'lib/sinatra/omniauth.rb', line 117

def authenticate_user!
  if !current_user
    flash.error = 'You need to sign in before you can access this page!'
    redirect to('/auth')
  end
end

#current_authObject



112
113
114
115
# File 'lib/sinatra/omniauth.rb', line 112

def current_auth
  current_user
  @current_auth
end

#current_userObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/sinatra/omniauth.rb', line 94

def current_user
  session.delete :authentication_id   # Clean up old auth values
  begin
    if session[:user_id] && session[:authentication_provider]
      @current_auth ||= Authentication.first(:user_id => session[:user_id], :provider => session[:authentication_provider])
      @current_user ||= @current_auth.user
    end
    return @current_user if @current_user
  rescue      # Invalid cookie value formats?
    @current_user = nil
    @current_auth = nil
  end

  # Clean up any old/bad cookie values:
  session.delete :user_id
  session.delete :authentication_provider
end