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. Please see the COPYING file for
8 class AccountController < ApplicationController
11 # Be sure to include AuthenticationSystem in Application Controller instead
12 include AuthenticatedSystem
13 # If you want "remember me" functionality, add this before_filter to Application Controller
14 before_filter :login_from_cookie
16 # say something nice, you goof! something sweet.
18 redirect_to(:action => 'signup') unless logged_in? || User.count > 0
21 #these methods provide basic functionality for the user login system
22 #===================================================================
25 return unless request.post?
26 self.current_user = User.authenticate(params[:login], params[:password])
28 if params[:remember_me] == "1"
29 self.current_user.remember_me
30 cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
32 redirect_back_or_default :controller => 'front'
33 flash[:notice] = "Logged in successfully"
38 raise "Not Implemented!"
42 @user = User.new(params[:user])
43 return unless request.post?
45 self.current_user = @user
46 redirect_back_or_default :controller => 'front'
47 flash[:notice] = "Thanks for signing up!"
48 rescue ActiveRecord::RecordInvalid
49 render :action => 'signup'
53 self.current_user.forget_me if logged_in?
54 cookies.delete :auth_token
56 flash[:notice] = "You have been logged out."
57 redirect_back_or_default :controller => 'front'
59 #======================================================================
61 #The following methods are for selectricity specific uses
63 @user = User.find(params[:id])
67 @user = User.find(params[:id])
68 return unless request.post?
69 @user.email=params[:email]
71 flash[:notice] = "Email successfully updated"
72 render :action => 'summary'