diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index b655335..41d73ef 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -17,6 +17,7 @@ class AccountController < ApplicationController @user = User.find_by_activation_code(params[:activation_code]) if params[:activation_code] if @user and @user.activate @message = _("Your account has been activated, now you can log in!") + session[:join] = params[:join] unless params[:join].blank? render :action => 'login', :userlogin => @user.login else session[:notice] = _("It looks like you're trying to activate an account. Perhaps have already activated this account?") @@ -35,6 +36,7 @@ class AccountController < ApplicationController self.current_user ||= User.authenticate(params[:user][:login], params[:user][:password], environment) if params[:user] if logged_in? + join_community(self.current_user) if params[:remember_me] == "1" self.current_user.remember_me cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } @@ -91,6 +93,7 @@ class AccountController < ApplicationController if session[:may_be_a_bot] return false unless verify_recaptcha :model=>@user, :message=>_('Captcha (the human test)') end + @user.community_to_join = session[:join] @user.signup! owner_role = Role.find_by_name('owner') @user.person.affiliate(@user.person, [owner_role]) if owner_role @@ -101,6 +104,7 @@ class AccountController < ApplicationController end if @user.activated? self.current_user = @user + join_community(@user) go_to_signup_initial_page else @register_pending = true @@ -448,4 +452,12 @@ class AccountController < ApplicationController redirect_back_or_default(default) end end + + def join_community(user) + profile_to_join = session[:join] + unless profile_to_join.blank? + environment.profiles.find_by_identifier(profile_to_join).add_member(user.person) + session.delete(:join) + end + end end diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 3cc8c55..4fbb43a 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -3,7 +3,7 @@ class ProfileController < PublicController needs_profile before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add] before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail] - before_filter :login_required, :only => [:add, :join, :join_not_logged, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity, :send_mail] + before_filter :login_required, :only => [:add, :join, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity, :send_mail] helper TagsHelper @@ -97,21 +97,12 @@ class ProfileController < PublicController end def join_not_logged - if request.post? - profile.add_member(user) - session[:notice] = _('%s administrator still needs to accept you as member.') % profile.name if profile.closed? - redirect_to_previous_location + session[:join] = profile.identifier + + if user + redirect_to :controller => 'profile', :action => 'join' else - if user.memberships.include?(profile) - session[:notice] = _('You are already a member of %s.') % profile.name - redirect_to profile.url - return - end - if request.xhr? - render :layout => false - else - redirect_to profile.url - end + redirect_to :controller => '/account', :action => 'login' end end diff --git a/app/models/user.rb b/app/models/user.rb index 3b1da24..2970f28 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -50,6 +50,9 @@ class User < ActiveRecord::Base self.person.preferred_domain && self.person.preferred_domain.name || self.environment.default_hostname(true) end + # virtual attribute used to stash which community to join on signup or login + attr_accessor :community_to_join + class Mailer < ActionMailer::Base def activation_email_notify(user) user_email = "#{user.login}@#{user.email_domain}" @@ -72,7 +75,8 @@ class User < ActiveRecord::Base :activation_code => user.activation_code, :environment => user.environment.name, :url => user.environment.top_url, - :redirection => (true if user.return_to) + :redirection => (true if user.return_to), + :join => (user.community_to_join if user.community_to_join) end def signup_welcome_email(user) diff --git a/app/views/user/mailer/activation_code.rhtml b/app/views/user/mailer/activation_code.rhtml index ac03cc4..efe9df7 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, :redirection => @redirection) }) %> +<%= 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 => @redirection, :join => @join) }) %> <%= _("Greetings,") %> diff --git a/features/signup.feature b/features/signup.feature index c95c692..da6fa8f 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -275,7 +275,7 @@ Feature: signup And I fill in "Username" with "josesilva" And I fill in "Password" with "secret" And I press "Log in" - Then "Joao Silva" should be a member of "Free Software" + Then "José da Silva" should be a member of "Free Software" @selenium Scenario: join community on direct signup @@ -297,4 +297,4 @@ Feature: signup | Full name | José da Silva | And wait for the captcha signup time And I press "Create my account" - Then "Joao Silva" should be a member of "Free Software" + Then "José da Silva" should be a member of "Free Software" -- libgit2 0.21.2