mirror of
https://github.com/fazo96/markcloud.git
synced 2025-01-10 11:04:21 +01:00
finished everything. Just need testing.
This commit is contained in:
parent
f8f855c97c
commit
66e3ea81a9
@ -1,5 +1,5 @@
|
|||||||
docs = new Meteor.Collection 'docs'
|
docs = new Meteor.Collection 'docs'
|
||||||
Meteor.subscribe 'user'
|
|
||||||
UI.registerHelper 'mail', -> Meteor.user().emails[0].address
|
UI.registerHelper 'mail', -> Meteor.user().emails[0].address
|
||||||
|
|
||||||
Router.configure
|
Router.configure
|
||||||
@ -15,6 +15,11 @@ docController = RouteController.extend
|
|||||||
if @ready() then @render()
|
if @ready() then @render()
|
||||||
else @render 'loading'
|
else @render 'loading'
|
||||||
|
|
||||||
|
loggedOutController = RouteController.extend
|
||||||
|
onBeforeAction: -> if Meteor.user() then Router.go 'profile'
|
||||||
|
loggedInController = RouteController.extend
|
||||||
|
action: -> if !Meteor.user() then @render '404' else @render()
|
||||||
|
|
||||||
Router.map ->
|
Router.map ->
|
||||||
@route 'home',
|
@route 'home',
|
||||||
path: '/'
|
path: '/'
|
||||||
@ -30,29 +35,36 @@ Router.map ->
|
|||||||
path:'/src/:_id'
|
path:'/src/:_id'
|
||||||
controller: docController
|
controller: docController
|
||||||
@route 'verify',
|
@route 'verify',
|
||||||
path: '/verify/:token'
|
path: '/verify/:token?'
|
||||||
template: 'loading'
|
|
||||||
onBeforeAction: ->
|
onBeforeAction: ->
|
||||||
Accounts.verifyEmail @params.token, (err) ->
|
Accounts.verifyEmail @params.token, (err) ->
|
||||||
if err then errCallback err else Router.go 'home'
|
if err then errCallback err else Router.go 'home'
|
||||||
@route 'edit',
|
@route 'edit',
|
||||||
path: '/edit/:_id'
|
path: '/edit/:_id'
|
||||||
template: 'new'
|
template: 'new'
|
||||||
|
controller: loggedInController
|
||||||
waitOn: -> Meteor.subscribe 'doc', @params._id
|
waitOn: -> Meteor.subscribe 'doc', @params._id
|
||||||
data: -> docs.findOne @params._id
|
data: -> docs.findOne @params._id
|
||||||
@route 'list',
|
@route 'profile',
|
||||||
path: '/list/:user?'
|
path: '/u/:user?'
|
||||||
waitOn: -> Meteor.subscribe 'docs', @params.user
|
waitOn: ->
|
||||||
|
[Meteor.subscribe('docs', @params.user),
|
||||||
|
Meteor.subscribe('user',@params.user)]
|
||||||
data: -> userId: @params.user
|
data: -> userId: @params.user
|
||||||
onBeforeAction: ->
|
onBeforeAction: ->
|
||||||
if Meteor.user() and !@params.user
|
if Meteor.user() and !@params.user
|
||||||
Router.go 'list', user: Meteor.user()._id
|
Router.go 'profile', user: Meteor.user()._id
|
||||||
action: ->
|
action: ->
|
||||||
if !@params.user then @render '404'
|
if !@params.user then @render '404'
|
||||||
else @render()
|
else @render()
|
||||||
|
@route 'delete',
|
||||||
|
controller: loggedInController
|
||||||
@route 'new'
|
@route 'new'
|
||||||
@route 'signup'
|
@route 'signup',
|
||||||
@route 'signin', path: 'login'
|
controller: loggedOutController
|
||||||
|
@route 'signin',
|
||||||
|
path: 'login'
|
||||||
|
controller: loggedOutController
|
||||||
@route '404', path: '*'
|
@route '404', path: '*'
|
||||||
|
|
||||||
notification = new ReactiveVar()
|
notification = new ReactiveVar()
|
||||||
@ -68,6 +80,7 @@ Template.notifications.notification = -> notification.get()
|
|||||||
Template.notifications.events
|
Template.notifications.events
|
||||||
'click .close': -> notify()
|
'click .close': -> notify()
|
||||||
|
|
||||||
|
Template.layout.notHome = -> Router.current().route.name isnt 'home'
|
||||||
Template.layout.showSpinner = ->
|
Template.layout.showSpinner = ->
|
||||||
Meteor.status().connected is no or Router.current().ready() is no
|
Meteor.status().connected is no or Router.current().ready() is no
|
||||||
Template.home.ndocs = -> docs.find().count()
|
Template.home.ndocs = -> docs.find().count()
|
||||||
@ -96,9 +109,19 @@ Template.new.events
|
|||||||
else notify type:'success', msg:'Document created successfully'
|
else notify type:'success', msg:'Document created successfully'
|
||||||
if id then Router.go 'doc', _id: id
|
if id then Router.go 'doc', _id: id
|
||||||
|
|
||||||
Template.list.documents = ->
|
Template.profile.name = -> Meteor.user().username
|
||||||
console.log docs.find(owner: @userId).fetch()
|
Template.profile.isMe = ->
|
||||||
|
Meteor.user() and Meteor.user()._id is @userId
|
||||||
|
Template.profile.noDocs = -> docs.find(owner: @userId).count() is 0
|
||||||
|
Template.profile.documents = ->
|
||||||
docs.find {owner: @userId}, sort: dateCreated: -1
|
docs.find {owner: @userId}, sort: dateCreated: -1
|
||||||
|
Template.profile.events
|
||||||
|
'click #logout': -> Meteor.logout(); Router.go 'home'
|
||||||
|
|
||||||
|
Template.delete.events
|
||||||
|
'click #del-account': (e,t) ->
|
||||||
|
if t.find('#name').value is Meteor.user()._id
|
||||||
|
Meteor.call 'deleteMe'
|
||||||
|
|
||||||
Template.doc.source = -> Router.current().route.name is 'src'
|
Template.doc.source = -> Router.current().route.name is 'src'
|
||||||
Template.doc.rows = -> ""+@text.split('\n').length
|
Template.doc.rows = -> ""+@text.split('\n').length
|
||||||
@ -147,3 +170,6 @@ Template.signup.events
|
|||||||
password: t.find('#pw').value
|
password: t.find('#pw').value
|
||||||
}, (err) -> if err then errCallback err
|
}, (err) -> if err then errCallback err
|
||||||
else notify type: 'success', msg: 'check your email'
|
else notify type: 'success', msg: 'check your email'
|
||||||
|
|
||||||
|
Template.verify.events
|
||||||
|
'click #sendmail': -> Meteor.call 'sendVerificationEmail'
|
||||||
|
@ -22,6 +22,12 @@
|
|||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Home
|
||||||
|
|
||||||
|
#new, #btns {
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
// Editor
|
// Editor
|
||||||
|
|
||||||
#title {
|
#title {
|
||||||
@ -45,14 +51,26 @@
|
|||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sign up
|
// Sign up and Sign in
|
||||||
#signup-container, #signin-container {
|
#signup-container, #signin-container {
|
||||||
#mail { margin-top: 2em; }
|
#mail { margin-top: 2em; margin-bottom: 1em }
|
||||||
#pw {
|
#pw {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
margin-bottom: 1em;
|
|
||||||
}
|
}
|
||||||
.btn {
|
.btn {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#signup-container {
|
||||||
|
#pw {
|
||||||
|
margin-bottom: 1em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Profile
|
||||||
|
|
||||||
|
#profile-tools {
|
||||||
|
margin-top: 1em;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
}
|
||||||
|
@ -8,7 +8,19 @@
|
|||||||
<template name="layout">
|
<template name="layout">
|
||||||
{{> yield region="outside"}}
|
{{> yield region="outside"}}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>MarkCloud</h1>
|
<h1>MarkCloud
|
||||||
|
{{#if currentUser}}
|
||||||
|
<a class="pull-right" href="/u">
|
||||||
|
<small><i class="fa fa-chevron-right"></i></small>
|
||||||
|
</a>
|
||||||
|
{{else}}
|
||||||
|
{{#if notHome}}
|
||||||
|
<a class="pull-right" href="/">
|
||||||
|
<small><i class="fa fa-home"></i></small>
|
||||||
|
</a>
|
||||||
|
{{/if}}
|
||||||
|
{{/if}}
|
||||||
|
</h1>
|
||||||
<hr>
|
<hr>
|
||||||
{{> notifications}}
|
{{> notifications}}
|
||||||
{{> yield}}
|
{{> yield}}
|
||||||
@ -16,14 +28,41 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template name="home">
|
<template name="home">
|
||||||
{{#if currentUser}}<p>Logged in as <b>{{username}} ({{mail}})</b></p>{{/if}}
|
{{#markdown}}
|
||||||
<p>This is a demo app. Click <a href="new">here</a> to create a new document.</p>
|
### Share your markdown easily
|
||||||
<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>
|
Markcloud is a simple application that lets you share your markdown documents
|
||||||
<p>This demo was built by <a href="http://github.com/fazo96">Enrico
|
to the world. Just paste your markdown and get a _permanent link_ that lets you
|
||||||
Fasoli (fazo96)</a> in 45 minutes, it's now evolving to a full app.</p>
|
and everyone else view the result in a **modern responsive web page**.
|
||||||
<p>It's open source, you can find the code
|
|
||||||
<a href="http://github.com/fazo96/markcloud">here</a></p>
|
### Free as in Free Software
|
||||||
|
|
||||||
|
No ads. [Open Source](http://github.com/fazo96/markcloud).
|
||||||
|
|
||||||
|
Made by [some guy in the internet](http://github.com/fazo96) that you probably should not trust, but hey:
|
||||||
|
|
||||||
|
### No Account needed
|
||||||
|
|
||||||
|
You can create a document _right now_. It will expire in 7 days.
|
||||||
|
This home page is written in markdown too!
|
||||||
|
{{/markdown}}
|
||||||
|
<div class="text-center"><a class="btn btn-success" id="new" href="/new">
|
||||||
|
<i class="fa fa-file-text"></i> New Document</a></div>
|
||||||
|
{{#markdown}}
|
||||||
|
### But with an account...
|
||||||
|
|
||||||
|
- Your documents **never expire!**
|
||||||
|
- You can **edit** and **delete** your documents
|
||||||
|
- You can **view** and **share** a list of all your documents
|
||||||
|
|
||||||
|
You will be able to delete your account and all your data whenever you want.
|
||||||
|
{{/markdown}}
|
||||||
|
<div class="text-center" id="btns">
|
||||||
|
<a class="btn btn-primary" href="/signup">
|
||||||
|
<i class="fa fa-user"></i> Sign Up</a>
|
||||||
|
<a class="btn btn-success" href="/login">
|
||||||
|
<i class="fa fa-sign-in"></i> Log In</a>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template name="new">
|
<template name="new">
|
||||||
@ -66,32 +105,32 @@
|
|||||||
{{#unless currentUser}}
|
{{#unless currentUser}}
|
||||||
<p><a href="/login">Log in</a> to edit and delete your documents<br></p>
|
<p><a href="/login">Log in</a> to edit and delete your documents<br></p>
|
||||||
{{/unless}}
|
{{/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}}
|
{{#if valid}}
|
||||||
<div class="btn-group" id="tools">
|
{{#if owned}}
|
||||||
{{#if currentUser}}{{#if owned}}
|
<p>This document is <a href="/u">yours</a>.</p>
|
||||||
<button id="edit-doc" class="btn btn-primary">
|
|
||||||
<i class="fa fa-edit"></i> Edit</button>
|
|
||||||
{{/if}}{{/if}}
|
|
||||||
{{#if source}}
|
|
||||||
<button id="src-doc" class="btn btn-success">
|
|
||||||
<i class="fa fa-book"></i> View Document</button>
|
|
||||||
{{else}}
|
{{else}}
|
||||||
<button id="src-doc" class="btn btn-success">
|
{{#unless owner}}
|
||||||
<i class="fa fa-code"></i> View Source</button>
|
<p>This anonymous document will <b>expire {{expirationDays}}</b></p>
|
||||||
|
{{/unless}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if currentUser}}{{#if owned}}
|
<div class="btn-group" id="tools">
|
||||||
<button id="del-doc" class="btn btn-danger">
|
{{#if currentUser}}{{#if owned}}
|
||||||
<i class="fa fa-trash"></i> Delete</button>
|
<button id="edit-doc" class="btn btn-primary">
|
||||||
{{/if}}{{/if}}
|
<i class="fa fa-edit"></i> Edit</button>
|
||||||
</div>
|
{{/if}}{{/if}}
|
||||||
<br>
|
{{#if source}}
|
||||||
|
<button id="src-doc" class="btn btn-success">
|
||||||
|
<i class="fa fa-book"></i> View Document</button>
|
||||||
|
{{else}}
|
||||||
|
<button id="src-doc" class="btn btn-success">
|
||||||
|
<i class="fa fa-code"></i> View Source</button>
|
||||||
|
{{/if}}
|
||||||
|
{{#if currentUser}}{{#if owned}}
|
||||||
|
<button id="del-doc" class="btn btn-danger">
|
||||||
|
<i class="fa fa-trash"></i> Delete</button>
|
||||||
|
{{/if}}{{/if}}
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
{{/if}}Powered by <a href="/">MarkCloud</a>
|
{{/if}}Powered by <a href="/">MarkCloud</a>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -128,7 +167,7 @@
|
|||||||
|
|
||||||
<template name="signup">
|
<template name="signup">
|
||||||
<div id="signup-container">
|
<div id="signup-container">
|
||||||
<h2>Sign Up<a href="/"><i class="fa fa-home pull-right"></i></a></h2>
|
<h2>Sign Up</h2>
|
||||||
<p>You will be able to log in using your email or your username.</p>
|
<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="mail" placeholder="E-Mail Address">
|
||||||
<input type="text" class="form-control" id="name" placeholder="Username">
|
<input type="text" class="form-control" id="name" placeholder="Username">
|
||||||
@ -142,7 +181,7 @@
|
|||||||
|
|
||||||
<template name="signin">
|
<template name="signin">
|
||||||
<div id="signin-container">
|
<div id="signin-container">
|
||||||
<h2>Sign In<a href="/"><i class="fa fa-home pull-right"></i></a></h2>
|
<h2>Sign In</h2>
|
||||||
<input type="text" class="form-control" id="mail" placeholder="E-Mail Address or Username">
|
<input type="text" class="form-control" id="mail" placeholder="E-Mail Address or Username">
|
||||||
<input type="password" class="form-control" placeholder="Password" id="pw">
|
<input type="password" class="form-control" placeholder="Password" id="pw">
|
||||||
<button class="btn btn-primary" id="signin">Sign In</button>
|
<button class="btn btn-primary" id="signin">Sign In</button>
|
||||||
@ -151,10 +190,48 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template name="list">
|
<template name="profile">
|
||||||
<ul class="list-group">
|
{{#if isMe}}
|
||||||
{{#each documents}}
|
<div class="text-center">
|
||||||
<a class="list-group-item" href="/d/{{_id}}">{{title}}</a>
|
<p>Hello {{name}} ({{mail}}). This is your profile.</p>
|
||||||
{{/each}}
|
</div>
|
||||||
</ul>
|
{{/if}}
|
||||||
|
{{#if noDocs}}
|
||||||
|
<div class="text-center">
|
||||||
|
{{#if isMe}}
|
||||||
|
<p>You don't have any documents yet.</p>
|
||||||
|
{{else}}
|
||||||
|
<p>This user does not have any documents.</p>
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
{{#if isMe}}
|
||||||
|
<div class="text-center" id="profile-tools">
|
||||||
|
<a class="btn btn-primary" id="logout">
|
||||||
|
<i class="fa fa-sign-out"></i> Logout</a>
|
||||||
|
<a class="btn btn-success" href="/new">
|
||||||
|
<i class="fa fa-file-text"></i> New Document</a>
|
||||||
|
<a class="btn btn-danger" href="/delete">
|
||||||
|
<i class="fa fa-exclamation-circle"></i> Delete Account</a>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
{{#unless noDocs}}
|
||||||
|
<ul class="list-group">
|
||||||
|
{{#each documents}}
|
||||||
|
<a class="list-group-item" href="/d/{{_id}}">{{title}}</a>
|
||||||
|
{{/each}}
|
||||||
|
</ul>
|
||||||
|
{{/unless}}
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template name="delete">
|
||||||
|
<p>If you want to delete your account enter your User Id ({{currentUser._id}})</p>
|
||||||
|
<input type="text" class="form-control" id="name" placeholder="enter your User Id.">
|
||||||
|
<button class="btn btn-danger" id="del-account">
|
||||||
|
<i class="fa fa-exclamation-circle"></i> Confirm</button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template name="verify">
|
||||||
|
<p>If you didn't receive anything at <b>{{mail}}</b> address press the button below.</p>
|
||||||
|
<button id="sendmail" class="btn btn-primary">Resend</button>
|
||||||
</template>
|
</template>
|
||||||
|
@ -22,10 +22,8 @@ Meteor.publish 'doc', (id) -> docs.find {_id: id}, limit: 1
|
|||||||
Meteor.publish 'docs', (userId) ->
|
Meteor.publish 'docs', (userId) ->
|
||||||
if userId? then docs.find {owner: userId}, fields: text: 0
|
if userId? then docs.find {owner: userId}, fields: text: 0
|
||||||
else docs.find {}, fields: text: 0
|
else docs.find {}, fields: text: 0
|
||||||
Meteor.publish 'user', ->
|
Meteor.publish 'user', (id) ->
|
||||||
if @userId
|
Meteor.users.find {_id: id}, fields: {username: 1}
|
||||||
Meteor.users.find {_id: @userId}, fields: {dateCreated: 1}
|
|
||||||
else @ready()
|
|
||||||
|
|
||||||
docs.allow
|
docs.allow
|
||||||
insert: (uid,doc) ->
|
insert: (uid,doc) ->
|
||||||
@ -45,4 +43,10 @@ docs.allow
|
|||||||
remove: (uid,doc) -> doc.owner is uid
|
remove: (uid,doc) -> doc.owner is uid
|
||||||
fetch: ['owner']
|
fetch: ['owner']
|
||||||
|
|
||||||
# Save account creation date
|
Meteor.methods
|
||||||
|
'deleteMe': ->
|
||||||
|
if @userId
|
||||||
|
Meteor.users.remove @userId
|
||||||
|
docs.remove owner: @userId
|
||||||
|
'sendVerificationEmail': ->
|
||||||
|
if @userId then Accounts.sendVerificationEmail @userId
|
||||||
|
Loading…
Reference in New Issue
Block a user