Sha256: ec57e1b9026881830e91ca60861a27c4fc246a624f9f70ca1aeb283bbf9901a8
Contents?: true
Size: 849 Bytes
Versions: 21
Compression:
Stored size: 849 Bytes
Contents
class ApplicationController < Sinatra::Base # Configure Warden for authentication enable :sessions Warden::Manager.before_failure {|env,opts| env['REQUEST_METHOD'] = 'POST'} Warden::Strategies.add(:password) do def valid? params['user'] && params['user']['username'] && params['user']['password'] end def authenticate! unless (user = User.find_by_username params['user']['username']) fail! 'The username you entered does not exist' else user.authenticate(params['user']['password']) ? success!(user) : fail!('Could not log in') end end end helpers do def current_user env['warden'].user end def authenticated? !!current_user end def authenticate env['warden'].authenticate! end alias_method :logged_in?, :authenticated? end end
Version data entries
21 entries across 21 versions & 1 rubygems