1
0
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:
Enrico Fasoli 2014-10-06 17:14:26 +02:00
parent f8f855c97c
commit 66e3ea81a9
4 changed files with 184 additions and 59 deletions

View File

@ -1,5 +1,5 @@
docs = new Meteor.Collection 'docs'
Meteor.subscribe 'user'
UI.registerHelper 'mail', -> Meteor.user().emails[0].address
Router.configure
@ -15,6 +15,11 @@ docController = RouteController.extend
if @ready() then @render()
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 ->
@route 'home',
path: '/'
@ -30,29 +35,36 @@ Router.map ->
path:'/src/:_id'
controller: docController
@route 'verify',
path: '/verify/:token'
template: 'loading'
path: '/verify/:token?'
onBeforeAction: ->
Accounts.verifyEmail @params.token, (err) ->
if err then errCallback err else Router.go 'home'
@route 'edit',
path: '/edit/:_id'
template: 'new'
controller: loggedInController
waitOn: -> Meteor.subscribe 'doc', @params._id
data: -> docs.findOne @params._id
@route 'list',
path: '/list/:user?'
waitOn: -> Meteor.subscribe 'docs', @params.user
@route 'profile',
path: '/u/:user?'
waitOn: ->
[Meteor.subscribe('docs', @params.user),
Meteor.subscribe('user',@params.user)]
data: -> userId: @params.user
onBeforeAction: ->
if Meteor.user() and !@params.user
Router.go 'list', user: Meteor.user()._id
Router.go 'profile', user: Meteor.user()._id
action: ->
if !@params.user then @render '404'
else @render()
@route 'delete',
controller: loggedInController
@route 'new'
@route 'signup'
@route 'signin', path: 'login'
@route 'signup',
controller: loggedOutController
@route 'signin',
path: 'login'
controller: loggedOutController
@route '404', path: '*'
notification = new ReactiveVar()
@ -68,6 +80,7 @@ Template.notifications.notification = -> notification.get()
Template.notifications.events
'click .close': -> notify()
Template.layout.notHome = -> Router.current().route.name isnt 'home'
Template.layout.showSpinner = ->
Meteor.status().connected is no or Router.current().ready() is no
Template.home.ndocs = -> docs.find().count()
@ -96,9 +109,19 @@ Template.new.events
else notify type:'success', msg:'Document created successfully'
if id then Router.go 'doc', _id: id
Template.list.documents = ->
console.log docs.find(owner: @userId).fetch()
Template.profile.name = -> Meteor.user().username
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
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.rows = -> ""+@text.split('\n').length
@ -147,3 +170,6 @@ Template.signup.events
password: t.find('#pw').value
}, (err) -> if err then errCallback err
else notify type: 'success', msg: 'check your email'
Template.verify.events
'click #sendmail': -> Meteor.call 'sendVerificationEmail'

View File

@ -22,6 +22,12 @@
margin-top: 1em;
}
// Home
#new, #btns {
margin-top: 1em;
}
// Editor
#title {
@ -45,14 +51,26 @@
margin-top: 1em;
}
// Sign up
// Sign up and Sign in
#signup-container, #signin-container {
#mail { margin-top: 2em; }
#mail { margin-top: 2em; margin-bottom: 1em }
#pw {
margin-top: 1em;
margin-bottom: 1em;
}
.btn {
margin-top: 1em;
}
}
#signup-container {
#pw {
margin-bottom: 1em;
}
}
// Profile
#profile-tools {
margin-top: 1em;
margin-bottom: 1em;
}

View File

@ -8,7 +8,19 @@
<template name="layout">
{{> yield region="outside"}}
<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>
{{> notifications}}
{{> yield}}
@ -16,14 +28,41 @@
</template>
<template name="home">
{{#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>
<p>This demo was built by <a href="http://github.com/fazo96">Enrico
Fasoli (fazo96)</a> in 45 minutes, it's now evolving to a full app.</p>
<p>It's open source, you can find the code
<a href="http://github.com/fazo96/markcloud">here</a></p>
{{#markdown}}
### Share your markdown easily
Markcloud is a simple application that lets you share your markdown documents
to the world. Just paste your markdown and get a _permanent link_ that lets you
and everyone else view the result in a **modern responsive web page**.
### 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 name="new">
@ -66,32 +105,32 @@
{{#unless currentUser}}
<p><a href="/login">Log in</a> to edit and delete your documents<br></p>
{{/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">
{{#if currentUser}}{{#if owned}}
<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>
{{#if owned}}
<p>This document is <a href="/u">yours</a>.</p>
{{else}}
<button id="src-doc" class="btn btn-success">
<i class="fa fa-code"></i> View Source</button>
{{#unless owner}}
<p>This anonymous document will <b>expire {{expirationDays}}</b></p>
{{/unless}}
{{/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>
<div class="btn-group" id="tools">
{{#if currentUser}}{{#if owned}}
<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}}
<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>
</div>
</template>
@ -128,7 +167,7 @@
<template name="signup">
<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>
<input type="text" class="form-control" id="mail" placeholder="E-Mail Address">
<input type="text" class="form-control" id="name" placeholder="Username">
@ -142,7 +181,7 @@
<template name="signin">
<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="password" class="form-control" placeholder="Password" id="pw">
<button class="btn btn-primary" id="signin">Sign In</button>
@ -151,10 +190,48 @@
</div>
</template>
<template name="list">
<ul class="list-group">
{{#each documents}}
<a class="list-group-item" href="/d/{{_id}}">{{title}}</a>
{{/each}}
</ul>
<template name="profile">
{{#if isMe}}
<div class="text-center">
<p>Hello {{name}} ({{mail}}). This is your profile.</p>
</div>
{{/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>

View File

@ -22,10 +22,8 @@ Meteor.publish 'doc', (id) -> docs.find {_id: id}, limit: 1
Meteor.publish 'docs', (userId) ->
if userId? then docs.find {owner: userId}, fields: text: 0
else docs.find {}, fields: text: 0
Meteor.publish 'user', ->
if @userId
Meteor.users.find {_id: @userId}, fields: {dateCreated: 1}
else @ready()
Meteor.publish 'user', (id) ->
Meteor.users.find {_id: id}, fields: {username: 1}
docs.allow
insert: (uid,doc) ->
@ -45,4 +43,10 @@ docs.allow
remove: (uid,doc) -> doc.owner is uid
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