Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AccountController < ApplicationController
- # 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
- ### Leaving this in ensures I dont ever get logged in... had to comment it out - 2007-01-11
- 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
- if current_user.super
- redirect_back_or_default(:controller => 'sms', :action => 'list' )
- else
- redirect_back_or_default(:controller => Site.find(current_user.site_id).name+'/sms', :action => 'show', :site_id => current_user.site_id )
- end
- flash[:notice] = "Logged in successfully"
- else
- flash[:notice] = "Username or password was incorrect"
- 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
- @site = nil
- flash[:notice] = "You have been logged out."
- redirect_back_or_default(:controller => '/account', :action => 'index')
- flash[:notice] = "A password reset link has been sent to your email address"
- else
- flash[:notice] = "Could not find a user with that email address"
- end
- end
- def reset_password
- @user = User.find_by_password_reset_code(params[:id])
- return if @user unless params[:password]
- if (params[:password] == params[:password_confirmation])
- self.current_user = @user #for the next two lines to work
- current_user.password_confirmation = params[:password_confirmation]
- current_user.password = params[:password]
- @user.reset_password
- flash[:notice] = current_user.save ? "Password reset" : "Password not reset"
- else
- flash[:notice] = "Password mismatch"
- end
- redirect_back_or_default(:controller => '/account', :action => 'index')
- end
- end
Add Comment
Please, Sign In to add comment