2014-11-17 14:45:23 +09:00
|
|
|
// Controller for user pages
|
|
|
|
|
2014-11-27 17:25:01 +05:30
|
|
|
UserPageController = RouteController.extend({
|
2014-12-15 09:52:37 +09:00
|
|
|
|
2014-11-17 14:45:23 +09:00
|
|
|
waitOn: function() {
|
|
|
|
return [
|
2014-12-08 17:25:11 +09:00
|
|
|
coreSubscriptions.subscribe('singleUser', this.params._idOrSlug)
|
2014-11-17 14:45:23 +09:00
|
|
|
]
|
|
|
|
},
|
2014-12-15 09:52:37 +09:00
|
|
|
|
|
|
|
getUser: function () {
|
|
|
|
return Meteor.users.findOne({slug: this.params._idOrSlug});
|
|
|
|
},
|
|
|
|
|
2014-11-17 14:45:23 +09:00
|
|
|
data: function() {
|
|
|
|
var findById = Meteor.users.findOne(this.params._idOrSlug);
|
|
|
|
var findBySlug = Meteor.users.findOne({slug: this.params._idOrSlug});
|
2014-11-30 18:23:19 -08:00
|
|
|
if (typeof findById !== 'undefined') {
|
2014-11-17 14:45:23 +09:00
|
|
|
// redirect to slug-based URL
|
|
|
|
Router.go(getProfileUrl(findById), {replaceState: true});
|
2014-11-30 18:23:19 -08:00
|
|
|
} else {
|
2014-11-17 14:45:23 +09:00
|
|
|
return {
|
2014-11-30 18:23:19 -08:00
|
|
|
user: (typeof findById == 'undefined') ? findBySlug : findById
|
2014-11-17 14:45:23 +09:00
|
|
|
};
|
|
|
|
}
|
2014-11-27 17:25:01 +05:30
|
|
|
},
|
2014-12-15 09:52:37 +09:00
|
|
|
|
|
|
|
getTitle: function () {
|
2015-01-05 16:32:38 +09:00
|
|
|
return getDisplayName(this.getUser()) + ' - ' + getSetting('title', "Telescope");
|
2014-12-15 09:52:37 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
getDescription: function () {
|
|
|
|
return i18n.t('the_profile_of') + ' ' + getDisplayName(this.getUser());
|
|
|
|
},
|
|
|
|
|
2014-11-27 17:25:01 +05:30
|
|
|
fastRender: true
|
2014-12-15 09:52:37 +09:00
|
|
|
|
2014-11-17 14:45:23 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
// Controller for user account editing
|
|
|
|
|
2014-12-08 10:30:31 +09:00
|
|
|
UserEditController = RouteController.extend({
|
2014-11-17 14:45:23 +09:00
|
|
|
waitOn: function() {
|
2014-11-30 18:23:19 -08:00
|
|
|
return [
|
2014-12-08 22:17:43 +09:00
|
|
|
coreSubscriptions.subscribe('singleUser', this.params.slug)
|
2014-11-30 18:23:19 -08:00
|
|
|
]
|
2014-11-17 14:45:23 +09:00
|
|
|
},
|
|
|
|
data: function() {
|
2014-11-30 18:23:19 -08:00
|
|
|
var user = Meteor.users.findOne({slug: this.params.slug});
|
2014-12-08 22:17:43 +09:00
|
|
|
return {
|
2014-11-30 18:23:19 -08:00
|
|
|
user: user
|
2014-12-08 22:17:43 +09:00
|
|
|
};
|
2014-11-27 17:25:01 +05:30
|
|
|
},
|
|
|
|
fastRender: true
|
2014-11-17 14:45:23 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
Meteor.startup(function () {
|
2014-11-22 21:19:55 -08:00
|
|
|
|
2014-11-17 14:45:23 +09:00
|
|
|
// User Logout
|
|
|
|
|
|
|
|
Router.route('/sign-out', {
|
|
|
|
name: 'signOut',
|
2014-12-13 11:58:47 +09:00
|
|
|
template: getTemplate('sign_out'),
|
2014-11-17 14:45:23 +09:00
|
|
|
onBeforeAction: function() {
|
|
|
|
Meteor.logout(function() {
|
|
|
|
});
|
2014-12-13 11:58:47 +09:00
|
|
|
this.next();
|
2014-11-17 14:45:23 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// User Profile
|
|
|
|
|
|
|
|
Router.route('/users/:_idOrSlug', {
|
|
|
|
name: 'user_profile',
|
|
|
|
template: getTemplate('user_profile'),
|
|
|
|
controller: UserPageController
|
|
|
|
});
|
|
|
|
|
|
|
|
// User Edit
|
|
|
|
|
2014-11-30 18:23:19 -08:00
|
|
|
Router.route('/users/:slug/edit', {
|
2014-11-17 14:45:23 +09:00
|
|
|
name: 'user_edit',
|
|
|
|
template: getTemplate('user_edit'),
|
2014-11-30 18:23:19 -08:00
|
|
|
controller: UserEditController,
|
|
|
|
onBeforeAction: function () {
|
|
|
|
// Only allow users with permissions to see the user edit page.
|
|
|
|
if (Meteor.user() && (
|
|
|
|
isAdmin(Meteor.user()) ||
|
|
|
|
this.params.slug === Meteor.user().slug
|
|
|
|
)) {
|
|
|
|
this.next();
|
|
|
|
} else {
|
|
|
|
this.render(getTemplate('no_rights'));
|
|
|
|
}
|
|
|
|
}
|
2014-11-17 14:45:23 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
// All Users
|
|
|
|
|
|
|
|
Router.route('/all-users/:limit?', {
|
|
|
|
name: 'all-users',
|
|
|
|
template: getTemplate('users'),
|
|
|
|
waitOn: function() {
|
|
|
|
var limit = parseInt(this.params.limit) || 20;
|
|
|
|
return coreSubscriptions.subscribe('allUsers', this.params.filterBy, this.params.sortBy, limit);
|
|
|
|
},
|
|
|
|
data: function() {
|
|
|
|
var limit = parseInt(this.params.limit) || 20,
|
2014-11-22 21:19:55 -08:00
|
|
|
parameters = getUsersParameters(this.params.query.filterBy, this.params.query.sortBy, limit),
|
|
|
|
filterBy = (typeof this.params.query.filterBy === 'string') ? this.params.query.filterBy : 'all',
|
|
|
|
sortBy = (typeof this.params.query.sortBy === 'string') ? this.params.query.sortBy : 'createdAt';
|
2014-11-17 14:45:23 +09:00
|
|
|
Session.set('usersLimit', limit);
|
|
|
|
return {
|
|
|
|
users: Meteor.users.find(parameters.find, parameters.options),
|
|
|
|
filterBy: filterBy,
|
|
|
|
sortBy: sortBy
|
|
|
|
};
|
|
|
|
},
|
|
|
|
fastRender: true
|
|
|
|
});
|
|
|
|
|
|
|
|
// Unsubscribe (from notifications)
|
|
|
|
|
|
|
|
Router.route('/unsubscribe/:hash', {
|
|
|
|
name: 'unsubscribe',
|
|
|
|
template: getTemplate('unsubscribe'),
|
|
|
|
data: function() {
|
|
|
|
return {
|
|
|
|
hash: this.params.hash
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|