diff --git a/app/assets/javascripts/discourse/controllers/login.js.es6 b/app/assets/javascripts/discourse/controllers/login.js.es6 index e6309349841..50abf282d73 100644 --- a/app/assets/javascripts/discourse/controllers/login.js.es6 +++ b/app/assets/javascripts/discourse/controllers/login.js.es6 @@ -80,7 +80,7 @@ export default Ember.Controller.extend(ModalFunctionality, { const shouldRedirectToUrl = self.session.get("shouldRedirectToUrl"); $hidden_login_form.find('input[name=username]').val(self.get('loginName')); $hidden_login_form.find('input[name=password]').val(self.get('loginPassword')); - if (self.get('loginRequired') && destinationUrl) { + if (destinationUrl) { // redirect client to the original URL $.cookie('destination_url', null); $hidden_login_form.find('input[name=redirect]').val(destinationUrl); diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6fc780aabc2..0131fcb8094 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -162,11 +162,15 @@ class UsersController < ApplicationController end def my_redirect - if current_user.present? && params[:path] =~ /^[a-z\-\/]+$/ - redirect_to path("/users/#{current_user.username}/#{params[:path]}") - return + + raise Discourse::NotFound if params[:path] !~ /^[a-z\-\/]+$/ + + if current_user.blank? + cookies[:destination_url] = "/my/#{params[:path]}" + redirect_to :login + else + redirect_to(path("/users/#{current_user.username}/#{params[:path]}")) end - raise Discourse::NotFound end def invited