Class: ElsSessionController

Inherits:
ApplicationController
  • Object
show all
Includes:
ElsToken
Defined in:
app/controllers/els_session_controller.rb

Defined Under Namespace

Classes: ElsFaker

Instance Method Summary collapse

Instance Method Details

#createObject

Should not get here during production



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/els_session_controller.rb', line 29

def create
  begin
    if params["override"]
      # just fake the session
      logger.debug("faking session with id #{params["username"]}")
      @els_identity = ElsFaker.new(params["username"])
    else
      logger.debug("attempting to authenticate #{params["username"]}")
      token = authenticate(params["username"],params["password"])
      logger.debug("got token #{token}")
      if token
        @els_identity = get_token_identity(token)
        flash[:notice] = "cannot retrieve identity" unless @els_identity
      else
        flash[:error] = "unable to authenticate"
      end
    end
  rescue Exception => e
    flash[:error] = "Something went wrong #{e.message}"
  end
  if @els_identity
    update_and_return
  else
    render :new
  end
end

#destroyObject



56
57
58
59
60
61
62
# File 'app/controllers/els_session_controller.rb', line 56

def destroy
  Rails.cache.delete(session[:els_token], :namespace => "els_identity")
  session[:els_token] = nil
  session[:redirect_to] = nil
  cookies.delete(self.class.els_options['cookie'], :domain => request.env["SERVER_NAME"])
  redirect_to els_session_new_path
end

#newObject

When in dev/qa we may need to provide credentials if ELS has not been setup this will be valid if a known cookie exists



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/els_session_controller.rb', line 14

def new
  @els_identity = get_identity rescue nil
  if @els_identity
    logger.debug("retrieved els identity #{@els_identity.inspect}")
    session[:els_token] = @els_identity.token_id
    Rails.cache.write(session[:els_token], @els_identity, 
      :namespace => "els_identity",
      :expires_in => 1.hour)
    go_back
  end
  logger.debug("unable to retrieve els identity :(")
  # or get some login details  
end

#showObject



8
9
# File 'app/controllers/els_session_controller.rb', line 8

def show
end