Class AccountsController
In: app/controllers/accounts_controller.rb
Parent: ApplicationController

Methods

Public Instance methods

[Source]

     # File app/controllers/accounts_controller.rb, line 267
267:   def activate
268:     @activation = params[:activation]
269:     @email = params[:email]
270:     @user = User.find_by_email(@email)
271:     if request.post?
272:       if @user && @activation && params[:password]
273:         @user.activate(@activation)
274:         if @user.is_activated && User.authenticate(@email, params[:password])
275:           allow_access(@user)
276:           flash[:notice] = I18n.t('account_successfully_activated', :scope => 'messages.account', :email => @user.email)
277:         else
278:           @user.deactivate
279:           flash[:notice] = I18n.t('error_unable_to_activate_user_account', :scope => 'messages.account')
280:         end      
281:       end
282:       
283:       respond_to do |format|
284:         if @user && @user.is_activated
285:           redirect_to( '/' )
286:           return 
287:         else
288:           flash[:notice] = I18n.t('error_unable_to_verify_activation', :scope => 'messages.account')
289:           format.html { render :action => 'activate' }  
290:           format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
291:         end
292:       end
293:     end
294:   end

[Source]

     # File app/controllers/accounts_controller.rb, line 133
133:   def change_password
134:     @user = current_user
135: 
136:     # do not allow someone to change account information that is not their own
137:     unless @user
138:       flash[:notice] = I18n.t('please_login_to_change_account', :scope => 'messages.account')
139:       default_redirect_to
140:       return
141:     end
142: 
143:     if request.post?
144:       respond_to do |format|
145:         if @user.update_password(params[:current_password], params[:new_password], params[:confirm_password]) && @user.save!
146:           flash[:notice] = I18n.t('password_updated', :scope => 'messages.account')
147:           redirect_to( :action => 'my_account', :id => @user.id)
148:           return
149:         else
150:           flash.now[:notice] = I18n.t('unable_to_update_password', :scope => 'messages.account')
151:           format.html { render :action => 'change_password' }  
152:           format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
153:         end
154:       end
155:     end     
156:   end

[Source]

    # File app/controllers/accounts_controller.rb, line 9
 9:   def confirm_password_reset
10:     @email = params[:user] ? params[:user][:email] : params[:email]
11:     @user = User.find_by_email(@email)
12:     @confirmation = params[:confirmation]
13:     if @user && @confirmation
14:       begin
15:         if @user.confirm?(@confirmation)
16:           new_password = @user.reset_password
17:           UserMailer.deliver_new_account_password(@user, new_password)
18:           flash[:notice] = I18n.t('email_sent', :scope => 'messages.account', :email => @user.email)
19:           redirect_to( :action => 'login', :email => @user.email)
20:         else
21:           flash.now[:notice] = I18n.t('cannot_confirm_password', :scope => 'messages.account')
22:         end
23:       rescue Exception => exception
24:         logger.error(exception.backtrace.join("  \n"))
25:         flash.now[:notice] = I18n.t('error_unable_to_send_reset_password', :scope => 'messages.account', :email => @user.email, :reason => exception.message)
26:       end
27:     else
28:         flash.now[:notice] = I18n.t('submit_email_and_confirmation_key', :scope => 'messages.account')
29:     end    
30:   end

[Source]

     # File app/controllers/accounts_controller.rb, line 158
158:   def delete_account
159:     @user = current_user
160: 
161:     # do not allow someone to delete account information that is not their own
162:     unless @user
163:       flash[:notice] = I18n.t('please_login_to_delete_account', :scope => 'messages.account')
164:       default_redirect_to
165:       return
166:     end
167: 
168:     respond_to do |format|
169:       if @user.delete
170:         flash[:notice] = I18n.t('account_deleted', :scope => 'messages.account')
171:         redirect_to( '/')
172:         return
173:       else
174:         flash.now[:notice] = I18n.t('unable_to_delete_account', :scope => 'messages.account')
175:         format.html { render :action => 'my_account' }  
176:         format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
177:         return
178:       end
179:     end
180:   end

[Source]

     # File app/controllers/accounts_controller.rb, line 221
221:   def login
222:     session[:user_id] = nil
223:     
224:     if request.post?
225:       email = params[:email]
226:       
227:       if "on" == params[:save_email]
228:         cookies[:email] = { 
229:           :value => params[:email],
230:           :expires => 10.year.from_now
231:         }
232:       else
233:         cookies.delete(:email) if cookies[:email]
234:       end
235: 
236:       if not User.exists?(email)
237:         flash.now[:notice] = I18n.t('invalid_email_or_password', :scope => 'messages.account')
238:       elsif !User.is_activated?(email)
239:          link = I18n.t('resend_activation_link', :scope => 'messages.account', :email => email)
240:          flash.now[:notice] = I18n.t('account_not_activated', :scope => 'messages.account', :link => link)
241:       else
242:         password = params[:password]
243:         user = User.authenticate(email, password)
244:         if user
245:           allow_access user
246:           uri = session[:original_url]
247:           session[:original_url] = nil
248:           redirect_to( uri || '/' )
249:           return
250:         elsif User.is_activated?(params[:email])
251:           flash.now[:notice] = I18n.t('invalid_email_or_password', :scope => 'messages.account')
252:         end
253:       end
254:     end    
255:     respond_to do |format|
256:       format.html
257:       format.xml
258:     end    
259:   end

[Source]

     # File app/controllers/accounts_controller.rb, line 261
261:   def logout
262:     session.delete
263:     flash.now[:notice] = I18n.t('logged_out', :scope => 'messages.account')
264:     redirect_to('/')
265:   end

[Source]

     # File app/controllers/accounts_controller.rb, line 201
201:   def my_account
202:     if request.post?
203:         
204:       @user.first_name = params[:user][:first_name] ? params[:user][:first_name] : @user.first_name
205:       @user.last_name  = params[:user][:last_name]  ? params[:user][:last_name]  : @user.last_name
206:       @user.email      = params[:user][:email]      ? params[:user][:email]      : @user.email
207:         
208:       respond_to do |format|
209:         if @user.save!
210:           flash[:notice]       = I18n.t('account_successfully_updated', :scope => 'messages.account')
211:           redirect_to( :action => 'my_account')
212:           return
213:         else
214:           format.html { render :action => 'my_account' }  
215:           format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
216:         end
217:       end
218:     end    
219:   end

[Source]

     # File app/controllers/accounts_controller.rb, line 182
182:   def preferences
183:     if request.post?
184:         
185:       for preference, value in params[:user]
186:         @user.set_preference(preference, value)
187:       end
188:       
189:       respond_to do |format|
190:         if @user.save!
191:           update_preferences
192:           flash[:notice] = I18n.t('preferences_successfully_updated', :scope => 'messages.account')
193:           return
194:         else
195:           format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
196:         end
197:       end
198:     end    
199:   end

[Source]

     # File app/controllers/accounts_controller.rb, line 296
296:   def preferred_language
297:     update_dictionary_language(params[:language_dictionary])
298:     update_target_language(params[:language_target])
299:     redirect_to(:back)
300:   end

[Source]

     # File app/controllers/accounts_controller.rb, line 80
 80:   def register
 81:     if params[:user]
 82:       begin
 83:         if params[:user][:language_native]
 84:           # we cannot have this as an attribute to user
 85:           language_native = params[:user][:language_native]
 86:           params[:user].delete(:language_native)
 87:         end
 88:         @user = User.new(params[:user]) 
 89:         respond_to do |format|
 90:           
 91:           # verify that user agrees to our terms of service and privacy policy
 92:           user_agrees = true
 93:           user_agrees_message = ''
 94:           unless params[:agree_to_terms_of_service]
 95:             user_agrees_message << I18n.t('confirm_terms_of_service', :scope => 'messages.account') << '<br />'
 96:             user_agrees = false
 97:           end
 98:           unless params[:agree_to_privacy_policy]
 99:             user_agrees_message << I18n.t('confirm_privacy_policy', :scope => 'messages.account')         
100:             user_agrees = false
101:           end
102:           unless user_agrees
103:             raise user_agrees_message 
104:           end
105:           
106:           @user.reset_activation
107: 
108:           if request.post? and not @user.nil? and  @user.save!
109:             @user.set_preference('language_native', language_native)
110:             UserMailer.deliver_activate_account(@user)
111:             flash[:notice] = I18n.t('account_sucesssfully_registered', :scope => 'messages.account', :email => @user.email)
112:             default_redirect_to
113:             return
114:           else
115:             raise I18n.t('account_not_registered', :scope => 'messages.account', :email => @user.email)
116:           end
117:         end
118:       rescue Exception => exception
119:         logger.error(exception.backtrace.join("  \n"))
120:         flash[:notice] = exception.message
121:         respond_to do |format|
122:           format.html { render :action => 'register' }  
123:           format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
124:         end
125:       end
126:     end
127:   end

[Source]

    # File app/controllers/accounts_controller.rb, line 32
32:   def request_password_reset
33:     email = params[:user] ? params[:user][:email] : params[:email]
34:     @user = User.find_by_email(email)
35:     if request.post?
36:       if @user
37:         begin
38:           is_activated = true
39:           @user.reset_activation(is_activated)
40:           UserMailer.deliver_request_password_reset(@user)
41:           flash[:notice] =  I18n.t('email_confirmation_key_sent', :scope => 'messages.account', :email => @user.email)
42:           redirect_to( :action => 'login', :email => @user.email)
43:         rescue Exception => exception
44:           logger.error(exception.backtrace.join("  \n"))
45:           flash.now[:notice] = I18n.t('error_enable_to_reset_password', :scope => 'messages.account', :email => @user.email, :reason => exception.message)
46:         end
47:       else
48:           flash.now[:notice] = I18n.t('please_submit_address_reset_password', :scope => 'messages.account')
49:       end  
50:     end 
51:   end

[Source]

    # File app/controllers/accounts_controller.rb, line 53
53:   def resend_activation
54:     if params[:user]
55:       @user = User.find_by_email(params[:user][:email])
56:     else
57:       @user = User.find_by_email(params[:email])      
58:     end
59:     if request.post?
60:       if @user
61:         if !@user.is_activated?
62:           begin
63:             @user.reset_activation
64:             UserMailer.deliver_activate_account(@user)
65:             flash[:notice] = I18n.t('email_activation_key_set', :scope => 'messages.account', :email => @user.email)
66:             redirect_to( :action => 'activate', :email => @user.email)
67:           rescue Exception => exception
68:             logger.error(exception.backtrace.join("  \n"))
69:             flash.now[:notice] = I18n.t('error_unable_to_send_activation', :scope => 'messages.account', :email => @user.email, :reason => exception.message)
70:           end
71:         else
72:           flash.now[:notice] = I18n.t('thank_you_account_activated', :scope => 'messages.account')
73:         end
74:       else
75:         flash.now[:notice] = I18n.t('please_submit_address_resend_activation_key', :scope => 'messages.account')
76:       end
77:     end
78:   end

[Source]

     # File app/controllers/accounts_controller.rb, line 129
129:   def view
130:     @user = current_user    
131:   end

[Validate]