summaryrefslogtreecommitdiff
path: root/packages/chef-server/app/controllers/openid_login.rb
blob: dfb621ca5c7247576d13fcaaa3850e1dfed7fcb9 (plain)
1
2
3
4
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
40
41
42
# Controller for handling the login, logout process for "users" of our
# little server.  Users have no password.  This is just an example.

require 'openid'

class OpenidLogin < Application

  provides :html, :json

  def index
    @headers['X-XRDS-Location'] = url(:controller => "server",
                                                  :action => "idp_xrds",
                                                  :only_path => false)
    display({ })
  end

  def submit
    user = params[:username]

    # if we get a user, log them in by putting their username in
    # the session hash.
    unless user.nil?
      session[:username] = user unless user.nil?
      session[:approvals] = []
      session[:notice] = "Your OpenID URL is <b>
        #{url(:controller => "openid_server", :action => "user_page", :username => params[:username])}
        </b><br/><br/>Proceed to step 2 below."
    else
      session[:error] = "Sorry, couldn't log you in. Try again."
    end
    
    redirect url(:controller => "openid_login")
  end

  def logout
    # delete the username from the session hash
    session[:username] = nil
    session[:approvals] = nil
    redirect url(:controller => "openid_login")
  end

end