Module: Mumukit::Platform::WebFramework::Rails

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

Class Method Summary collapse

Class Method Details

.configure_controller!(controller_class) ⇒ Object

Configures forgery protection and mixes authentication methods.

Parameters:

  • controller_class (ActionController::Base::Class)


66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/mumukit/login/framework/rails.rb', line 66

def self.configure_controller!(controller_class)
  controller_class.class_eval do
    include Mumukit::Login::AuthenticationHelpers
    include Mumukit::Login::AuthorizationHelpers

    helper_method :current_user,
                  :current_user?,
                  :current_user_uid,
                  :mumukit_controller,
                  :login_form

  end
end

.configure_login_controller!(controller_class) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mumukit/login/framework/rails.rb', line 50

def self.(controller_class)
  controller_class.class_eval do
    include Mumukit::Login::LoginControllerHelpers

    %w(callback_current_user login_failure logout_current_user login_current_user).each do |method|
      define_method method do
        self.send "#{method}!"
      end
    end
  end
end

.configure_login_routes!(rails_router) ⇒ Object

Configures the login routes. This method should be used this way:

controller :sessions do
  Mumukit::Login.configure_session_controller_routes! self
end

Parameters:

  • rails_router (RailsRouter)


41
42
43
44
45
46
47
48
# File 'lib/mumukit/login/framework/rails.rb', line 41

def self.(rails_router)
  rails_router.controller :login do
    rails_router.match 'auth/:provider/callback' => :callback_current_user, via: [:get, :post]
    rails_router.get 'auth/failure' => :login_failure
    rails_router.get 'logout' => :logout_current_user
    rails_router.get 'login' => :login_current_user
  end
end

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



12
13
14
15
16
# File 'lib/mumukit/login/framework/rails.rb', line 12

def self.delete_cookie!(key, domain, rails_controller)
  rails_controller.instance_eval do
    cookies.delete key, domain: domain
  end
end

.env(rails_controller) ⇒ Object



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

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


18
19
20
21
22
# File 'lib/mumukit/login/framework/rails.rb', line 18

def self.read_cookie(key, rails_controller)
  rails_controller.instance_eval do
    cookies[key]
  end
end

.redirect!(path, rails_controller) ⇒ Object



24
25
26
# File 'lib/mumukit/login/framework/rails.rb', line 24

def self.redirect!(path, rails_controller)
  rails_controller.redirect_to path
end

.render_html!(html, rails_controller) ⇒ Object



28
29
30
# File 'lib/mumukit/login/framework/rails.rb', line 28

def self.render_html!(html, rails_controller)
  rails_controller.render html: html[:body].html_safe, layout: true
end

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



6
7
8
9
10
# File 'lib/mumukit/login/framework/rails.rb', line 6

def self.write_cookie!(key, value, rails_controller)
  rails_controller.instance_eval do
    cookies[key] = value
  end
end