about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorAkinori MUSHA <knu@idaemons.org>2017-05-26 21:14:03 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-05-26 14:14:03 +0200
commitf6a93fc15022b8c5ac6574b8918a2ec1a54c6040 (patch)
treea834f01768592c6c4155edde362d332533c8c603 /app
parent019f3377bbf845fcb97b55ab14c903c17e79a803 (diff)
Go to root after login in single user mode (#3289)
In single user mode, visitors are redirected to the single user's
profile page.  So, if you are the owner without a session, you start
from that page, click the login button and authenticate yourself
expecting you'll soon get started with the home page, but in reality
you'll get redirected back to where you started from -- your own
profile page.

This fixes the behavior by redirecting you home after login if you
have started from your own profile page.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/auth/sessions_controller.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/app/controllers/auth/sessions_controller.rb b/app/controllers/auth/sessions_controller.rb
index 1aa84a354..f399c6f49 100644
--- a/app/controllers/auth/sessions_controller.rb
+++ b/app/controllers/auth/sessions_controller.rb
@@ -35,10 +35,10 @@ class Auth::SessionsController < Devise::SessionsController
     params.require(:user).permit(:email, :password, :otp_attempt)
   end
 
-  def after_sign_in_path_for(_resource)
+  def after_sign_in_path_for(resource)
     last_url = stored_location_for(:user)
 
-    if [about_path].include?(last_url)
+    if home_paths(resource).include?(last_url)
       root_path
     else
       last_url || root_path
@@ -81,4 +81,14 @@ class Auth::SessionsController < Devise::SessionsController
     session[:otp_user_id] = user.id
     render :two_factor
   end
+
+  private
+
+  def home_paths(resource)
+    paths = [about_path]
+    if single_user_mode? && resource.is_a?(User)
+      paths << short_account_path(username: resource.account)
+    end
+    paths
+  end
 end