public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
insoshi / app / controllers / people_controller.rb
100644 131 lines (115 sloc) 3.628 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
class PeopleController < ApplicationController
  
  skip_before_filter :require_activation, :only => :verify
  skip_before_filter :admin_warning, :only => [ :show, :update ]
  before_filter :login_required, :only => [ :edit, :update ]
  before_filter :correct_user_required, :only => [ :edit, :update ]
  before_filter :setup
  
  def index
    @people = Person.active(params[:page])
 
    respond_to do |format|
      format.html
    end
  end
  
  def show
    @person = Person.find(params[:id], :include => :activities)
    if @person.deactivated?
      flash[:error] = "That person has been deactivated"
      redirect_to home_url and return
    end
    if logged_in?
      @common_connections = current_person.common_connections_with(@person)
    end
    if current_person?(@person)
      link = edit_person_path(@person)
      flash.now[:notice] = %(You are viewing your own profile.
<a href="#{link}">Click here to edit it</a>)
    end
    respond_to do |format|
      format.html
    end
  end
  
  def new
    @body = "register single-col"
    @person = Person.new
 
    respond_to do |format|
      format.html
    end
  end
 
  def create
    cookies.delete :auth_token
    @person = Person.new(params[:person])
    respond_to do |format|
      if @person.save
        self.current_person = @person
        if global_prefs.email_verifications?
          # TODO: move some of this into models.
          @person.deactivated = true; @person.save!
          @verification = EmailVerification.create(:person => @person)
          @person.email_verifications << @verification
          flash[:notice] = %(Thanks for signing up! A verification email has
been sent to #{@person.email}.)
          format.html { redirect_to(home_url) }
        else
          flash[:notice] = "Thanks for signing up!"
          format.html { redirect_back_or_default(home_url) }
        end
      else
        @body = "register single-col"
        format.html { render :action => 'new' }
      end
    end
  end
 
  def verify
    verification = EmailVerification.find_by_code(params[:id])
    if verification.nil?
      flash[:error] = "Invalid email verification code"
      redirect_to home_url
    else
      verification.person.deactivated = false; verification.person.save!
      flash[:success] = "Email verified. Your profile is active!"
      redirect_to verification.person
    end
  end
 
  def edit
    @person = Person.find(params[:id])
 
    respond_to do |format|
      format.html
    end
  end
 
  def update
    @person = Person.find(params[:id])
    respond_to do |format|
      case params[:type]
      when 'info_edit'
        if @person.update_attributes(params[:person])
          flash[:success] = 'Profile updated!'
          format.html { redirect_to(@person) }
        else
          format.html { render :action => "edit" }
        end
      when 'password_edit'
        if @person.change_password?(params[:person])
          flash[:success] = 'Password changed.'
          format.html { redirect_to(@person) }
        else
          format.html { render :action => "edit" }
        end
      end
    end
  end
  
  def common_contacts
    @person = Person.find(params[:id])
    @common_connections = @person.common_connections_with(current_person,
                                                          params[:page])
    respond_to do |format|
      format.html
    end
  end
  
  private
 
    def setup
      @body = "person"
    end
  
    def correct_user_required
      redirect_to home_url unless Person.find(params[:id]) == current_person
    end
end