~acesuares/qspell/trunk

« back to all changes in this revision

Viewing changes to vendor/plugins/vote_fu/examples/users_controller.rb

  • Committer: Ace Suares
  • Date: 2009-10-07 06:16:20 UTC
  • Revision ID: ace@suares.an-20091007061620-j39st30s42edy61t
 * voting with vote_fu

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# I usually use the user class from restful_authentication as my principle voter class
 
2
# There are generally no changes required to support voting in this controller. 
 
3
 
 
4
class UsersController < ApplicationController
 
5
  # Be sure to include AuthenticationSystem in Application Controller instead
 
6
  include AuthenticatedSystem
 
7
  
 
8
  # Protect these actions behind an admin login
 
9
  before_filter :admin_required, :only => [:suspend, :unsuspend, :destroy, :purge]
 
10
  before_filter :find_user, :only => [:suspend, :unsuspend, :destroy, :purge, :show]
 
11
 
 
12
  before_filter :login_required, :only => [:index]
 
13
 
 
14
  # render new.html.erb
 
15
  def new
 
16
  end
 
17
 
 
18
  # GET /users/:id
 
19
  def show
 
20
  end
 
21
  
 
22
 
 
23
  def create
 
24
    cookies.delete :auth_token
 
25
    @user = User.new(params[:user])
 
26
    @user.register! if @user.valid?
 
27
    if @user.errors.empty?
 
28
      self.current_user.forget_me if logged_in?
 
29
      cookies.delete :auth_token
 
30
      reset_session
 
31
      flash[:notice] = "Thanks for signing up!"
 
32
    else
 
33
      render :action => 'new'
 
34
    end
 
35
  end
 
36
 
 
37
  def activate
 
38
    unless params[:activation_code].blank?
 
39
      self.current_user = User.find_by_activation_code(params[:activation_code])
 
40
      if logged_in? && !current_user.active?
 
41
        current_user.activate!
 
42
        flash[:notice] = "Signup complete!"
 
43
        redirect_back_or_default('/')
 
44
      else
 
45
        flash[:error] = "Sorry, we couldn't find that activation code. Please cut and paste your activation code into the space at left."
 
46
      end
 
47
    end
 
48
    # render activate.html.erb    
 
49
  end
 
50
 
 
51
  def suspend
 
52
    @user.suspend! 
 
53
    redirect_to users_path
 
54
  end
 
55
 
 
56
  def unsuspend
 
57
    @user.unsuspend! 
 
58
    redirect_to users_path
 
59
  end
 
60
 
 
61
  def destroy
 
62
    @user.delete!
 
63
    redirect_to users_path
 
64
  end
 
65
 
 
66
  def purge
 
67
    @user.destroy
 
68
    redirect_to users_path
 
69
  end
 
70
 
 
71
protected
 
72
  def find_user
 
73
    @user = User.find(params[:id])
 
74
  end
 
75
 
 
76
end