| Class | PeopleController |
| In: |
app/controllers/people_controller.rb
|
| Parent: | ApplicationController |
# File app/controllers/people_controller.rb, line 28
28: def create
29: @title = t('people.registro_nuevo', :name => t('site_name'))
30: @user = Person.new(params[:user])
31: @user.user_ip = request.remote_ip
32:
33: respond_to do |format|
34: if @user.save
35: cookies.delete :auth_token
36: # protects against session fixation attacks, wreaks havoc with
37: # request forgery protection.
38: # uncomment at your own risk
39: # reset_session
40: # self.current_user = @user
41:
42: flash[:notice] = t('people.gracias_por_unirte')
43:
44: email = Notifier.create_activate_person_account(@user)
45:
46: begin
47: logger.info("Mandando activacion a #{@user.email}")
48: Notifier.deliver(email)
49: rescue Net::SMTPServerBusy, Net::SMTPSyntaxError => err_type
50: logger.info("Error al mandar mail de activacion: " + err_type)
51: flash[:error] = t('session.Error_servidor_correo')
52: end
53:
54:
55: format.html { redirect_back_or_default(root_path) }
56: format.xml { render :xml => @user, :status => :created, :location => @user }
57: else
58: format.html { render :action => "new" }
59: format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
60: end
61: end
62: end
# File app/controllers/people_controller.rb, line 3 3: def index 4: @people = Person.approved.paginate :order => "people.created_at DESC", :page => params[:page], :per_page => 8 5: @title = t('people.unidas') 6: @breadcrumbs_info = [[t('people.unidas'), people_path]] 7: end
# File app/controllers/people_controller.rb, line 20
20: def new
21: @user = Person.new
22: @title = t('people.registro_nuevo', :name => t('site_name'))
23: # @title = I18n.t('people.registro_nuevo', :name => Notifier::SERVICENAME)
24: # store_previous_location unless session[:return_to]
25: @breadcrumbs_info = [[t('people.registro_nuevo', :name => Notifier::SERVICENAME), signup_path]]
26: end
# File app/controllers/people_controller.rb, line 9
9: def show
10: begin
11: @person = Person.approved.find(params[:id])
12: rescue ActiveRecord::RecordNotFound
13: flash[:notice] = t('people.not_found')
14: redirect_to root_path and return
15: end
16: @title = "#{@person.public_name}"
17: @title << ", #{t('people.de', :city => @person.public_city)}" if @person.public_city
18: end
# File app/controllers/people_controller.rb, line 64
64: def update
65: @person = Person.approved.find(current_user.id)
66: if @person.update_attributes(params[:person])
67: redirect_to account_path
68: else
69: render :template => '/account/edit'
70: end
71:
72: end
# File app/controllers/people_controller.rb, line 75
75: def validate_field
76: if params[:type].eql?('Person')
77: user_attrs = ['email', 'password', 'password_confirmation', 'url', 'name', 'last_names']
78: elsif params[:type].eql?('Journalist')
79: user_attrs = ['email', 'password', 'password_confirmation', 'media', 'url', 'name', 'last_names']
80: else
81: user_attrs = ['email', 'password', 'password_confirmation', 'telephone', 'name', 'last_names']
82: end
83:
84: user_params = params.dup.delete_if {|k, v| !user_attrs.include?(k)}
85:
86: render :update do |page|
87: if user_params.length > 0
88: u = params[:type].constantize.new(user_params)
89: u.valid?
90: user_params.each do |pk, pv|
91: if u.errors.on(pk)
92: page.select("#user_#{pk}_container span.error_message").each(&:remove)
93: page.insert_html :after, "user_#{pk}", content_tag(:span, u.errors.on(pk).to_a.join(' y '), :class => 'error_message')
94: else
95: page.select("#user_#{pk}_container span.error_message").each(&:remove)
96: end
97: end
98: end
99: end
100: end