]> projects.mako.cc - selectricity/blob - app/controllers/account_controller.rb
Merge Justin
[selectricity] / 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   def login
15     return unless request.post?
16     self.current_user = User.authenticate(params[:login], params[:password])
17     if logged_in?
18       if params[:remember_me] == "1"
19         self.current_user.remember_me
20         cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
21       end
22       redirect_back_or_default(:controller => '/site', :action => 'index')
23       flash[:notice] = "Logged in successfully"
24     end
25   end
26
27   def signup
28     @user = User.new(params[:user])
29     return unless request.post?
30     @user.save!
31     self.current_user = @user
32     redirect_back_or_default(:controller => '/site', :action => 'index')
33     flash[:notice] = "Thanks for signing up!"
34   rescue ActiveRecord::RecordInvalid
35     render :action => 'signup'
36   end
37   
38   def logout
39     self.current_user.forget_me if logged_in?
40     cookies.delete :auth_token
41     reset_session
42     flash[:notice] = "You have been logged out."
43     redirect_back_or_default(:controller => '/site', :action => 'index')
44   end
45 end

Benjamin Mako Hill || Want to submit a patch?