Class: Goldberg::AuthController

Inherits:
ApplicationController show all
Includes:
Controller
Defined in:
lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/auth_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Controller

included

Methods included from Six::Import::Controller::ClassMethods

#copy, #six_local_auto_login

Methods inherited from ActionController::Base

#active_scaffold_render_secure_download, #assign_names_with_active_scaffold, #render_with_active_scaffold, #search_generic_view_paths?

Class Method Details

.set_user(session, user_id = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/auth_controller.rb', line 5

def self.set_user(session, user_id = nil)
  find_user_id = user_id || session[:goldberg][:user_id]
  Goldberg.user = (if find_user_id then Goldberg::User.find(find_user_id) else nil end)
  
  if Goldberg.user
    role = Goldberg.user.role
  else
    role = Goldberg::Role.find(Goldberg.settings.public_role_id)
  end
    
  if role
    if not role.cache or not role.cache.has_key?(:credentials)
      Role.rebuild_cache
      role = Goldberg::Role.find(role.id)
    end
    # session[:credentials] = role.cache[:credentials]
    Goldberg.credentials = role.cache[:credentials]
    Goldberg.menu = role.cache[:menu]
    session[:goldberg][:menu_history] ||= Hash.new
    if session[:goldberg][:menu_history].has_key?(session[:goldberg][:path])
      Goldberg.menu.select(session[:goldberg][:menu_history][session[:goldberg][:path]])
    else
      Goldberg.menu.select(session[:goldberg][:menu_item])
      session[:goldberg][:menu_history][session[:goldberg][:path]] =
        session[:goldberg][:menu_item]
    end
    logger.info "Logging in user as role #{role.name}"
  else
    logger.error "Something went seriously wrong with the role"
  end

  if Goldberg.user 
    session[:goldberg][:user_id] = Goldberg.user.id
  end
end

Instance Method Details

#loginObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/auth_controller.rb', line 41

def 
  if request.get?
    if Goldberg.user #if user goes to login url or hits back button and is already logged in
      redirect_to Goldberg.user.get_start_path
    else
      reset_session #double check there isn't a stale session
      render :action => 'login'
   end
  else
    user = User.find_by_name(params[:login][:name])
    
    if user and user.check_password(params[:login][:password])
      logger.info "User #{params[:login][:name]} successfully logged in"
      Goldberg.user = user
      self.class.set_user(session, user.id)

      respond_to do |wants|
        wants.html do
          if session[:pending_request]
            logger.info "Pending request: #{session[:pending_request].inspect}"
            pending = session[:pending_request]
            session[:pending_request] = nil
            redirect_to pending
          else
            redirect_to user.get_start_path
          end
        end
        wants.xml do
          render :nothing => true, :status => 200
        end
      end
      
    else
      logger.warn "Failed login attempt"
      respond_to do |wants|
        wants.html do
          flash.now[:error] = "Incorrect username/password"
          render :action => 'login'
        end
        wants.xml do
          render :nothing => true, :status => 404
        end
      end
    end
  end
end

#logoutObject

def login



88
89
90
91
92
93
94
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/auth_controller.rb', line 88

def logout 
  if request.post?
    reset_session
  end 
  flash[:notice] = 'You are now logged out.'
  redirect_to Goldberg.settings.public_role.get_start_path 
end