blob: 34c357c612cd9728a2d6854b8c7e3a74f845b0cf (
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# controllers/application.rb:
# Parent class of all controllers in FOI site. Filters added to this controller
# apply to all controllers in the application. Likewise, all the methods added
# will be available for all controllers.
#
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
# $Id: application.rb,v 1.6 2007-09-12 15:27:15 francis Exp $
class ApplicationController < ActionController::Base
# Standard hearders, footers and navigation for whole site
layout "default"
# Pick a unique cookie name to distinguish our session data from others'
session :session_key => '_foi_session_id'
# Login form
def signin
if request.post?
user = User.authenticate(params[:email], params[:password])
if user
session[:user] = user.id
redirect_to :action => session[:intended_action], :controller => session[:intended_controller]
else
flash[:error] = "Email or password not correct"
end
end
render :template => 'user_accounts/signin'
end
# Logout form
def signout
sessions[:user] = nil
redirect_to frontpage
end
private
# Check the user is logged in
def check_authentication
unless session[:user]
session[:intended_action] = action_name
session[:intended_controller] = controller_name
redirect_to :action => "signin"
end
end
# For administration interface, return display name of authenticated user
def admin_http_auth_user
if not request.env["REMOTE_USER"]
return "*unknown*";
else
return request.env["REMOTE_USER"]
end
end
end
|