Vulcan/packages/telescope-users/lib/routes.js

130 lines
2.7 KiB
JavaScript
Raw Normal View History

// Controller for user pages
Users.controllers = {};
Users.controllers.page = RouteController.extend({
waitOn: function() {
return [
coreSubscriptions.subscribe('singleUser', this.params._idOrSlug)
];
},
2015-03-28 18:30:26 +09:00
getUser: function () {
return Meteor.users.findOne({"telescope.slug": this.params._idOrSlug});
},
data: function() {
var findById = Meteor.users.findOne(this.params._idOrSlug);
var findBySlug = Meteor.users.findOne({"telescope.slug": this.params._idOrSlug});
if (typeof findById !== 'undefined') {
// redirect to slug-based URL
Router.go(Users.getProfileUrl(findById), {replaceState: true});
} else {
return {
user: findById || findBySlug
};
}
2014-11-27 17:25:01 +05:30
},
getTitle: function () {
return Users.getDisplayName(this.getUser());
},
getDescription: function () {
return i18n.t('the_profile_of') + ' ' + Users.getDisplayName(this.getUser());
},
2014-11-27 17:25:01 +05:30
fastRender: true
});
// Controller for user account editing
Users.controllers.edit = RouteController.extend({
waitOn: function() {
return [
2014-12-08 22:17:43 +09:00
coreSubscriptions.subscribe('singleUser', this.params.slug)
];
},
data: function() {
2015-02-02 18:53:42 +09:00
// if there is no slug, default to current user
var user = !!this.params.slug ? Meteor.users.findOne({"telescope.slug": this.params.slug}) : Meteor.user();
2014-12-08 22:17:43 +09:00
return {
user: user
2014-12-08 22:17:43 +09:00
};
2014-11-27 17:25:01 +05:30
},
fastRender: true
});
Meteor.startup(function () {
2014-11-22 21:19:55 -08:00
// User Logout
Router.route('/sign-out', {
name: 'signOut',
2015-04-13 16:29:33 +09:00
template: 'sign_out',
onBeforeAction: function() {
Meteor.logout(function() {
});
2014-12-13 11:58:47 +09:00
this.next();
}
});
// User Profile
Router.route('/users/:_idOrSlug', {
name: 'user_profile',
2015-04-13 16:29:33 +09:00
template: 'user_profile',
controller: Users.controllers.page
});
// User Edit
Router.route('/users/:slug/edit', {
name: 'user_edit',
2015-04-13 16:29:33 +09:00
template: 'user_edit',
controller: Users.controllers.edit,
onBeforeAction: function () {
// Only allow users with permissions to see the user edit page.
if (Meteor.user() && (
2015-04-27 17:14:07 +09:00
Users.is.admin(Meteor.user()) ||
this.params.slug === Meteor.user().telescope.slug
)) {
this.next();
} else {
2015-04-13 16:29:33 +09:00
this.render('no_rights');
}
}
});
2015-02-02 18:53:42 +09:00
Router.route('/account', {
name: 'userAccountShortcut',
2015-04-13 16:29:33 +09:00
template: 'user_edit',
controller: Users.controllers.edit
2015-02-02 18:53:42 +09:00
});
// All Users
2015-03-23 10:32:56 +09:00
Router.route('/users-dashboard', {
2015-04-22 08:47:23 +09:00
controller: Telescope.controllers.admin,
name: 'users_dashboard'
});
// Unsubscribe (from notifications)
Router.route('/unsubscribe/:hash', {
name: 'unsubscribe',
2015-04-13 16:29:33 +09:00
template: 'unsubscribe',
data: function() {
return {
hash: this.params.hash
};
}
});
2015-03-28 18:30:26 +09:00
});