57cf343ea9de01ab95d67c6de556130df0ef4d1e
[selectricity] / app / controllers / account_controller.rb
1 # Selectricity: Voting Machinery for the Masses
2 # Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
3 # Copyright (C) 2007 Massachusetts Institute of Technology
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Affero General Public License for more details.
14 #
15 # You should have received a copy of the GNU Affero General Public
16 # License along with this program.  If not, see
17 # <http://www.gnu.org/licenses/>.
18
19 class AccountController < ApplicationController
20   layout 'main'
21   
22   # Be sure to include AuthenticationSystem in Application Controller instead
23   include AuthenticatedSystem
24   # If you want "remember me" functionality, add this before_filter to Application Controller
25   before_filter :login_from_cookie
26
27   # say something nice, you goof!  something sweet.
28   def index
29     redirect_to(:action => 'signup') unless logged_in? || User.count > 0
30   end
31   
32   #these methods provide basic functionality for the user login system
33   #===================================================================
34   def login
35     
36     return unless request.post?
37     self.current_user = User.authenticate(params[:login], params[:password])
38     if logged_in?
39       if params[:remember_me] == "1"
40         self.current_user.remember_me
41         cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
42       end
43       redirect_back_or_default :controller => 'front'
44       flash[:notice] = "Logged in successfully"
45     end
46   end
47   
48   def forgot_password
49     raise "Not Implemented!"
50   end
51
52   def signup
53     @user = User.new(params[:user])
54     return unless request.post?
55     @user.save!
56     self.current_user = @user
57     redirect_back_or_default :controller => 'front'
58     flash[:notice] = "Thanks for signing up!"
59   rescue ActiveRecord::RecordInvalid
60     render :action => 'signup'
61   end
62   
63   def logout
64     self.current_user.forget_me if logged_in?
65     cookies.delete :auth_token
66     reset_session
67     flash[:notice] = "You have been logged out."
68     redirect_back_or_default :controller => 'front'
69   end
70   #======================================================================
71   
72   #The following methods are for slectricity specific uses
73   def summary
74     @user = User.find(params[:id])
75   end
76   
77   
78 end
79
80

Benjamin Mako Hill || Want to submit a patch?