1
0
mirror of https://github.com/fazo96/homework.git synced 2025-01-09 12:10:08 +01:00

added twitter auth and new alerts

This commit is contained in:
Enrico Fasoli 2014-10-09 16:46:23 +02:00
parent 0b22888902
commit 5a0bc44182
9 changed files with 68 additions and 59 deletions

View File

@ -11,4 +11,7 @@ accounts-password
iron:router iron:router
mrt:moment mrt:moment
mizzao:bootstrap-3 mizzao:bootstrap-3
spiderable
kevohagan:sweetalert
accounts-twitter

View File

@ -1,5 +1,7 @@
accounts-base@1.1.1 accounts-base@1.1.1
accounts-oauth@1.1.1
accounts-password@1.0.2 accounts-password@1.0.2
accounts-twitter@1.0.1
application-configuration@1.0.2 application-configuration@1.0.2
autoupdate@1.1.1 autoupdate@1.1.1
base64@1.0.0 base64@1.0.0
@ -29,6 +31,7 @@ iron:layout@0.4.1
iron:router@0.9.4 iron:router@0.9.4
jquery@1.0.0 jquery@1.0.0
json@1.0.0 json@1.0.0
kevohagan:sweetalert@0.0.1
livedata@1.0.10 livedata@1.0.10
localstorage@1.0.0 localstorage@1.0.0
logging@1.0.3 logging@1.0.3
@ -42,6 +45,8 @@ mongo@1.0.6
mrt:moment@2.8.1 mrt:moment@2.8.1
natestrauser:font-awesome@4.2.0 natestrauser:font-awesome@4.2.0
npm-bcrypt@0.7.7 npm-bcrypt@0.7.7
oauth1@1.1.0
oauth@1.1.0
observe-sequence@1.0.2 observe-sequence@1.0.2
ordered-dict@1.0.0 ordered-dict@1.0.0
random@1.0.0 random@1.0.0
@ -55,10 +60,12 @@ session@1.0.2
sha@1.0.0 sha@1.0.0
spacebars-compiler@1.0.2 spacebars-compiler@1.0.2
spacebars@1.0.2 spacebars@1.0.2
spiderable@1.0.3
srp@1.0.0 srp@1.0.0
standard-app-packages@1.0.2 standard-app-packages@1.0.2
templating@1.0.7 templating@1.0.7
tracker@1.0.2 tracker@1.0.2
twitter@1.1.0
ui@1.0.3 ui@1.0.3
underscore@1.0.0 underscore@1.0.0
url@1.0.0 url@1.0.0

View File

@ -24,6 +24,19 @@ In the mails sent by Homework, the website links point to the `ROOT_URL`
environment variable as environment variable as
[explained on the Meteor docs](http://docs.meteor.com/#meteor_absoluteurl). [explained on the Meteor docs](http://docs.meteor.com/#meteor_absoluteurl).
#### 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'
```
### License ### License
The MIT License (MIT) The MIT License (MIT)

View File

@ -1,5 +1,5 @@
# Homework - Client Side # Homework - Client Side
version = "1.1.4" version = "1.1.5"
# Utilities # Utilities
tick = new Deps.Dependency() tick = new Deps.Dependency()
Meteor.setInterval (-> tick.changed();), 15000 Meteor.setInterval (-> tick.changed();), 15000
@ -8,9 +8,17 @@ notes = new Meteor.Collection "notes"
userSub = Meteor.subscribe 'user' userSub = Meteor.subscribe 'user'
getUser = -> Meteor.user() getUser = -> Meteor.user()
deleteAccount = -> deleteAccount = ->
Meteor.call 'deleteMe', (r) -> if r is yes then Router.go 'home' swal {
title: 'Are you sure?'
text: 'Do you want to permanently delete all your data?'
type: 'warning'
showCancelButton: yes
confirmButtonColor: "#DD6B55"
confirmButtonText: "Yes!"
}, -> Meteor.call 'deleteMe', (r) -> if r is yes then Router.go 'home'
amIValid = -> amIValid = ->
return no unless getUser() return no unless getUser()
return yes if getUser().username
return yes for mail in getUser().emails when mail.verified is yes; no return yes for mail in getUser().emails when mail.verified is yes; no
# Common Helpers for the Templates # Common Helpers for the Templates
@ -18,7 +26,9 @@ UI.registerHelper "version", -> version
UI.registerHelper "status", -> Meteor.status() UI.registerHelper "status", -> Meteor.status()
UI.registerHelper "loading", -> Meteor.loggingIn() or !Meteor.status().connected UI.registerHelper "loading", -> Meteor.loggingIn() or !Meteor.status().connected
UI.registerHelper "email", -> UI.registerHelper "email", ->
if getUser() then return getUser().emails[0].address if getUser()
if getUser().username then return getUser().username
else return getUser().emails[0].address
UI.registerHelper "verified", -> amIValid() UI.registerHelper "verified", -> amIValid()
Meteor.startup -> Meteor.startup ->
@ -115,13 +125,18 @@ Router.map ->
# Some utility callbacks # Some utility callbacks
logoutCallback = (err) -> logoutCallback = (err) ->
if err then errCallback err if err then errCallback err else Router.go 'home'
else Router.go 'home'; Meteor.unsubscribe "my-notes"
errCallback = (err) -> errCallback = (err) ->
if err.reason if err.reason
showError msg: err.reason showError msg: err.reason
else showErrror msg: err else showErrror msg: err
Template.homepage.events
'click #twitter': -> Meteor.loginWithTwitter (e) ->
if e? then errCallback e
else
Router.go 'notes'
swal 'Ok', 'Logged In', 'success'
Template.reconnect.time = -> Template.reconnect.time = ->
tick.depend() tick.depend()
if Meteor.status().retryTime if Meteor.status().retryTime
@ -134,7 +149,7 @@ Template.menu.events
'click .go-archive': -> Router.go 'archive' 'click .go-archive': -> Router.go 'archive'
# Account Page # Account Page
Template.account.dateformat = -> getUser().dateformat Template.account.dateformat = -> if getUser() then return getUser().dateformat
Template.account.events Template.account.events
'click #reset-settings': (e,t) -> 'click #reset-settings': (e,t) ->
t.find('#set-date-format').value = "MM/DD/YYYY" t.find('#set-date-format').value = "MM/DD/YYYY"
@ -211,34 +226,14 @@ Template.editor.events
t.find('.date').value = moment().add(1,'days').format(getUser().dateformat) t.find('.date').value = moment().add(1,'days').format(getUser().dateformat)
'keypress .title': (e,t) -> saveCurrentNote t, e 'keypress .title': (e,t) -> saveCurrentNote t, e
# Notifications (not used yet)
alerts = []
alertDep = new Deps.Dependency
# Show a notification
notify = (data) ->
alerts.push
title: data.title
msg: data.msg
type: data.type or "danger"
alertDep.changed()
# Clear all notifications
clearNotifications = -> alerts.clear(); alertDep.changed()
# Get all the notifications
Template.notifications.notification = -> alertDep.depend(); alerts
Template.notifications.events
'click .close-notification': (e,template) ->
alerts.splice alerts.indexOf(this), 1
alertDep.changed()
# "Error" visualization template # "Error" visualization template
errorDep = new Deps.Dependency; shownError = undefined
showError = (err) -> showError = (err) ->
if err? return unless err?
shownError = err; shownError.type = err.type or "danger" type = err.type or 'error'
else shownError = undefined if !err.title?
errorDep.changed() title = if type is 'error' then 'Error' else 'Ok'
Template.error.error = -> errorDep.depend(); shownError else title = err.title
Template.error.events 'click .close': -> showError() swal title, err.msg, type
# Verify Email page # Verify Email page
Template.verifyEmail.token = -> Router.current().params.token Template.verifyEmail.token = -> Router.current().params.token

View File

@ -5,6 +5,10 @@ input {
max-width: 400px; max-width: 400px;
} }
#twitter {
margin-bottom: 1em;
}
.page-header { .page-header {
text-align: center; text-align: center;
} }

View File

@ -17,8 +17,8 @@
</template> </template>
<!-- /notes and /archive --> <!-- /notes and /archive -->
<template name="notes">{{> error }} {{> editor }} {{> notelist }} {{> menu}}</template> <template name="notes">{{> editor }} {{> notelist }} {{> menu}}</template>
<template name="archive">{{> error}} {{> archivedlist }} {{> menu }}</template> <template name="archive"> {{> archivedlist }} {{> menu }}</template>
<!-- Note Adder --> <!-- Note Adder -->
<template name="noteadder"> <template name="noteadder">
@ -104,7 +104,6 @@
<template name="login"> <template name="login">
<div align="center"> <div align="center">
<h3 class="cool-header"><i class="fa fa-sign-in fa-2x"></i><br>Sign In</h3> <h3 class="cool-header"><i class="fa fa-sign-in fa-2x"></i><br>Sign In</h3>
{{> error}}
{{#if loading}} {{#if loading}}
{{> loading}} {{> loading}}
{{else}} {{else}}
@ -130,7 +129,6 @@
{{> loading}} {{> loading}}
{{else}} {{else}}
<p>Password must be at least 8 characters. You will need to confirm your email.</p> <p>Password must be at least 8 characters. You will need to confirm your email.</p>
{{> error}}
<input type="text" id="r-mail" class="form-control register in-bt" placeholder="Email"> <input type="text" id="r-mail" class="form-control register in-bt" placeholder="Email">
<input type="password" id="r-pass" class="form-control register in-bt" placeholder="Password"> <input type="password" id="r-pass" class="form-control register in-bt" placeholder="Password">
<input type="password" id="r-pass-2" class="form-control register pass-rep in-bt" placeholder="Repeat Password"> <input type="password" id="r-pass-2" class="form-control register pass-rep in-bt" placeholder="Repeat Password">
@ -146,7 +144,6 @@
<template name="account"> <template name="account">
<div align="center"> <div align="center">
<h3 class="cool-header"><i class="fa fa-user fa-2x"></i><br>{{email}}</h3> <h3 class="cool-header"><i class="fa fa-user fa-2x"></i><br>{{email}}</h3>
{{> error}}
<p class="lead">Settings</p> <p class="lead">Settings</p>
<p>You can choose the format used to write and read dates in the note list</p> <p>You can choose the format used to write and read dates in the note list</p>
<input type="text" class="form-control" id="set-date-format" placeholder="Date Format" value="{{dateformat}}"> <input type="text" class="form-control" id="set-date-format" placeholder="Date Format" value="{{dateformat}}">
@ -174,7 +171,6 @@
<h3 class="cool-header"><i class="fa fa-envelope fa-2x"></i><br> <h3 class="cool-header"><i class="fa fa-envelope fa-2x"></i><br>
Please verify your Email Address<br><small>{{email}}</small></h3> Please verify your Email Address<br><small>{{email}}</small></h3>
<p>Click the link inside the email we sent you or paste it here:</p> <p>Click the link inside the email we sent you or paste it here:</p>
{{> error}}
<input type="text" id="token-field" class="form-control" placeholder="Token" value="{{token}}"> <input type="text" id="token-field" class="form-control" placeholder="Token" value="{{token}}">
<div align="center" class="btn-group"> <div align="center" class="btn-group">
<button type="button" class="btn btn-warning btn-ver" id="btn-resend"> <button type="button" class="btn btn-warning btn-ver" id="btn-resend">
@ -189,26 +185,6 @@
</div> </div>
</template> </template>
<!-- Notification list. It doesn't show anything unless there are notifications -->
<template name="notifications">
{{#each notification}}
<div class="alert alert-{{type}} notification">
<p align="center">{{msg}}</p>
<button type="button" class="close close-notification">&times;</button>
</div>
{{/each}}
</template>
<!-- Shows an Error if there is one. It's dismissable -->
<template name="error">
{{#if error}}
<div align="center"><div class="alert alert-{{error.type}} error">
<p align="center">{{error.msg}}</p>
<button type="button" class="close close-error">&times;</button>
</div></div>
{{/if}}
</template>
<!-- Shows the "fork me on github" ribbon --> <!-- Shows the "fork me on github" ribbon -->
<template name="ribbon"> <template name="ribbon">
<div class="github-fork-ribbon-wrapper right"> <div class="github-fork-ribbon-wrapper right">
@ -282,6 +258,9 @@
</div> </div>
{{#unless loading}} {{#unless loading}}
<div align="center" style="margin-top:20px;"> <div align="center" style="margin-top:20px;">
<a id="twitter" class="btn btn-primary">
<i class="fa fa-twitter"></i> Log In with Twitter
</a><br>
<a href="{{pathFor 'login'}}" role="button" class="btn btn-primary"> <a href="{{pathFor 'login'}}" role="button" class="btn btn-primary">
<i class="fa fa-sign-in"></i> Sign In <i class="fa fa-sign-in"></i> Sign In
</a> </a>

1
server/.gitignore vendored Normal file
View File

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

View File

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

View File

@ -13,9 +13,11 @@ isUsers = (u,doc) -> u and doc.userId is u
# Returns true if the user has verified at least one email address # Returns true if the user has verified at least one email address
userValidated = (user) -> userValidated = (user) ->
return no unless user? return no unless user?
return yes if user.services.twitter
return yes for mail in user.emails when mail.verified is yes; no return yes for mail in user.emails when mail.verified is yes; no
Meteor.publish 'user', -> Meteor.users.find @userId, fields: dateformat: 1 Meteor.publish 'user', ->
Meteor.users.find @userId, fields: {dateformat: 1, username: 1}
# Publish user's notes to each user. # Publish user's notes to each user.
Meteor.publish "my-notes", -> Meteor.publish "my-notes", ->
if userValidated getUser(@userId) if userValidated getUser(@userId)
@ -26,6 +28,8 @@ Meteor.publish "archive", ->
# Custom new account default settings # Custom new account default settings
Accounts.onCreateUser (options, user) -> Accounts.onCreateUser (options, user) ->
console.log options
console.log user
user.dateformat = options.dateformat or "MM/DD/YYYY" user.dateformat = options.dateformat or "MM/DD/YYYY"
return user return user