aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/application.rb
blob: e5c6a455b70b1749bd06ff30a359d8d649ba79cb (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
# 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.2 2007-08-01 16:41:32 francis Exp $


class ApplicationController < ActionController::Base
    # Pick a unique cookie name to distinguish our session data from others'
    session :session_key => '_foi_session_id'

    def check_authentication
        unless session[:user]
            session[:intended_action] = action_name
            session[:intended_controller] = controller_name
            redirect_to :action => "signin"
        end
    end

    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[:notice] = "Email or password not correct"
            end

        end
    end

    def signout
        sessions[:user] = nil
        redirect_to frontpage
    end

end