Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AccountController < ApplicationController
- observer :user_observer
- # If you want "remember me" functionality, add the this before_filter uncommended to Application Controller
- # before_filter :login_from_cookie
- # the below method is to be deleted, It's from Authentication module
- # def logged_in?
- # (@current_user ||= session[:user] ? User.find_by_id(session[:user]) : :false).is_a?(User)
- # end
- 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 current_user
- 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 => '/contract', :action => 'index')
- flash[:notice] = "Logged in successfully as #{ current_user.login }"
- else
- flash[:notice] = "Either the username or password are incorrect."
- end
- end
- def signup
- @user = User.new(params[:user])
- return unless request.post?
- if @user.save
- redirect_back_or_default(:controller => 'contract', :action => 'index')
- flash[:notice] = "Thank You for applying for membership."
- end
- 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
- def change_password
- return unless request.post?
- if User.authenticate(current_user.login, params[:old_password])
- if (params[:password] == params[:password_confirmation])
- # why is this attrribute set? it seems redundant
- current_user.password_confirmation = params[:password_confirmation]
- current_user.password = params[:password]
- # somehow, this save is setting activated_at to null
- flash[:notice] = current_user.save ?
- "Password changed" :
- "Password not changed"
- else
- flash[:notice] = "Password mismatch"
- @old_password = params[:old_password]
- end
- else
- flash[:notice] = "Wrong password"
- end
- end
- def activate
- if params[:activation_code]
- @user = User.find_by_activation_code(params[:activation_code])
- if @user and @user.activate
- self.current_user = @user
- redirect_back_or_default(:controller => '/account', :action => 'index')
- flash[:notice] = "Your account has been activated."
- else
- flash[:error] = "Unable to activate the account. Did you provide the correct information?"
- end
- else
- flash.clear
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement