mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
reworking invite system
This commit is contained in:
parent
51ced3e331
commit
e9119ef036
17 changed files with 121 additions and 42 deletions
|
@ -7,6 +7,12 @@
|
|||
<p>No settings yet.</p>
|
||||
{{/if}}
|
||||
{{#if currentUser.isAdmin}}
|
||||
<div class="control-group">
|
||||
<label class="control-label">Require Invite?</label>
|
||||
<div class="controls">
|
||||
<input type="checkbox" name="requireInvite" id="requireInvite" {{#if requireInvite}}checked{{/if}} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label>Site Title</label>
|
||||
<div class="controls"><input id="title" name="title" type="text" value="{{title}}" /></div>
|
||||
|
|
|
@ -2,6 +2,7 @@ Template.settings.events = {
|
|||
'click input[type=submit]': function(e){
|
||||
e.preventDefault();
|
||||
if(!Meteor.user()) throw 'You must be logged in.';
|
||||
var requireInvite=!!$('#requireInvite').attr('checked');
|
||||
var title= $('#title').val();
|
||||
var theme = $('#theme').val();
|
||||
var footerCode=$("#footerCode").val();
|
||||
|
@ -23,6 +24,7 @@ Template.settings.events = {
|
|||
if(prevSetting){
|
||||
Settings.update(prevSetting._id,{
|
||||
$set: {
|
||||
requireInvite:requireInvite,
|
||||
title: title,
|
||||
theme: theme,
|
||||
footerCode: footerCode,
|
||||
|
@ -46,6 +48,7 @@ Template.settings.events = {
|
|||
});
|
||||
}else{
|
||||
var settingId = Settings.insert({
|
||||
requireInvite:requireInvite,
|
||||
title: title,
|
||||
theme: theme,
|
||||
footerCode: footerCode,
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
{{/with}}
|
||||
{{/if}}
|
||||
|
||||
{{#if currentUser.approved}}
|
||||
{{#if canPostComment}}
|
||||
{{> comment_form}}
|
||||
{{/if}}
|
||||
</div>
|
||||
|
|
|
@ -3,8 +3,13 @@ Template.comment_page.post = function(){
|
|||
return selectedComment && Posts.findOne(selectedComment.post);
|
||||
};
|
||||
|
||||
Template.comment_page.comment = function(){
|
||||
var comment = Comments.findOne(Session.get('selectedCommentId'));
|
||||
Template.comment_page.repress_recursion = true;
|
||||
return comment;
|
||||
};
|
||||
Template.comment_page.helpers({
|
||||
comment: function(){
|
||||
var comment = Comments.findOne(Session.get('selectedCommentId'));
|
||||
Template.comment_page.repress_recursion = true;
|
||||
return comment;
|
||||
},
|
||||
canComment: function(){
|
||||
return canComment(Meteor.user());
|
||||
}
|
||||
});
|
|
@ -50,7 +50,7 @@
|
|||
<li><a id="signup" href="signup">Sign Up</a></li>
|
||||
<li><a id="signin" href="signin">Sign In</a></li>
|
||||
{{/if}} -->
|
||||
{{#if currentUser.approved}}
|
||||
{{#if canPost}}
|
||||
<li><a id="submit" class="submit button" href="/submit">Post</a></li>
|
||||
{{/if}}
|
||||
</ul>
|
||||
|
|
|
@ -21,28 +21,25 @@ Template.nav.helpers({
|
|||
site_title: function(){
|
||||
return getSetting('title');
|
||||
},
|
||||
|
||||
logo_url: function(){
|
||||
return getSetting('logoUrl');
|
||||
},
|
||||
|
||||
logo_height: function(){
|
||||
return getSetting('logoHeight');
|
||||
},
|
||||
|
||||
logo_width: function(){
|
||||
return getSetting('logoWidth');
|
||||
},
|
||||
|
||||
logo_top: function(){
|
||||
return Math.floor((70-getSetting('logoHeight'))/2);
|
||||
},
|
||||
|
||||
logo_offset: function(){
|
||||
return -Math.floor(getSetting('logoWidth')/2);
|
||||
},
|
||||
|
||||
intercom: function(){
|
||||
return !!getSetting('intercomId');
|
||||
}
|
||||
},
|
||||
canPost: function(){
|
||||
return canPost(Meteor.user());
|
||||
}
|
||||
});
|
|
@ -15,6 +15,7 @@ Template.notifications.helpers({
|
|||
notification_class: function(){
|
||||
var notifications=Notifications.find({userId: Meteor.user()._id, read: false}).fetch();
|
||||
if(notifications.length==0)
|
||||
return 'no-notifications';
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
{{#with post}}
|
||||
{{> post_item}}
|
||||
{{/with}}
|
||||
{{#if currentUser.approved}}
|
||||
{{#if canComment}}
|
||||
{{> comment_form}}
|
||||
{{/if}}
|
||||
{{> comment_list}}
|
||||
|
|
|
@ -7,6 +7,9 @@ Template.post_page.helpers({
|
|||
var converter = new Markdown.Converter();
|
||||
var html_body=converter.makeHtml(this.body);
|
||||
return html_body.autoLink();
|
||||
},
|
||||
canComment: function(){
|
||||
return canComment(Meteor.user());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
</td>
|
||||
<td><a href="#">{{comments_count}}</a></td>
|
||||
<td>{{karma}}</td>
|
||||
<td>{{#if isAdmin}}<i class="icon-check"></i>{{/if}}</td>
|
||||
<td>{{#if isInvited}}<i class="icon-check"></i>{{else}}<a href="#" class="invite-link">Invite</a>{{/if}}</td>
|
||||
<td>{{#if isAdmin}}<i class="icon-check"></i>{{else}}<a href="#" class="admin-link">Make admin</a>{{/if}}</td>
|
||||
</tr>
|
||||
</template>
|
|
@ -27,4 +27,39 @@ Template.user_item.helpers({
|
|||
// Posts.find({'user_id':this._id}).forEach(function(post){console.log(post.headline);});
|
||||
return Comments.find({'userId':this._id}).count();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Template.user_item.events({
|
||||
'click .invite-link': function(e, instance){
|
||||
e.preventDefault();
|
||||
Meteor.users.update(instance.data._id,{
|
||||
$set:{
|
||||
isInvited: true
|
||||
}
|
||||
});
|
||||
},
|
||||
'click .uninvite-link': function(e, instance){
|
||||
e.preventDefault();
|
||||
Meteor.users.update(instance.data._id,{
|
||||
$set:{
|
||||
isInvited: false
|
||||
}
|
||||
});
|
||||
},
|
||||
'click .admin-link': function(e, instance){
|
||||
e.preventDefault();
|
||||
Meteor.users.update(instance.data._id,{
|
||||
$set:{
|
||||
isAdmin: true
|
||||
}
|
||||
});
|
||||
},
|
||||
'click .unadmin-link': function(e, instance){
|
||||
e.preventDefault();
|
||||
Meteor.users.update(instance.data._id,{
|
||||
$set:{
|
||||
isAdmin: false
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
|
@ -11,6 +11,7 @@
|
|||
<td>Posts</td>
|
||||
<td>Comments</td>
|
||||
<td>Karma</td>
|
||||
<td>Is Invited?</td>
|
||||
<td>Is Admin?</td>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -2,9 +2,9 @@ Meteor.methods({
|
|||
comment: function(postId, parentCommentId, text){
|
||||
var user = Meteor.user();
|
||||
|
||||
if (!user || !user.approved)
|
||||
throw new Meteor.Error('You need to login and be approved to post new comments.')
|
||||
|
||||
if (!user || !canPost(user))
|
||||
throw new Meteor.Error('You need to login or be invited to post new comments.')
|
||||
|
||||
var comment = {
|
||||
post: postId
|
||||
, body: text
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
Meteor.methods({
|
||||
post: function(post){
|
||||
var user = Meteor.user();
|
||||
if (!user || !user.approved)
|
||||
throw new Meteor.Error('You need to login and be approved to post new stories.')
|
||||
|
||||
if (!user || !canPost(user))
|
||||
throw new Meteor.Error('You need to login or be invited to post new stories.')
|
||||
|
||||
post = _.extend(post, {
|
||||
userId: user._id,
|
||||
author: user.username,
|
||||
|
|
33
lib/users.js
33
lib/users.js
|
@ -1,3 +1,10 @@
|
|||
isAdminById=function(userId){
|
||||
var user = Meteor.users.findOne(userId);
|
||||
return user && isAdmin(user);
|
||||
}
|
||||
isAdmin=function(user){
|
||||
return user.isAdmin;
|
||||
}
|
||||
getDisplayNameById = function(userId){
|
||||
getDisplayName(Meteor.users.findOne(userId));
|
||||
}
|
||||
|
@ -36,3 +43,29 @@ getCurrentUserEmail = function(){
|
|||
userProfileComplete = function(user) {
|
||||
return !!getEmail(user);
|
||||
}
|
||||
|
||||
// Permissions
|
||||
|
||||
canView = function(user){
|
||||
|
||||
}
|
||||
canPost = function(user){
|
||||
if(typeof user=='undefined')
|
||||
return false
|
||||
if(isAdmin(user))
|
||||
return true;
|
||||
if(getSetting('requireInvite')==true){
|
||||
return user.isInvited;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
canComment = function(user){
|
||||
if(typeof user=='undefined')
|
||||
return false;
|
||||
if(isAdmin(user))
|
||||
return true;
|
||||
if(getSetting('requireInvite')==true){
|
||||
return user.isInvited;
|
||||
}
|
||||
return true;
|
||||
}
|
|
@ -1,11 +1,5 @@
|
|||
// Users
|
||||
isAdmin=function(userId){
|
||||
var user = Meteor.users.findOne(userId);
|
||||
return user && user.isAdmin;
|
||||
}
|
||||
|
||||
Meteor.publish('users', function() {
|
||||
if (this.userId() && isAdmin(this.userId())) {
|
||||
if (this.userId() && isAdminById(this.userId())) {
|
||||
return Meteor.users.find();
|
||||
}else{
|
||||
return Meteor.users.find({}, {fields: {emails: false}});
|
||||
|
@ -24,13 +18,13 @@ Meteor.startup(function(){
|
|||
// console.log(docs);
|
||||
// console.log('fields: '+fields);
|
||||
// console.log(modifier); //uncommenting this crashes everything
|
||||
if(isAdmin(userId) || (docs[0]._id && docs[0]._id==userId)){
|
||||
if(isAdminById(userId) || (docs[0]._id && docs[0]._id==userId)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
, remove: function(userId, docs){
|
||||
if(isAdmin(userId) || (docs[0]._id && docs[0]._id==userId)){
|
||||
if(isAdminById(userId) || (docs[0]._id && docs[0]._id==userId)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -61,13 +55,13 @@ Meteor.startup(function(){
|
|||
// console.log(userId);
|
||||
// console.log(docs);
|
||||
// console.log('fields: '+fields);
|
||||
if(isAdmin(userId) || (docs[0].user_id && docs[0].user_id==userId)){
|
||||
if(isAdminById(userId) || (docs[0].user_id && docs[0].user_id==userId)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
, remove: function(userId, docs){
|
||||
if(isAdmin(userId) || (docs[0].user_id && docs[0].user_id==userId)){
|
||||
if(isAdminById(userId) || (docs[0].user_id && docs[0].user_id==userId)){
|
||||
return true;
|
||||
}
|
||||
return false; }
|
||||
|
@ -91,13 +85,13 @@ Meteor.startup(function(){
|
|||
return false;
|
||||
}
|
||||
, update: function(userId, docs, fields, modifier){
|
||||
if(isAdmin(userId) || (docs[0].user_id && docs[0].user_id==userId)){
|
||||
if(isAdminById(userId) || (docs[0].user_id && docs[0].user_id==userId)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
, remove: function(userId, docs){
|
||||
if(isAdmin(userId) || (docs[0].user_id && docs[0].user_id==userId)){
|
||||
if(isAdminById(userId) || (docs[0].user_id && docs[0].user_id==userId)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -115,9 +109,9 @@ Meteor.publish('settings', function() {
|
|||
|
||||
Meteor.startup(function(){
|
||||
Settings.allow({
|
||||
insert: function(userId, docs){ return isAdmin(userId); }
|
||||
, update: function(userId, docs, fields, modifier){ return isAdmin(userId); }
|
||||
, remove: function(userId, docs){ return isAdmin(userId); }
|
||||
insert: function(userId, docs){ return isAdminById(userId); }
|
||||
, update: function(userId, docs, fields, modifier){ return isAdminById(userId); }
|
||||
, remove: function(userId, docs){ return isAdminById(userId); }
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -139,13 +133,13 @@ Meteor.startup(function(){
|
|||
return false;
|
||||
}
|
||||
, update: function(userId, docs, fields, modifier){
|
||||
if(isAdmin(userId) || (docs[0].user_id && docs[0].user_id==userId)){
|
||||
if(isAdminById(userId) || (docs[0].user_id && docs[0].user_id==userId)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
, remove: function(userId, docs){
|
||||
if(isAdmin(userId) || (docs[0].user_id && docs[0].user_id==userId)){
|
||||
if(isAdminById(userId) || (docs[0].user_id && docs[0].user_id==userId)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -5,7 +5,7 @@ Accounts.onCreateUser(function(options, extra, user){
|
|||
user.profile = user.profile || {};
|
||||
|
||||
// users start pending, need to be approved
|
||||
user.approved = false
|
||||
user.isInvited = false
|
||||
|
||||
if (options.email)
|
||||
user.profile.email = options.email;
|
||||
|
|
Loading…
Add table
Reference in a new issue