X-Git-Url: https://projects.mako.cc/source/selectricity-live/blobdiff_plain/dc635b6d39be19a09a428282b6d639d029908df6..22f84a3ea8bc39eb4cb91575d35dfca683336032:/app/controllers/account_controller.rb?ds=inline diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb new file mode 100644 index 0000000..c13203b --- /dev/null +++ b/app/controllers/account_controller.rb @@ -0,0 +1,45 @@ +class AccountController < ApplicationController + layout 'hc' + + # Be sure to include AuthenticationSystem in Application Controller instead + include AuthenticatedSystem + # If you want "remember me" functionality, add this before_filter to Application Controller + before_filter :login_from_cookie + + # say something nice, you goof! something sweet. + def index + redirect_to(:action => 'signup') unless logged_in? || User.count > 0 + end + + def login + return unless request.post? + self.current_user = User.authenticate(params[:login], params[:password]) + if logged_in? + if params[:remember_me] == "1" + self.current_user.remember_me + cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } + end + redirect_back_or_default(:controller => '/account', :action => 'index') + flash[:notice] = "Logged in successfully" + end + end + + def signup + @user = User.new(params[:user]) + return unless request.post? + @user.save! + self.current_user = @user + redirect_back_or_default(:controller => '/account', :action => 'index') + flash[:notice] = "Thanks for signing up!" + rescue ActiveRecord::RecordInvalid + render :action => 'signup' + end + + def logout + self.current_user.forget_me if logged_in? + cookies.delete :auth_token + reset_session + flash[:notice] = "You have been logged out." + redirect_back_or_default(:controller => '/account', :action => 'index') + end +end