Merge pull request #611 from anthonymayer/siteurl-in-urls

Fix various url problems by taking siteUrl into account when getting route urls.
This commit is contained in:
Sacha Greif 2014-12-10 09:39:38 +09:00
commit ca78347dce
6 changed files with 28 additions and 21 deletions

View file

@ -152,7 +152,7 @@ Template[getTemplate('comment_item')].events({
'click .not-upvoted .upvote': function(e, instance){ 'click .not-upvoted .upvote': function(e, instance){
e.preventDefault(); e.preventDefault();
if(!Meteor.user()){ if(!Meteor.user()){
Router.go(getSigninUrl()); Router.go('atSignIn');
flashMessage(i18n.t("please_log_in_first"), "info"); flashMessage(i18n.t("please_log_in_first"), "info");
} }
Meteor.call('upvoteComment', this, function(error, result){ Meteor.call('upvoteComment', this, function(error, result){
@ -162,7 +162,7 @@ Template[getTemplate('comment_item')].events({
'click .upvoted .upvote': function(e, instance){ 'click .upvoted .upvote': function(e, instance){
e.preventDefault(); e.preventDefault();
if(!Meteor.user()){ if(!Meteor.user()){
Router.go(getSigninUrl()); Router.go('atSignIn');
flashMessage(i18n.t("please_log_in_first"), "info"); flashMessage(i18n.t("please_log_in_first"), "info");
} }
Meteor.call('cancelUpvoteComment', this, function(error, result){ Meteor.call('cancelUpvoteComment', this, function(error, result){
@ -172,7 +172,7 @@ Template[getTemplate('comment_item')].events({
'click .not-downvoted .downvote': function(e, instance){ 'click .not-downvoted .downvote': function(e, instance){
e.preventDefault(); e.preventDefault();
if(!Meteor.user()){ if(!Meteor.user()){
Router.go(getSigninUrl()); Router.go('atSignIn');
flashMessage(i18n.t("please_log_in_first"), "info"); flashMessage(i18n.t("please_log_in_first"), "info");
} }
Meteor.call('downvoteComment', this, function(error, result){ Meteor.call('downvoteComment', this, function(error, result){
@ -182,7 +182,7 @@ Template[getTemplate('comment_item')].events({
'click .downvoted .downvote': function(e, instance){ 'click .downvoted .downvote': function(e, instance){
e.preventDefault(); e.preventDefault();
if(!Meteor.user()){ if(!Meteor.user()){
Router.go(getSigninUrl()); Router.go('atSignIn');
flashMessage(i18n.t("please_log_in_first"), "info"); flashMessage(i18n.t("please_log_in_first"), "info");
} }
Meteor.call('cancelDownvoteComment', this, function(error, result){ Meteor.call('cancelDownvoteComment', this, function(error, result){

View file

@ -6,7 +6,7 @@ Template[getTemplate('userMenu')].helpers({
return getDisplayName(Meteor.user()); return getDisplayName(Meteor.user());
}, },
profileUrl: function () { profileUrl: function () {
return getProfileUrl(Meteor.user()); return Router.routes['user_profile'].path({_idOrSlug: Meteor.user().slug});
}, },
userEditUrl: function () { userEditUrl: function () {
return Router.routes['user_edit'].path(Meteor.user()); return Router.routes['user_edit'].path(Meteor.user());

View file

@ -15,7 +15,7 @@ Template[getTemplate('postUpvote')].events({
var post = this; var post = this;
e.preventDefault(); e.preventDefault();
if(!Meteor.user()){ if(!Meteor.user()){
Router.go(getSigninUrl()); Router.go('atSignIn');
flashMessage(i18n.t("please_log_in_first"), "info"); flashMessage(i18n.t("please_log_in_first"), "info");
} }
Meteor.call('upvotePost', post, function(error, result){ Meteor.call('upvotePost', post, function(error, result){

View file

@ -5,9 +5,6 @@ cl = function(something){
getCurrentTemplate = function() { getCurrentTemplate = function() {
return Router.current().lookupTemplate(); return Router.current().lookupTemplate();
}; };
getCurrentRoute = function() {
return Router.current().url;
};
t=function(message){ t=function(message){
var d=new Date(); var d=new Date();
console.log("### "+message+" rendered at "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds()); console.log("### "+message+" rendered at "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds());
@ -46,25 +43,37 @@ goTo = function(url){
Router.go(url); Router.go(url);
}; };
// This function should only ever really be necessary server side
// Client side using .path() is a better option since it's relative
// and shouldn't care about the siteUrl.
getRouteUrl = function (routeName, params, options) {
options = options || {};
options.host = getSiteUrl();
return Router.routes[routeName].url(
params || {},
options
);
};
getSignupUrl = function(){ getSignupUrl = function(){
return Router.routes['atSignUp'].url(); return getRouteUrl('atSignUp');
}; };
getSigninUrl = function(){ getSigninUrl = function(){
return Router.routes['atSignIn'].url(); return getRouteUrl('atSignIn');
}; };
getPostUrl = function(id){ getPostUrl = function(id){
return Router.routes['post_page'].url({_id: id}); return getRouteUrl('post_page', {_id: id});
}; };
getPostEditUrl = function(id){ getPostEditUrl = function(id){
return Router.routes['post_edit'].url({_id: id}); return getRouteUrl('post_edit', {_id: id});
}; };
getCommentUrl = function(id){ getCommentUrl = function(id){
return Router.routes['comment_reply'].url({_id: id}); return getRouteUrl('comment_reply', {_id: id});
}; };
getPostCommentUrl = function(postId, commentId){ getPostCommentUrl = function(postId, commentId){
// get link to a comment on a post page // get link to a comment on a post page
return Router.routes['post_page_comment'].url({ return getRouteUrl('post_page_comment', {
_id: postId, _id: postId,
commentId: commentId commentId: commentId
}); });
@ -88,9 +97,7 @@ invitesEnabled = function () {
return getSetting("requireViewInvite") || getSetting("requirePostInvite"); return getSetting("requireViewInvite") || getSetting("requirePostInvite");
}; };
getOutgoingUrl = function(url){ getOutgoingUrl = function(url){
// we don't use IR's url() function here in case ROOT_URL hasn't been set return getRouteUrl('out', {}, {query: {url: url}});
var cleanUrl = encodeURIComponent(url);
return getSetting('siteUrl', Meteor.absoluteUrl()) + 'out?url=' + cleanUrl;
}; };
// ---------------------------------- String Helper Functions ----------------------------------- // // ---------------------------------- String Helper Functions ----------------------------------- //
cleanUp = function(s){ cleanUp = function(s){

View file

@ -47,7 +47,7 @@ getProfileUrl = function(user) {
return getProfileUrlBySlugOrId(user.slug); return getProfileUrlBySlugOrId(user.slug);
}; };
getProfileUrlBySlugOrId = function(slugOrId) { getProfileUrlBySlugOrId = function(slugOrId) {
return Router.routes['user_profile'].url({_idOrSlug: slugOrId}); return getRouteUrl('user_profile', {_idOrSlug: slugOrId});
}; };
hasPassword = function(user) { hasPassword = function(user) {
return !!user.services.password; return !!user.services.password;

View file

@ -1,5 +1,5 @@
getUnsubscribeLink = function(user){ getUnsubscribeLink = function(user){
return Router.routes['unsubscribe'].url({hash: user.email_hash}); return getRouteUrl('unsubscribe', {hash: user.email_hash});
}; };
// given a notification, return the correct subject and html to send an email // given a notification, return the correct subject and html to send an email