mirror of
https://github.com/fazo96/markcloud.git
synced 2025-01-10 11:04:21 +01:00
added expiration, usernames and other stuff
This commit is contained in:
parent
1a7de61d0f
commit
f8f855c97c
@ -71,6 +71,7 @@ Template.notifications.events
|
||||
Template.layout.showSpinner = ->
|
||||
Meteor.status().connected is no or Router.current().ready() is no
|
||||
Template.home.ndocs = -> docs.find().count()
|
||||
Template.new.showTitleChecked = -> return "checked" unless @showTitle is no
|
||||
Template.new.events
|
||||
'click #upload': (e,t) ->
|
||||
if t.find('#title').value is ''
|
||||
@ -90,31 +91,22 @@ Template.new.events
|
||||
title: t.find('#title').value
|
||||
text: t.find('#editor').value
|
||||
showTitle: $('#show-title').is(':checked')
|
||||
dateCreated: moment().unix()
|
||||
}, (err,id) ->
|
||||
if err then errCallback err
|
||||
else notify type:'success', msg:'Document created successfully'
|
||||
if id then Router.go 'doc', _id: id
|
||||
###docs.upsert @_id, $set: {
|
||||
title: t.find('#title').value
|
||||
text: t.find('#editor').value
|
||||
showTitle: $('#show-title').is(':checked')
|
||||
dateCreated: moment().unix()
|
||||
}, (err,resp) ->
|
||||
if err then errCallback err
|
||||
else if @_id
|
||||
notify type:'success', msg:'Document updated'
|
||||
Router.go 'doc', _id: @_id
|
||||
else
|
||||
notify type:'success', msg:'Document created successfully'
|
||||
Router.go 'doc', _id: resp.insertedId###
|
||||
|
||||
Template.list.documents = -> docs.find owner: @userId
|
||||
Template.list.documents = ->
|
||||
console.log docs.find(owner: @userId).fetch()
|
||||
docs.find {owner: @userId}, sort: dateCreated: -1
|
||||
|
||||
Template.doc.source = -> Router.current().route.name is 'src'
|
||||
Template.doc.rows = -> ""+@text.split('\n').length
|
||||
Template.doc.valid = -> @text?
|
||||
Template.doc.owned = -> Meteor.user()._id is @owner
|
||||
Template.doc.expirationDays = ->
|
||||
if @owner then return 'never'
|
||||
else return moment.unix(@dateCreated).add(7,'days').fromNow()
|
||||
Template.doc.events
|
||||
'click #edit-doc': -> Router.go 'edit', _id: @_id
|
||||
'click #del-doc': ->
|
||||
@ -130,7 +122,7 @@ Template.doc.events
|
||||
Template.signin.events
|
||||
'click #signin': (e,t) ->
|
||||
if not t.find('#mail').value
|
||||
return notify msg: 'please enter an email'
|
||||
return notify msg: 'please enter your email or username'
|
||||
else if not t.find('#pw').value
|
||||
return notify msg: "Please enter a password"
|
||||
else
|
||||
@ -141,14 +133,16 @@ Template.signin.events
|
||||
Template.signup.events
|
||||
'click #signup': (e,t) ->
|
||||
if not t.find('#mail').value
|
||||
return notify msg: 'please enter an email'
|
||||
return notify msg: 'please enter your email'
|
||||
if not t.find('#name').value
|
||||
return notify msg: 'please enter your user name'
|
||||
else if not t.find('#pw').value
|
||||
return notify msg: "Please enter a password"
|
||||
else if t.find('#pw').value isnt t.find('#rpw').value
|
||||
return notify msg: "The passwords don't match"
|
||||
else # Sending actual registration request
|
||||
console.log t.find('#mail').value
|
||||
Accounts.createUser {
|
||||
username: t.find('#name').value
|
||||
email: t.find('#mail').value
|
||||
password: t.find('#pw').value
|
||||
}, (err) -> if err then errCallback err
|
||||
|
@ -16,7 +16,7 @@
|
||||
</template>
|
||||
|
||||
<template name="home">
|
||||
{{#if currentUser}}<p>Logged in as <b>{{mail}}</b></p>{{/if}}
|
||||
{{#if currentUser}}<p>Logged in as <b>{{username}} ({{mail}})</b></p>{{/if}}
|
||||
<p>This is a demo app. Click <a href="new">here</a> to create a new document.</p>
|
||||
<p>After submitting the document you will be redirected to its permanent link</p>
|
||||
<p>There are <b>{{ndocs}}</b> documents in the database</p>
|
||||
@ -29,10 +29,11 @@
|
||||
<template name="new">
|
||||
<p>Write your document in <a href="https://help.github.com/articles/github-flavored-markdown/">GitHub Flavored Markdown</a> then submit it with the button. You will be redirected to its permanent link</p>
|
||||
<input type="text" id="title" class="form-control" placeholder="Title" value="{{title}}">
|
||||
<input type="checkbox" id="show-title" checked> Show title in document
|
||||
<input type="checkbox" id="show-title" {{showTitleChecked}}>
|
||||
Show title in document
|
||||
<textarea id="editor" class="form-control" rows="10" placeholder="Write your markdown :)" autofocus>{{text}}</textarea>
|
||||
<button id="upload" class="btn btn-primary">
|
||||
<i class="fa fa-upload"></i> {{#if _id}}Update{{else}}Upload{{/if}}</button>
|
||||
<i class="fa fa-upload"></i> {{#if _id}}Update{{else}}Create{{/if}}</button>
|
||||
</template>
|
||||
|
||||
<template name="docLayout">
|
||||
@ -67,6 +68,10 @@
|
||||
{{/unless}}
|
||||
{{#if owned}}
|
||||
<p>This document is <b>yours</b>.</p>
|
||||
{{else}}
|
||||
{{#unless owner}}
|
||||
<p>This anonymous document will <b>expire {{expirationDays}}</b></p>
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
{{#if valid}}
|
||||
<div class="btn-group" id="tools">
|
||||
@ -124,7 +129,9 @@
|
||||
<template name="signup">
|
||||
<div id="signup-container">
|
||||
<h2>Sign Up<a href="/"><i class="fa fa-home pull-right"></i></a></h2>
|
||||
<p>You will be able to log in using your email or your username.</p>
|
||||
<input type="text" class="form-control" id="mail" placeholder="E-Mail Address">
|
||||
<input type="text" class="form-control" id="name" placeholder="Username">
|
||||
<input type="password" class="form-control" placeholder="Password" id="pw">
|
||||
<input type="password" class="form-control" placeholder="Repeat Password" id="rpw">
|
||||
<button class="btn btn-primary" id="signup">Sign Up</button>
|
||||
@ -136,7 +143,7 @@
|
||||
<template name="signin">
|
||||
<div id="signin-container">
|
||||
<h2>Sign In<a href="/"><i class="fa fa-home pull-right"></i></a></h2>
|
||||
<input type="text" class="form-control" id="mail" placeholder="E-Mail Address">
|
||||
<input type="text" class="form-control" id="mail" placeholder="E-Mail Address or Username">
|
||||
<input type="password" class="form-control" placeholder="Password" id="pw">
|
||||
<button class="btn btn-primary" id="signin">Sign In</button>
|
||||
<hr>
|
||||
@ -145,7 +152,9 @@
|
||||
</template>
|
||||
|
||||
<template name="list">
|
||||
<ul class="list-group">
|
||||
{{#each documents}}
|
||||
<a href="/d/{{_id}}">{{title}}</a>
|
||||
<a class="list-group-item" href="/d/{{_id}}">{{title}}</a>
|
||||
{{/each}}
|
||||
</ul>
|
||||
</template>
|
||||
|
@ -1,5 +1,18 @@
|
||||
docs = new Meteor.Collection 'docs'
|
||||
|
||||
cleanDocuments = ->
|
||||
docs.remove {
|
||||
owner: {$exists: no},
|
||||
dateCreated: $lte: moment().subtract(7, 'days').unix()
|
||||
}, (e,n) ->
|
||||
if e then console.log e
|
||||
console.log n+' anonymous documents \
|
||||
not updated by more than 7 days have been removed'
|
||||
|
||||
Meteor.startup ->
|
||||
cleanDocuments()
|
||||
Meteor.setInterval cleanDocuments, 3600000
|
||||
|
||||
validatedUser = (uid) ->
|
||||
return no unless Meteor.users.findOne uid
|
||||
u = Meteor.users.findOne uid
|
||||
@ -18,15 +31,18 @@ docs.allow
|
||||
insert: (uid,doc) ->
|
||||
if doc.text and doc.title
|
||||
doc.dateCreated = moment().unix()
|
||||
doc.showTitle ?= yes
|
||||
if doc.owner and !uid then return no
|
||||
if uid then doc.owner = uid
|
||||
console.log doc.dateCreated
|
||||
return yes
|
||||
return no
|
||||
docs.allow
|
||||
# Owners can update and remove their documents
|
||||
update: (uid,doc) -> doc.owner is uid
|
||||
update: (uid,doc) ->
|
||||
return no unless uid is doc.owner
|
||||
docs.update doc._id, $set: lastModified: moment().unix()
|
||||
return yes
|
||||
remove: (uid,doc) -> doc.owner is uid
|
||||
fetch: ['owner'] # Only fetch the owner field from the database documents
|
||||
fetch: ['owner']
|
||||
|
||||
# Save account creation date
|
||||
|
Loading…
Reference in New Issue
Block a user