Merge head
[selectricity-live] / app / controllers / account_controller.rb
1 class AccountController < ApplicationController
2   layout 'main'
3   
4   # Be sure to include AuthenticationSystem in Application Controller instead
5   include AuthenticatedSystem
6   # If you want "remember me" functionality, add this before_filter to Application Controller
7   before_filter :login_from_cookie
8
9   # say something nice, you goof!  something sweet.
10   def index
11     redirect_to(:action => 'signup') unless logged_in? || User.count > 0
12   end
13   
14   #these methods provide basic functionality for the user login system
15   #===================================================================
16   def login
17     return unless request.post?
18     self.current_user = User.authenticate(params[:login], params[:password])
19     if logged_in?
20       if params[:remember_me] == "1"
21         self.current_user.remember_me
22         cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
23       end
24       redirect_back_or_default(:controller => '/site', :action => 'index')
25       flash[:notice] = "Logged in successfully"
26     end
27   end
28   
29   def forgot_password
30     raise "Not Implemented!"
31   end
32
33   def signup
34     @user = User.new(params[:user])
35     return unless request.post?
36     @user.save!
37     self.current_user = @user
38     redirect_back_or_default(:controller => '/site', :action => 'index')
39     flash[:notice] = "Thanks for signing up!"
40   rescue ActiveRecord::RecordInvalid
41     render :action => 'signup'
42   end
43   
44   def logout
45     self.current_user.forget_me if logged_in?
46     cookies.delete :auth_token
47     reset_session
48     flash[:notice] = "You have been logged out."
49     redirect_back_or_default(:controller => '/site', :action => 'index')
50   end
51   #======================================================================
52   
53   #The following methods are for slectricity specific uses
54   def summary
55     @user = User.find(params[:id])
56   end
57   
58   
59 end
60
61

Benjamin Mako Hill || Want to submit a patch?