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
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.
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.
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/>.
19 class AccountController < ApplicationController
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
27 # say something nice, you goof! something sweet.
29 redirect_to(:action => 'signup') unless logged_in? || User.count > 0
32 #these methods provide basic functionality for the user login system
33 #===================================================================
36 return unless request.post?
37 self.current_user = User.authenticate(params[:login], params[:password])
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 }
43 redirect_back_or_default :controller => 'front'
44 flash[:notice] = "Logged in successfully"
49 raise "Not Implemented!"
53 @user = User.new(params[:user])
54 return unless request.post?
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'
64 self.current_user.forget_me if logged_in?
65 cookies.delete :auth_token
67 flash[:notice] = "You have been logged out."
68 redirect_back_or_default :controller => 'front'
70 #======================================================================
72 #The following methods are for selectricity specific uses
74 @user = User.find(params[:id])