Class: AccountController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/account_controller.rb

Instance Method Summary collapse

Instance Method Details

#activateObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/account_controller.rb', line 8

def activate
  if logged_in?
    redirect_to "/"
    return
  end

  @account = Account.find params[:account]

  if not @account.nil? and @account.activation_key == params[:activation_key]
    @account.active = true
    @account.activation_key = nil
    @account.save
  else
    redirect_to :action => :activation_error
  end
end

#activation_errorObject



104
105
# File 'app/controllers/account_controller.rb', line 104

def activation_error
end

#add_openidObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'app/controllers/account_controller.rb', line 110

def add_openid
  if using_open_id?
    authenticate_with_open_id(params[:openid_url]) do |result, identity_url|
      if result.successful?
        id = OpenIdIdentity.find_by_identity_url(identity_url)
        if id.nil?
          id = OpenIdIdentity.new :person => logged_in_person, :identity_url => identity_url
        else
          if id.person.nil?
            id.person = logged_in_person
          elsif id.person != logged_in_person
            flash[:error_messages] = ["That OpenID belongs to a different person (#{id.person.name})."]
            return
          end
        end
        if not id.save
          flash[:error_messages] = id.errors.collect { |e| e[0].humanize + " " + e[1] }
        end
      else
        flash[:error_messages] = [result.message]
      end
      redirect_to :action => 'edit_profile'
    end
  else
    flash[:error_messages] = ["Please enter an OpenID url."]
  end
end

#change_passwordObject



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/account_controller.rb', line 90

def change_password
  password = params[:password]
  if password[:password1].nil? or password[:password2].nil?
    redirect_to :action => :edit_profile
  elsif password[:password1] != password[:password2]
    flash[:error_messages] = ["The passwords you entered don't match.  Please try again."]
    redirect_to :action => :edit_profile
  else
    acct = logged_in_person.
    acct.password = password[:password1]
    acct.save
  end
end

#delete_openidObject



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'app/controllers/account_controller.rb', line 138

def delete_openid
  id = OpenIdIdentity.find(params[:id])
  if id.person == logged_in_person
    if logged_in_person. or logged_in_person.open_id_identities.length > 1
      id.destroy
    else
      flash[:error_messages] = ["Deleting that OpenID would leave you no way of logging in!"]
    end
  else
    flash[:error_messages] = ["That OpenID does not belong to you!"]
  end
  redirect_to :action => 'edit_profile'
end

#edit_email_addressesObject



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
# File 'app/controllers/account_controller.rb', line 39

def edit_email_addresses
  errs = []
  
  if params[:new_address] and params[:new_address].length > 0
    existing_ea = EmailAddress.find_by_address params[:new_address]
    if existing_ea
      errs.push "A different person is already associated with the email address you tried to add."
    else
      newea = EmailAddress.create :person => logged_in_person, :address => params[:new_address]
      if params[:primary] == 'new'
        newea.primary = true
        newea.save
      end
    end
  end
  
  if params[:primary] and params[:primary] != 'new'
    id = params[:primary].to_i
    if id != 0
      addr = EmailAddress.find id
      if addr.person != logged_in_person
        errs.push "The email address you've selected as primary belongs to a different person."
      else
        addr.primary = true
        addr.save
      end
    else
      errs.push "The email address you've selected as primary doesn't exist."
    end
  end
  
  if params[:delete]
    params[:delete].each do |id|
      addr = EmailAddress.find id
      if addr.person != logged_in_person
        errs.push "The email address you've selected to delete belongs to a different person."
      elsif addr.primary
        errs.push "You can't delete your primary email address.  Try making a different email address your primary address first."
      else
        addr.destroy
      end
    end
  end
  
  if errs.length > 0
    flash[:error_messages] = errs
  end
  
  redirect_to :action => :edit_profile
end

#edit_profileObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/account_controller.rb', line 25

def edit_profile
  @person = logged_in_person
  if not AeUsers.profile_class.nil?
    @app_profile = AeUsers.profile_class.find_by_person_id(@person.id)
  end
  
  if request.post?
    @person.update_attributes params[:person]
    if @app_profile
      @app_profile.update_attributes params[:app_profile]
    end
  end
end

#signupObject



152
153
154
155
156
157
158
159
# File 'app/controllers/account_controller.rb', line 152

def 
  ret = ()
  if ret == :success
    redirect_to :action => 'signup_success'
  elsif ret == :no_activation
    redirect_to :action => :signup_noactivation
  end
end

#signup_successObject



107
108
# File 'app/controllers/account_controller.rb', line 107

def 
end