From 8ee125a83859872afde7d73049c19b17e0c1ff73 Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Mon, 15 Sep 2014 15:52:42 -0300 Subject: [PATCH] signup_image_upload: Add image on user signup --- app/controllers/public/account_controller.rb | 9 +++++++++ app/views/profile_editor/_person_form.html.erb | 2 +- test/functional/account_controller_test.rb | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index b5b45e6..1e5c2b4 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -97,6 +97,7 @@ class AccountController < ApplicationController @user.return_to = session[:return_to] @person = Person.new(params[:profile_data]) @person.environment = @user.environment + if request.post? if may_be_a_bot set_signup_start_time_for_now @@ -115,6 +116,14 @@ class AccountController < ApplicationController invitation.update_attributes!({:friend => @user.person}) invitation.finish end + + unless params[:file].nil? + image = Image::new :uploaded_data=> params[:file][:image] + + @user.person.image = image + @user.person.save + end + if @user.activated? self.current_user = @user check_join_in_community(@user) diff --git a/app/views/profile_editor/_person_form.html.erb b/app/views/profile_editor/_person_form.html.erb index 12fbc65..a2bd218 100644 --- a/app/views/profile_editor/_person_form.html.erb +++ b/app/views/profile_editor/_person_form.html.erb @@ -25,7 +25,7 @@ <%= optional_field(@person, 'address', labelled_form_field(_('Address (street and number)'), text_field(:profile_data, :address, :rel => _('Address')))) %> <%= optional_field(@person, 'address_reference', labelled_form_field(_('Address reference'), text_field(:profile_data, :address_reference, :rel => _('Address reference')))) %> <%= optional_field(@person, 'district', labelled_form_field(_('District'), text_field(:profile_data, :district, :rel => _('District')))) %> -<%= optional_field(@person, 'image', labelled_form_field(_('Image'), file_field(:profile_data, :image, :rel => _('Image')))) %> +<%= optional_field(@person, 'image', labelled_form_field(_('Image'), file_field(:file, :image, :rel => _('Image')))) %> <% optional_field(@person, 'schooling') do %>
diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index 85a75a4..8ae54c8 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -637,6 +637,23 @@ class AccountControllerTest < ActionController::TestCase assert_equal 'example.com', Person['testuser'].organization end + should "create a new user with image" do + post :signup, :user => { + :login => 'testuser', :password => '123456', :password_confirmation => '123456', :email => 'testuser@example.com' + }, + :profile_data => { + :organization => 'example.com' + }, + :file => { + :image => fixture_file_upload('/files/rails.png', 'image/png') + } + + assert_response :successs + + person = Person["testuser"] + assert_equal "rails.png", person.image.filename + end + should 'activate user after signup if environment is set to skip confirmation' do env = Environment.default env.enable('skip_new_user_email_confirmation') @@ -965,6 +982,7 @@ class AccountControllerTest < ActionController::TestCase end protected + def new_user(options = {}, extra_options ={}) data = {:profile_data => person_data} if extra_options[:profile_data] -- libgit2 0.21.2