Commit 8ee125a83859872afde7d73049c19b17e0c1ff73
1 parent
dfe39540
Exists in
master
and in
27 other branches
signup_image_upload: Add image on user signup
Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com> Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
3 changed files
with
28 additions
and
1 deletions
Show diff stats
app/controllers/public/account_controller.rb
| ... | ... | @@ -97,6 +97,7 @@ class AccountController < ApplicationController |
| 97 | 97 | @user.return_to = session[:return_to] |
| 98 | 98 | @person = Person.new(params[:profile_data]) |
| 99 | 99 | @person.environment = @user.environment |
| 100 | + | |
| 100 | 101 | if request.post? |
| 101 | 102 | if may_be_a_bot |
| 102 | 103 | set_signup_start_time_for_now |
| ... | ... | @@ -115,6 +116,14 @@ class AccountController < ApplicationController |
| 115 | 116 | invitation.update_attributes!({:friend => @user.person}) |
| 116 | 117 | invitation.finish |
| 117 | 118 | end |
| 119 | + | |
| 120 | + unless params[:file].nil? | |
| 121 | + image = Image::new :uploaded_data=> params[:file][:image] | |
| 122 | + | |
| 123 | + @user.person.image = image | |
| 124 | + @user.person.save | |
| 125 | + end | |
| 126 | + | |
| 118 | 127 | if @user.activated? |
| 119 | 128 | self.current_user = @user |
| 120 | 129 | check_join_in_community(@user) | ... | ... |
app/views/profile_editor/_person_form.html.erb
| ... | ... | @@ -25,7 +25,7 @@ |
| 25 | 25 | <%= optional_field(@person, 'address', labelled_form_field(_('Address (street and number)'), text_field(:profile_data, :address, :rel => _('Address')))) %> |
| 26 | 26 | <%= optional_field(@person, 'address_reference', labelled_form_field(_('Address reference'), text_field(:profile_data, :address_reference, :rel => _('Address reference')))) %> |
| 27 | 27 | <%= optional_field(@person, 'district', labelled_form_field(_('District'), text_field(:profile_data, :district, :rel => _('District')))) %> |
| 28 | -<%= optional_field(@person, 'image', labelled_form_field(_('Image'), file_field(:profile_data, :image, :rel => _('Image')))) %> | |
| 28 | +<%= optional_field(@person, 'image', labelled_form_field(_('Image'), file_field(:file, :image, :rel => _('Image')))) %> | |
| 29 | 29 | |
| 30 | 30 | <% optional_field(@person, 'schooling') do %> |
| 31 | 31 | <div class="formfieldline"> | ... | ... |
test/functional/account_controller_test.rb
| ... | ... | @@ -637,6 +637,23 @@ class AccountControllerTest < ActionController::TestCase |
| 637 | 637 | assert_equal 'example.com', Person['testuser'].organization |
| 638 | 638 | end |
| 639 | 639 | |
| 640 | + should "create a new user with image" do | |
| 641 | + post :signup, :user => { | |
| 642 | + :login => 'testuser', :password => '123456', :password_confirmation => '123456', :email => 'testuser@example.com' | |
| 643 | + }, | |
| 644 | + :profile_data => { | |
| 645 | + :organization => 'example.com' | |
| 646 | + }, | |
| 647 | + :file => { | |
| 648 | + :image => fixture_file_upload('/files/rails.png', 'image/png') | |
| 649 | + } | |
| 650 | + | |
| 651 | + assert_response :successs | |
| 652 | + | |
| 653 | + person = Person["testuser"] | |
| 654 | + assert_equal "rails.png", person.image.filename | |
| 655 | + end | |
| 656 | + | |
| 640 | 657 | should 'activate user after signup if environment is set to skip confirmation' do |
| 641 | 658 | env = Environment.default |
| 642 | 659 | env.enable('skip_new_user_email_confirmation') |
| ... | ... | @@ -965,6 +982,7 @@ class AccountControllerTest < ActionController::TestCase |
| 965 | 982 | end |
| 966 | 983 | |
| 967 | 984 | protected |
| 985 | + | |
| 968 | 986 | def new_user(options = {}, extra_options ={}) |
| 969 | 987 | data = {:profile_data => person_data} |
| 970 | 988 | if extra_options[:profile_data] | ... | ... |