1
0
mirror of https://github.com/fazo96/markcloud.git synced 2025-01-24 13:14:21 +01:00

added twitter auth

This commit is contained in:
Enrico Fasoli 2014-10-08 21:38:32 +02:00
parent f276c97deb
commit ce757fedbf
9 changed files with 57 additions and 13 deletions

View File

@ -14,4 +14,5 @@ accounts-password
mrt:moment
reactive-var
kevohagan:sweetalert
accounts-twitter

View File

@ -1,5 +1,7 @@
accounts-base@1.1.1
accounts-oauth@1.1.1
accounts-password@1.0.2
accounts-twitter@1.0.1
application-configuration@1.0.2
autoupdate@1.1.1
base64@1.0.0
@ -44,6 +46,8 @@ mongo@1.0.6
mrt:moment@2.8.1
natestrauser:font-awesome@4.2.0
npm-bcrypt@0.7.7
oauth1@1.1.0
oauth@1.1.0
observe-sequence@1.0.2
ordered-dict@1.0.0
perak:markdown@1.0.4
@ -61,6 +65,7 @@ spacebars@1.0.2
srp@1.0.0
templating@1.0.7
tracker@1.0.2
twitter@1.1.0
ui@1.0.3
underscore@1.0.0
url@1.0.0

View File

@ -14,6 +14,22 @@ If you want to set up a server, make sure to configure the `MAIL_URL`
and `ROOT_URL` environment variables as explained in the
[Meteor Docs](http://docs.meteor.com).
#### Twitter Authentication
Create this file: `server/settings.coffee` with this content:
```coffeescript
Meteor.startup ->
Accounts.loginServiceConfiguration.remove service : 'twitter'
Accounts.loginServiceConfiguration.insert
service: 'twitter'
consumerKey: 'Your API key'
secret: 'Your API secret'
```
Your users will now be able to login using twitter. You may want to disable the
button if you don't configure twitter authentication.
## License
The MIT License (MIT)

View File

@ -2,9 +2,11 @@ docs = new Meteor.Collection 'docs'
amIValid = ->
return no unless Meteor.user()
return yes if !Meteor.user().emails?
return yes for mail in Meteor.user().emails when mail.verified is yes; no
UI.registerHelper 'mail', -> Meteor.user().emails[0].address
UI.registerHelper 'mail', ->
if Meter.user().emails then Meteor.user().emails[0].address
UI.registerHelper 'amIValid', amIValid
Router.configure
@ -17,7 +19,6 @@ docController = RouteController.extend
waitOn: -> Meteor.subscribe 'doc', @params._id
data: -> docs.findOne @params._id
action: ->
console.log @render
if @ready()
if @data()? then @render()
else @render '404'
@ -85,14 +86,20 @@ share.notify = notify = (opt) ->
errCallback = (err) ->
return unless err
console.log err
if err.reason
notify title: err.code or 'Error', msg: err.reason, type: 'error'
else notify title: 'Error', msg: err, type: 'error'
Template.layout.notHome = -> Router.current().route.name isnt 'home'
Template.layout.showSpinner = ->
Meteor.status().connected is no or Router.current().ready() is no
Template.layout.showSpinner = -> Meteor.status().connected is yes
Template.home.events
'click #twitter-login': ->
if Meteor.user() then return notify msg: "You're already Logged In!"
Meteor.loginWithTwitter {}, (e) ->
if e then errCallback e
else
Meteor.subscribe 'user'
notify type: 'success', msg: 'Logged in'
Template.editor.isPublic = -> return "checked" if @public is yes
Template.editor.showTitleChecked = -> return "checked" unless @showTitle is no
Template.editor.events

View File

@ -74,6 +74,9 @@
#profile-tools {
margin-top: 1em;
margin-bottom: 1em;
a {
margin-bottom: 1em;
}
}
.label {

View File

@ -50,9 +50,7 @@
{{#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**.
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
@ -77,10 +75,14 @@ This home page is written in markdown too!
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" id="twitter-login">
<i class="fa fa-twitter"></i> Log In With Twitter</a>
<br>or<br>
<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>
@ -187,7 +189,11 @@ You will be able to delete your account and all your data whenever you want.
<template name="profile">
{{#if isMe}}
<div class="text-center">
<p>Hello <b>{{username}}</b> ({{mail}}). This is your profile.</p>
{{#if mail}}
<p>Hello <b>{{username}}</b> ({{mail}}). This is your profile.</p>
{{else}}
<p>Hello <b>{{profile.name}}</b> (@{{username}}). This is your profile.</p>
{{/if}}
{{#if noDocs}}
<p>You don't have any documents yet.</p>
{{/if}}
@ -210,9 +216,9 @@ You will be able to delete your account and all your data whenever you want.
{{else}}
<div class="text-center">
{{#if noDocs}}
<p>{{username}} doesn't have any public documents.</p>
<p>@{{username}} doesn't have any public documents.</p>
{{else}}
<p>These are {{username}}'s public documents.</p>
<p>These are @{{username}}'s public documents.</p>
{{/if}}
</div>
{{/if}}

1
server/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
settings.coffee

View File

@ -13,6 +13,9 @@ Accounts.config {
# Code that checks if a new user request is valid
Accounts.validateNewUser (user) ->
user.dateCreated = moment().unix()
if user.services.twitter?
user.username = user.services.twitter.screenName
return yes
mail = user.emails[0].address
if Match.test(mail,String) is no or validateEmail(mail) is no
throw new Meteor.Error 403, "Invalid Email"

View File

@ -16,6 +16,7 @@ Meteor.startup ->
validatedUser = (uid) ->
u = Meteor.users.findOne uid
return no unless u
return yes if u.services.twitter
return yes for mail in u.emails when mail.verified is yes; no
Meteor.publish 'doc', (id) -> docs.find {_id: id}, limit: 1
@ -26,9 +27,10 @@ Meteor.publish 'docs', (userId) ->
else docs.find {owner: userId, public: yes}, fields: text: 0
else docs.find {}, fields: text: 0
Meteor.publish 'user', (id) ->
id ?= @userId
if @userId is id
Meteor.users.find id, fields: {username: 1, emails: 1}
else Meteor.users.find id, fields: {username: 1}
Meteor.users.find id, fields: { username: 1, emails: 1, profile: 1 }
else Meteor.users.find id, fields: { username : 1, profile: 1 }
docs.allow
insert: (uid,doc) ->