Module: Mumukit::Platform::WebFramework::Sinatra

Defined in:
lib/mumukit/login/framework/sinatra.rb

Class Method Summary collapse

Class Method Details

.configure_controller!(sinatra_helpers) ⇒ Object



49
50
51
52
53
54
# File 'lib/mumukit/login/framework/sinatra.rb', line 49

def self.configure_controller!(sinatra_helpers)
  sinatra_helpers.instance_eval do
    include Mumukit::Login::AuthenticationHelpers
    include Mumukit::Login::AuthorizationHelpers
  end
end

.configure_login_controller!(sinatra_helpers) ⇒ Object



43
44
45
46
47
# File 'lib/mumukit/login/framework/sinatra.rb', line 43

def self.(sinatra_helpers)
  sinatra_helpers.instance_eval do
    include Mumukit::Login::LoginControllerHelpers
  end
end

.configure_login_routes!(sinatra_module) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/mumukit/login/framework/sinatra.rb', line 31

def self.(sinatra_module)
  sinatra_module.instance_eval do
    auth_callback = proc { callback_current_user! }
    get '/auth/:provider/callback', &auth_callback
    post '/auth/:provider/callback', &auth_callback
    get('/auth/failure') {  }
    get('/logout') { logout_current_user! }
    get('/login') {  }
  end
end

.delete_cookie!(key, domain, sinatra_handler) ⇒ Object



10
11
12
# File 'lib/mumukit/login/framework/sinatra.rb', line 10

def self.delete_cookie!(key, domain, sinatra_handler)
  sinatra_handler.response.delete_cookie key, domain: domain
end

.env(sinatra_handler) ⇒ Object



2
3
4
# File 'lib/mumukit/login/framework/sinatra.rb', line 2

def self.env(sinatra_handler)
  sinatra_handler.request.env
end


14
15
16
# File 'lib/mumukit/login/framework/sinatra.rb', line 14

def self.read_cookie(key, sinatra_handler)
  sinatra_handler.request.cookies[key]
end

.redirect!(path, sinatra_handler) ⇒ Object



18
19
20
# File 'lib/mumukit/login/framework/sinatra.rb', line 18

def self.redirect!(path, sinatra_handler)
  sinatra_handler.redirect path
end

.render_html!(html, sinatra_handler) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/mumukit/login/framework/sinatra.rb', line 22

def self.render_html!(html, sinatra_handler)
<<HTML
<html>
<head>#{html[:header]}</head>
<body>#{html[:body]}</body>
</html>
HTML
end

.write_cookie!(key, value, sinatra_handler) ⇒ Object



6
7
8
# File 'lib/mumukit/login/framework/sinatra.rb', line 6

def self.write_cookie!(key, value, sinatra_handler)
  sinatra_handler.response.set_cookie key, value
end