Commit e32dafb8af3860be583ea39d0a77d3ea2e0e3b44
1 parent
b24e60ef
Exists in
master
and in
29 other branches
Allow customization of URL to redirect after login
Besides, allow session to hold a value for after signup redirection
Showing
6 changed files
with
51 additions
and
9 deletions
Show diff stats
app/controllers/public/account_controller.rb
@@ -438,7 +438,7 @@ class AccountController < ApplicationController | @@ -438,7 +438,7 @@ class AccountController < ApplicationController | ||
438 | end | 438 | end |
439 | 439 | ||
440 | def go_to_signup_initial_page | 440 | def go_to_signup_initial_page |
441 | - check_redirection_options(user, user.environment.redirection_after_signup, user.url) | 441 | + check_redirection_options user, user.environment.redirection_after_signup, user.url, signup: true |
442 | end | 442 | end |
443 | 443 | ||
444 | def redirect_if_logged_in | 444 | def redirect_if_logged_in |
@@ -458,8 +458,11 @@ class AccountController < ApplicationController | @@ -458,8 +458,11 @@ class AccountController < ApplicationController | ||
458 | 458 | ||
459 | protected | 459 | protected |
460 | 460 | ||
461 | - def check_redirection_options(user, condition, default) | ||
462 | - case condition | 461 | + def check_redirection_options user, condition, default, options={} |
462 | + if options[:signup] and target = session.delete(:after_signup_redirect_to) | ||
463 | + redirect_to target | ||
464 | + else | ||
465 | + case condition | ||
463 | when 'keep_on_same_page' | 466 | when 'keep_on_same_page' |
464 | redirect_back_or_default(user.admin_url) | 467 | redirect_back_or_default(user.admin_url) |
465 | when 'site_homepage' | 468 | when 'site_homepage' |
@@ -472,8 +475,11 @@ class AccountController < ApplicationController | @@ -472,8 +475,11 @@ class AccountController < ApplicationController | ||
472 | redirect_to user.admin_url | 475 | redirect_to user.admin_url |
473 | when 'welcome_page' | 476 | when 'welcome_page' |
474 | redirect_to :controller => :home, :action => :welcome, :template_id => (user.template && user.template.id) | 477 | redirect_to :controller => :home, :action => :welcome, :template_id => (user.template && user.template.id) |
475 | - else | ||
476 | - redirect_back_or_default(default) | 478 | + when 'custom_url' |
479 | + if (url = user.custom_url_redirection).present? then redirect_to url else redirect_back_or_default default end | ||
480 | + else | ||
481 | + redirect_back_or_default(default) | ||
482 | + end | ||
477 | end | 483 | end |
478 | end | 484 | end |
479 | 485 |
app/models/environment.rb
@@ -168,7 +168,8 @@ class Environment < ActiveRecord::Base | @@ -168,7 +168,8 @@ class Environment < ActiveRecord::Base | ||
168 | 'site_homepage' => _('Redirects the user to the environment homepage.'), | 168 | 'site_homepage' => _('Redirects the user to the environment homepage.'), |
169 | 'user_profile_page' => _('Redirects the user to his profile page.'), | 169 | 'user_profile_page' => _('Redirects the user to his profile page.'), |
170 | 'user_homepage' => _('Redirects the user to his homepage.'), | 170 | 'user_homepage' => _('Redirects the user to his homepage.'), |
171 | - 'user_control_panel' => _('Redirects the user to his control panel.') | 171 | + 'user_control_panel' => _('Redirects the user to his control panel.'), |
172 | + 'custom_url' => _('Specify the URL to redirect to:'), | ||
172 | } | 173 | } |
173 | end | 174 | end |
174 | validates_inclusion_of :redirection_after_login, :in => Environment.login_redirection_options.keys, :allow_nil => true | 175 | validates_inclusion_of :redirection_after_login, :in => Environment.login_redirection_options.keys, :allow_nil => true |
app/models/profile.rb
@@ -3,7 +3,9 @@ | @@ -3,7 +3,9 @@ | ||
3 | # which by default is the one returned by Environment:default. | 3 | # which by default is the one returned by Environment:default. |
4 | class Profile < ActiveRecord::Base | 4 | class Profile < ActiveRecord::Base |
5 | 5 | ||
6 | - attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :environment, :lat, :lng, :is_template, :fields_privacy, :preferred_domain_id, :category_ids, :country, :city, :state, :national_region_code, :email, :contact_email, :redirect_l10n, :notification_time, :redirection_after_login, :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret | 6 | + attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :environment, :lat, :lng, :is_template, :fields_privacy, :preferred_domain_id, :category_ids, :country, :city, :state, :national_region_code, :email, :contact_email, :redirect_l10n, :notification_time, |
7 | + :redirection_after_login, :custom_url_redirection, | ||
8 | + :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret | ||
7 | 9 | ||
8 | # use for internationalizable human type names in search facets | 10 | # use for internationalizable human type names in search facets |
9 | # reimplement on subclasses | 11 | # reimplement on subclasses |
@@ -1023,6 +1025,7 @@ private :generate_url, :url_options | @@ -1023,6 +1025,7 @@ private :generate_url, :url_options | ||
1023 | def preferred_login_redirection | 1025 | def preferred_login_redirection |
1024 | redirection_after_login.blank? ? environment.redirection_after_login : redirection_after_login | 1026 | redirection_after_login.blank? ? environment.redirection_after_login : redirection_after_login |
1025 | end | 1027 | end |
1028 | + settings_items :custom_url_redirection, type: String, default: nil | ||
1026 | 1029 | ||
1027 | def remove_from_suggestion_list(person) | 1030 | def remove_from_suggestion_list(person) |
1028 | suggestion = person.suggested_profiles.find_by_suggestion_id self.id | 1031 | suggestion = person.suggested_profiles.find_by_suggestion_id self.id |
app/views/profile_editor/_redirection_after_login.html.erb
0 → 100644
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +<% content_for :head do %> | ||
2 | + <%= javascript_include_tag 'redirection_after_login' %> | ||
3 | +<% end %> | ||
4 | + | ||
5 | +<h2><%= _('Page to redirect after login') %></h2> | ||
6 | +<%= f.select :redirection_after_login, Environment.login_redirection_options.map{ |key,value| [value,key] }, selected: @profile.preferred_login_redirection %> | ||
7 | + | ||
8 | +<%= f.text_field :custom_url_redirection %> | ||
9 | + |
app/views/profile_editor/edit.html.erb
@@ -44,8 +44,7 @@ | @@ -44,8 +44,7 @@ | ||
44 | <% end %> | 44 | <% end %> |
45 | 45 | ||
46 | <% if environment.enabled?('allow_change_of_redirection_after_login') %> | 46 | <% if environment.enabled?('allow_change_of_redirection_after_login') %> |
47 | - <h2><%= _('Page to redirect after login') %></h2> | ||
48 | - <%= select 'profile_data', 'redirection_after_login', Environment.login_redirection_options.map{|key,value|[value,key]}, { :selected => @profile.preferred_login_redirection} %> | 47 | + <%= render 'redirection_after_login', f: f %> |
49 | <% end %> | 48 | <% end %> |
50 | 49 | ||
51 | <h2><%= _('Translations') %></h2> | 50 | <h2><%= _('Translations') %></h2> |
@@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
1 | +redirection_after_login = { | ||
2 | + | ||
3 | + view: { | ||
4 | + select: function() { | ||
5 | + return $('#profile_data_redirection_after_login') | ||
6 | + }, | ||
7 | + customUrl: function() { | ||
8 | + return $('#profile_data_custom_url_redirection') | ||
9 | + }, | ||
10 | + }, | ||
11 | + | ||
12 | + toggleCustomUrl: function() { | ||
13 | + var view = redirection_after_login.view | ||
14 | + var formGroup = view.customUrl().parents('.form-group') | ||
15 | + formGroup.toggle(view.select().val() == 'custom_url') | ||
16 | + }, | ||
17 | + | ||
18 | +}; | ||
19 | + | ||
20 | +$(document).ready(function() { | ||
21 | + redirection_after_login.toggleCustomUrl() | ||
22 | + $(redirection_after_login.view.select()).on('change keyup', redirection_after_login.toggleCustomUrl) | ||
23 | +}) | ||
24 | + |