mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Support for /my/preferences to automatically redirect to the logged in
user.
This commit is contained in:
parent
61e6eae728
commit
b9ca124756
4 changed files with 45 additions and 1 deletions
|
@ -70,6 +70,17 @@ Discourse.URL = Em.Object.createWithMixins({
|
|||
// Schedule a DOM cleanup event
|
||||
Em.run.scheduleOnce('afterRender', Discourse.Route, 'cleanDOM');
|
||||
|
||||
// Rewrite /my/* urls
|
||||
if (path.indexOf('/my/') === 0) {
|
||||
var currentUser = Discourse.User.current();
|
||||
if (currentUser) {
|
||||
path = path.replace('/my/', '/users/' + currentUser.get('username_lower') + "/");
|
||||
} else {
|
||||
document.location.href = "/404";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Extract into rules we can inject into the URL handler
|
||||
if (this.navigatedToHome(oldPath, path)) { return; }
|
||||
if (this.navigatedToPost(oldPath, path)) { return; }
|
||||
|
|
|
@ -5,7 +5,7 @@ require_dependency 'avatar_upload_service'
|
|||
class UsersController < ApplicationController
|
||||
|
||||
skip_before_filter :authorize_mini_profiler, only: [:avatar]
|
||||
skip_before_filter :check_xhr, only: [:show, :password_reset, :update, :activate_account, :authorize_email, :user_preferences_redirect, :avatar]
|
||||
skip_before_filter :check_xhr, only: [:show, :password_reset, :update, :activate_account, :authorize_email, :user_preferences_redirect, :avatar, :my_redirect]
|
||||
|
||||
before_filter :ensure_logged_in, only: [:username, :update, :change_email, :user_preferences_redirect, :upload_user_image, :toggle_avatar, :clear_profile_background, :destroy]
|
||||
before_filter :respond_to_suspicious_request, only: [:create]
|
||||
|
@ -80,6 +80,15 @@ class UsersController < ApplicationController
|
|||
render nothing: true
|
||||
end
|
||||
|
||||
def my_redirect
|
||||
puts params[:path]
|
||||
if current_user.present? && params[:path] =~ /^[a-z\-]+$/
|
||||
redirect_to "/users/#{current_user.username}/#{params[:path]}"
|
||||
return
|
||||
end
|
||||
raise Discourse::NotFound.new
|
||||
end
|
||||
|
||||
def invited
|
||||
inviter = fetch_user_from_params
|
||||
|
||||
|
|
|
@ -174,6 +174,7 @@ Discourse::Application.routes.draw do
|
|||
get "users/activate-account/:token" => "users#activate_account"
|
||||
get "users/authorize-email/:token" => "users#authorize_email"
|
||||
get "users/hp" => "users#get_honeypot_value"
|
||||
get "my/:path", to: 'users#my_redirect'
|
||||
|
||||
get "user_preferences" => "users#user_preferences_redirect"
|
||||
get "users/:username/private-messages" => "user_actions#private_messages", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
|
|
|
@ -1323,4 +1323,27 @@ describe UsersController do
|
|||
end
|
||||
end
|
||||
|
||||
describe '.my_redirect' do
|
||||
|
||||
it "returns 404 if the user is not logged in" do
|
||||
get :my_redirect, path: "wat"
|
||||
response.should_not be_success
|
||||
response.should_not be_redirect
|
||||
end
|
||||
|
||||
context "when the user is logged in" do
|
||||
let!(:user) { log_in }
|
||||
|
||||
it "will not redirect to an invalid path" do
|
||||
get :my_redirect, path: "wat/..password.txt"
|
||||
response.should_not be_redirect
|
||||
end
|
||||
|
||||
it "will redirect to an valid path" do
|
||||
get :my_redirect, path: "preferences"
|
||||
response.should be_redirect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue