diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index 6cac48c..9ecc4ce 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -79,6 +79,7 @@ class AccountController < ApplicationController @user.environment = environment @terms_of_use = environment.terms_of_use @user.person_data = params[:profile_data] + @user.return_to = session[:return_to] @person = Person.new(params[:profile_data]) @person.environment = @user.environment if request.post? @@ -370,6 +371,12 @@ class AccountController < ApplicationController end def go_to_initial_page + if params[:redirection] + session[:return_to] = @user.return_to + @user.return_to = nil + @user.save + end + if params[:return_to] #I never get here redirect_to params[:return_to] diff --git a/app/models/user.rb b/app/models/user.rb index af6de5b..3cb63be 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -71,7 +71,8 @@ class User < ActiveRecord::Base body :recipient => user.name, :activation_code => user.activation_code, :environment => user.environment.name, - :url => user.environment.top_url + :url => user.environment.top_url, + :return_to => user.return_to end def signup_welcome_email(user) @@ -93,7 +94,7 @@ class User < ActiveRecord::Base self.person.save! end end - + has_one :person, :dependent => :destroy belongs_to :environment @@ -183,7 +184,7 @@ class User < ActiveRecord::Base encryption_methods[sym] = block end - # the encryption method used for this instance + # the encryption method used for this instance def encryption_method (password_type || User.system_encryption_method).to_sym end @@ -226,7 +227,7 @@ class User < ActiveRecord::Base end def remember_token? - remember_token_expires_at && Time.now.utc < remember_token_expires_at + remember_token_expires_at && Time.now.utc < remember_token_expires_at end # These create and unset the fields required for remembering users between browser closes @@ -255,7 +256,7 @@ class User < ActiveRecord::Base raise IncorrectPassword unless self.authenticated?(current) self.force_change_password!(new, confirmation) end - + # Changes the password of a user without asking for the old password. This # method is intended to be used by the "I forgot my password", and must be # used with care. @@ -326,7 +327,7 @@ class User < ActiveRecord::Base end protected - # before filter + # before filter def encrypt_password return if password.blank? self.salt ||= Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--") if new_record? diff --git a/app/views/user/mailer/activation_code.rhtml b/app/views/user/mailer/activation_code.rhtml index 3f35a3c..7a05794 100644 --- a/app/views/user/mailer/activation_code.rhtml +++ b/app/views/user/mailer/activation_code.rhtml @@ -1,6 +1,6 @@ <%= _('Hi, %{recipient}!') % { :recipient => @recipient } %> -<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code) }) %> +<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code, :redirection => (true if @return_to) ) }) %> <%= _("Greetings,") %> diff --git a/db/migrate/20140312184749_add_return_to_to_users.rb b/db/migrate/20140312184749_add_return_to_to_users.rb new file mode 100644 index 0000000..fc2b13d --- /dev/null +++ b/db/migrate/20140312184749_add_return_to_to_users.rb @@ -0,0 +1,9 @@ +class AddReturnToToUsers < ActiveRecord::Migration + def self.up + add_column :users, :return_to, :string + end + + def self.down + remove_column :users, :return_to, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index faa0350..e823458 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140205191914) do +ActiveRecord::Schema.define(:version => 20140312184749) do create_table "abuse_reports", :force => true do |t| t.integer "reporter_id" @@ -282,7 +282,7 @@ ActiveRecord::Schema.define(:version => 20140205191914) do t.text "signup_welcome_text" t.string "languages" t.string "default_language" - t.string "redirection_after_signup", :default => "keep_on_same_page" + t.string "redirection_after_signup", :default => "keep_on_same_page" end create_table "external_feeds", :force => true do |t| @@ -620,6 +620,7 @@ ActiveRecord::Schema.define(:version => 20140205191914) do t.datetime "chat_status_at" t.string "activation_code", :limit => 40 t.datetime "activated_at" + t.string "return_to" end create_table "validation_infos", :force => true do |t| diff --git a/features/signup.feature b/features/signup.feature index df60d9c..59ea024 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -141,3 +141,107 @@ Feature: signup And I press "Create my account" Then I should be on the homepage + @selenium + Scenario: user should stay on same page after following confirmation link + Given the environment is configured to stay on the same page after login + And feature "skip_new_user_email_confirmation" is disabled on environment + And feature "allow_change_of_redirection_after_login" is enabled on environment + And I am on /search/people + When I follow "Sign up" + And I fill in the following within ".no-boxes": + | e-Mail | josesilva@example.com | + | Username | josesilva | + | Password | secret | + | Password confirmation | secret | + | Full name | José da Silva | + And wait for the captcha signup time + And I press "Create my account" + And I go to josesilva's confirmation URL + And I fill in "Username" with "josesilva" + And I fill in "Password" with "secret" + And I press "Log in" + Then I should be on /search/people + + @selenium + Scenario: user should go to his homepage after following confirmation link + Given the environment is configured to redirect to profile homepage after login + And feature "skip_new_user_email_confirmation" is disabled on environment + And feature "allow_change_of_redirection_after_login" is enabled on environment + And I am on /search/people + When I follow "Sign up" + And I fill in the following within ".no-boxes": + | e-Mail | josesilva@example.com | + | Username | josesilva | + | Password | secret | + | Password confirmation | secret | + | Full name | José da Silva | + And wait for the captcha signup time + And I press "Create my account" + And I go to josesilva's confirmation URL + And I fill in "Username" with "josesilva" + And I fill in "Password" with "secret" + And I press "Log in" + Then I should be on /profile/josesilva + + @selenium + Scenario: user should go to his control panel after following confirmation link + Given the environment is configured to redirect to profile control panel after login + And feature "skip_new_user_email_confirmation" is disabled on environment + And feature "allow_change_of_redirection_after_login" is enabled on environment + And I am on /search/people + When I follow "Sign up" + And I fill in the following within ".no-boxes": + | e-Mail | josesilva@example.com | + | Username | josesilva | + | Password | secret | + | Password confirmation | secret | + | Full name | José da Silva | + And wait for the captcha signup time + And I press "Create my account" + And I go to josesilva's confirmation URL + And I fill in "Username" with "josesilva" + And I fill in "Password" with "secret" + And I press "Log in" + Then I should be on /myprofile/josesilva + + @selenium + Scenario: user should go to his profile page after following confirmation link + Given the environment is configured to redirect to profile page after login + And feature "skip_new_user_email_confirmation" is disabled on environment + And feature "allow_change_of_redirection_after_login" is enabled on environment + And I am on /search/people + When I follow "Sign up" + And I fill in the following within ".no-boxes": + | e-Mail | josesilva@example.com | + | Username | josesilva | + | Password | secret | + | Password confirmation | secret | + | Full name | José da Silva | + And wait for the captcha signup time + And I press "Create my account" + And I go to josesilva's confirmation URL + And I fill in "Username" with "josesilva" + And I fill in "Password" with "secret" + And I press "Log in" + Then I should be on /profile/josesilva + + @selenium + Scenario: user should go to the environment homepage after following confirmation link + Given the environment is configured to redirect to site homepage after login + And feature "skip_new_user_email_confirmation" is disabled on environment + And feature "allow_change_of_redirection_after_login" is enabled on environment + And I am on /search/people + When I follow "Sign up" + And I fill in the following within ".no-boxes": + | e-Mail | josesilva@example.com | + | Username | josesilva | + | Password | secret | + | Password confirmation | secret | + | Full name | José da Silva | + And wait for the captcha signup time + And I press "Create my account" + And I go to josesilva's confirmation URL + And I fill in "Username" with "josesilva" + And I fill in "Password" with "secret" + And I press "Log in" + Then I should be on the homepage diff --git a/features/support/paths.rb b/features/support/paths.rb index b11c075..f181f90 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -111,6 +111,10 @@ module NavigationHelpers when /the user data path/ '/account/user_data' + when /^(.+)'s confirmation URL/ + user = User[$1] + "/account/activate?activation_code=#{user.activation_code}&redirection=" + (user.return_to.nil? ? 'false' : 'true') + when /^(.+)'s members page/ '/profile/%s/members' % profile_identifier($1) -- libgit2 0.21.2