Commit 3923d48a58c9dde292da58e207893f73509fc541
1 parent
0efa7f89
Exists in
master
and in
22 other branches
social_network: Join community on login/signup
Join community if user log in or sign up after following a "Join" link within a community. (ActionItem3096)
Showing
5 changed files
with
26 additions
and
19 deletions
Show diff stats
app/controllers/public/account_controller.rb
| @@ -17,6 +17,7 @@ class AccountController < ApplicationController | @@ -17,6 +17,7 @@ class AccountController < ApplicationController | ||
| 17 | @user = User.find_by_activation_code(params[:activation_code]) if params[:activation_code] | 17 | @user = User.find_by_activation_code(params[:activation_code]) if params[:activation_code] |
| 18 | if @user and @user.activate | 18 | if @user and @user.activate |
| 19 | @message = _("Your account has been activated, now you can log in!") | 19 | @message = _("Your account has been activated, now you can log in!") |
| 20 | + session[:join] = params[:join] unless params[:join].blank? | ||
| 20 | render :action => 'login', :userlogin => @user.login | 21 | render :action => 'login', :userlogin => @user.login |
| 21 | else | 22 | else |
| 22 | session[:notice] = _("It looks like you're trying to activate an account. Perhaps have already activated this account?") | 23 | 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 | @@ -35,6 +36,7 @@ class AccountController < ApplicationController | ||
| 35 | self.current_user ||= User.authenticate(params[:user][:login], params[:user][:password], environment) if params[:user] | 36 | self.current_user ||= User.authenticate(params[:user][:login], params[:user][:password], environment) if params[:user] |
| 36 | 37 | ||
| 37 | if logged_in? | 38 | if logged_in? |
| 39 | + join_community(self.current_user) | ||
| 38 | if params[:remember_me] == "1" | 40 | if params[:remember_me] == "1" |
| 39 | self.current_user.remember_me | 41 | self.current_user.remember_me |
| 40 | cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } | 42 | cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } |
| @@ -91,6 +93,7 @@ class AccountController < ApplicationController | @@ -91,6 +93,7 @@ class AccountController < ApplicationController | ||
| 91 | if session[:may_be_a_bot] | 93 | if session[:may_be_a_bot] |
| 92 | return false unless verify_recaptcha :model=>@user, :message=>_('Captcha (the human test)') | 94 | return false unless verify_recaptcha :model=>@user, :message=>_('Captcha (the human test)') |
| 93 | end | 95 | end |
| 96 | + @user.community_to_join = session[:join] | ||
| 94 | @user.signup! | 97 | @user.signup! |
| 95 | owner_role = Role.find_by_name('owner') | 98 | owner_role = Role.find_by_name('owner') |
| 96 | @user.person.affiliate(@user.person, [owner_role]) if owner_role | 99 | @user.person.affiliate(@user.person, [owner_role]) if owner_role |
| @@ -101,6 +104,7 @@ class AccountController < ApplicationController | @@ -101,6 +104,7 @@ class AccountController < ApplicationController | ||
| 101 | end | 104 | end |
| 102 | if @user.activated? | 105 | if @user.activated? |
| 103 | self.current_user = @user | 106 | self.current_user = @user |
| 107 | + join_community(@user) | ||
| 104 | go_to_signup_initial_page | 108 | go_to_signup_initial_page |
| 105 | else | 109 | else |
| 106 | @register_pending = true | 110 | @register_pending = true |
| @@ -448,4 +452,12 @@ class AccountController < ApplicationController | @@ -448,4 +452,12 @@ class AccountController < ApplicationController | ||
| 448 | redirect_back_or_default(default) | 452 | redirect_back_or_default(default) |
| 449 | end | 453 | end |
| 450 | end | 454 | end |
| 455 | + | ||
| 456 | + def join_community(user) | ||
| 457 | + profile_to_join = session[:join] | ||
| 458 | + unless profile_to_join.blank? | ||
| 459 | + environment.profiles.find_by_identifier(profile_to_join).add_member(user.person) | ||
| 460 | + session.delete(:join) | ||
| 461 | + end | ||
| 462 | + end | ||
| 451 | end | 463 | end |
app/controllers/public/profile_controller.rb
| @@ -3,7 +3,7 @@ class ProfileController < PublicController | @@ -3,7 +3,7 @@ class ProfileController < PublicController | ||
| 3 | needs_profile | 3 | needs_profile |
| 4 | before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add] | 4 | before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add] |
| 5 | before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail] | 5 | before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail] |
| 6 | - 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] | 6 | + 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] |
| 7 | 7 | ||
| 8 | helper TagsHelper | 8 | helper TagsHelper |
| 9 | 9 | ||
| @@ -97,21 +97,12 @@ class ProfileController < PublicController | @@ -97,21 +97,12 @@ class ProfileController < PublicController | ||
| 97 | end | 97 | end |
| 98 | 98 | ||
| 99 | def join_not_logged | 99 | def join_not_logged |
| 100 | - if request.post? | ||
| 101 | - profile.add_member(user) | ||
| 102 | - session[:notice] = _('%s administrator still needs to accept you as member.') % profile.name if profile.closed? | ||
| 103 | - redirect_to_previous_location | 100 | + session[:join] = profile.identifier |
| 101 | + | ||
| 102 | + if user | ||
| 103 | + redirect_to :controller => 'profile', :action => 'join' | ||
| 104 | else | 104 | else |
| 105 | - if user.memberships.include?(profile) | ||
| 106 | - session[:notice] = _('You are already a member of %s.') % profile.name | ||
| 107 | - redirect_to profile.url | ||
| 108 | - return | ||
| 109 | - end | ||
| 110 | - if request.xhr? | ||
| 111 | - render :layout => false | ||
| 112 | - else | ||
| 113 | - redirect_to profile.url | ||
| 114 | - end | 105 | + redirect_to :controller => '/account', :action => 'login' |
| 115 | end | 106 | end |
| 116 | end | 107 | end |
| 117 | 108 |
app/models/user.rb
| @@ -50,6 +50,9 @@ class User < ActiveRecord::Base | @@ -50,6 +50,9 @@ class User < ActiveRecord::Base | ||
| 50 | self.person.preferred_domain && self.person.preferred_domain.name || self.environment.default_hostname(true) | 50 | self.person.preferred_domain && self.person.preferred_domain.name || self.environment.default_hostname(true) |
| 51 | end | 51 | end |
| 52 | 52 | ||
| 53 | + # virtual attribute used to stash which community to join on signup or login | ||
| 54 | + attr_accessor :community_to_join | ||
| 55 | + | ||
| 53 | class Mailer < ActionMailer::Base | 56 | class Mailer < ActionMailer::Base |
| 54 | def activation_email_notify(user) | 57 | def activation_email_notify(user) |
| 55 | user_email = "#{user.login}@#{user.email_domain}" | 58 | user_email = "#{user.login}@#{user.email_domain}" |
| @@ -72,7 +75,8 @@ class User < ActiveRecord::Base | @@ -72,7 +75,8 @@ class User < ActiveRecord::Base | ||
| 72 | :activation_code => user.activation_code, | 75 | :activation_code => user.activation_code, |
| 73 | :environment => user.environment.name, | 76 | :environment => user.environment.name, |
| 74 | :url => user.environment.top_url, | 77 | :url => user.environment.top_url, |
| 75 | - :redirection => (true if user.return_to) | 78 | + :redirection => (true if user.return_to), |
| 79 | + :join => (user.community_to_join if user.community_to_join) | ||
| 76 | end | 80 | end |
| 77 | 81 | ||
| 78 | def signup_welcome_email(user) | 82 | def signup_welcome_email(user) |
app/views/user/mailer/activation_code.rhtml
| 1 | <%= _('Hi, %{recipient}!') % { :recipient => @recipient } %> | 1 | <%= _('Hi, %{recipient}!') % { :recipient => @recipient } %> |
| 2 | 2 | ||
| 3 | -<%= 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) }) %> | 3 | +<%= 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) }) %> |
| 4 | 4 | ||
| 5 | <%= _("Greetings,") %> | 5 | <%= _("Greetings,") %> |
| 6 | 6 |
features/signup.feature
| @@ -275,7 +275,7 @@ Feature: signup | @@ -275,7 +275,7 @@ Feature: signup | ||
| 275 | And I fill in "Username" with "josesilva" | 275 | And I fill in "Username" with "josesilva" |
| 276 | And I fill in "Password" with "secret" | 276 | And I fill in "Password" with "secret" |
| 277 | And I press "Log in" | 277 | And I press "Log in" |
| 278 | - Then "Joao Silva" should be a member of "Free Software" | 278 | + Then "José da Silva" should be a member of "Free Software" |
| 279 | 279 | ||
| 280 | @selenium | 280 | @selenium |
| 281 | Scenario: join community on direct signup | 281 | Scenario: join community on direct signup |
| @@ -297,4 +297,4 @@ Feature: signup | @@ -297,4 +297,4 @@ Feature: signup | ||
| 297 | | Full name | José da Silva | | 297 | | Full name | José da Silva | |
| 298 | And wait for the captcha signup time | 298 | And wait for the captcha signup time |
| 299 | And I press "Create my account" | 299 | And I press "Create my account" |
| 300 | - Then "Joao Silva" should be a member of "Free Software" | 300 | + Then "José da Silva" should be a member of "Free Software" |