Module: Sinatra::Security

Defined in:
lib/sinatra/security.rb,
lib/sinatra/security/user.rb,
lib/sinatra/security/helpers.rb,
lib/sinatra/security/password.rb,
lib/sinatra/security/login_field.rb,
lib/sinatra/security/validations.rb,
lib/sinatra/security/identification.rb

Defined Under Namespace

Modules: Helpers, Identification, LoginField, Password, User, Validations

Constant Summary collapse

VERSION =
"0.2.1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



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

def self.registered(app)
  app.helpers Helpers

  app.set :login_error_message, "Wrong Email and/or Password combination."
  app.set :login_url,           "/login"
  app.set :login_user_class,    lambda { ::User }
  app.set :ignored_by_return_to, /(jpe?g|png|gif|css|js)$/
    
  app.post '/login' do
    if authenticate(params)
      redirect_to_return_url
    else
      session[:error] = settings.
      redirect settings.
    end
  end
end

Instance Method Details

#require_login(path_prefix) ⇒ nil

Allows you to declaratively declare secured locations based on their path prefix.

Examples:


 '/admin'

get '/admin/posts' do
  # Posts here
end

get '/admin/users' do
  # Users here
end

Parameters:

  • path_prefix (#to_s)

    a string to match against the start of request.fullpath

Returns:

  • (nil)


50
51
52
53
54
55
56
# File 'lib/sinatra/security.rb', line 50

def (path_prefix)
  before do
    if request.fullpath =~ /^#{path_prefix}/
      
    end
  end
end