class UsersController < ApplicationController layout 'application' before_filter :not_logged_in_required, :only => [:new, :create] before_filter :login_required, :only => [:show, :edit, :update] before_filter :check_super_user_role, :only => [:index, :destroy, :enable, :force_activate] def index @html_title = "User list on " @users = User.paginate(:page=> params[:page], :per_page => 30, :order => "email" ) end def show @user = User.find(params[:id]) || current_user @mymaps = @user.maps.paginate(:page => params[:page],:per_page => 8, :order => "updated_at DESC") @html_title = "#{@user.login.capitalize}'s User Page on " end # render new.rhtml def new @user = User.new end def create cookies.delete :auth_token @user = User.new(params[:user]) @user.save! # Uncomment to have the user automatically # logged in after creating an account - Not Recommended # self.current_user = @user flash[:notice] = "Thanks for signing up! Please check your email to activate your account before logging in. If you dont recieve an email, then %s" flash[:notice_item] = ["click here to resend the email", resend_activation_path] redirect_to login_path rescue ActiveRecord::RecordInvalid flash[:error] = "There was a problem creating your account." render :action => 'new' end def edit @user = current_user @html_title = @user.login + " Edit User Profile - " end def update @user = User.find(current_user) if @user.update_attributes(params[:user]) flash[:notice] = "User updated" redirect_to :action => 'show', :id => current_user else render :action => 'edit' end end def destroy @user = User.find(params[:id]) if @user.update_attribute(:enabled, false) flash[:notice] = "User disabled" else flash[:error] = "There was a problem disabling this user." end redirect_to :action => 'index' end def enable @user = User.find(params[:id]) if @user.update_attribute(:enabled, true) flash[:notice] = "User enabled" else flash[:error] = "There was a problem enabling this user." end redirect_to :action => 'index' end def activate logout_keeping_session! user = User.find_by_activation_code(params[:id]) unless params[:id].blank? case when (!params[:id].blank?) && user && !user.active? User.find_and_activate!(params[:id]) flash[:notice] = "Signup complete! Please sign in to continue." redirect_to '/login' when params[:id].blank? flash[:error] = "The activation code was missing. Please follow the URL from your email." redirect_back_or_default('/') else flash[:error] = "We couldn't find a user with that activation code -- check your email? Or maybe you've already activated -- try signing in." redirect_back_or_default('/') end end # def activate # @user = User.find_by_activation_code(params[:id]) unless params[:id].blank? # if @user and @user.activate # self.current_user = @user # # redirect_back_or_default(:action => 'show') # flash[:notice] = "Signup complete! Please sign in to continue." # redirect_to login_path # elsif params[:id].blank? # flash[:error] = "The activation code was missing. Please follow the URL from your email." # redirect_back_or_default('/') # else # flash[:error] = "We couldn't find a user with that activation code -- check your email? Or maybe you've already activated -- try signing in." # redirect_back_or_default('/') # end # end #called from admin console thingy def force_activate @user = User.find(params[:id]) if !@user.active? @user.force_activate! if @user.active? flash[:notice] = "User activated" else flash[:error] = "There was a problem activating this user." end else flash[:notice] = "User already active" end redirect_to :action => 'index' end def resend_activation return unless request.post? @user = User.find_by_email(params[:email]) if @user && !@user.active? flash[:notice] = "Activation email has been resent, check your email." UserMailer.deliver_signup_notification(@user) redirect_to login_path and return else flash[:notice] = "Activation email was not sent, either because the email was not the same as you gave when you signed up, or you have already been activated!" end end end