mirror of
https://github.com/fazo96/homework.git
synced 2025-01-10 12:14:22 +01:00
added twitter auth and new alerts
This commit is contained in:
parent
0b22888902
commit
5a0bc44182
@ -11,4 +11,7 @@ accounts-password
|
||||
iron:router
|
||||
mrt:moment
|
||||
mizzao:bootstrap-3
|
||||
spiderable
|
||||
kevohagan:sweetalert
|
||||
accounts-twitter
|
||||
|
||||
|
@ -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
|
||||
@ -29,6 +31,7 @@ iron:layout@0.4.1
|
||||
iron:router@0.9.4
|
||||
jquery@1.0.0
|
||||
json@1.0.0
|
||||
kevohagan:sweetalert@0.0.1
|
||||
livedata@1.0.10
|
||||
localstorage@1.0.0
|
||||
logging@1.0.3
|
||||
@ -42,6 +45,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
|
||||
random@1.0.0
|
||||
@ -55,10 +60,12 @@ session@1.0.2
|
||||
sha@1.0.0
|
||||
spacebars-compiler@1.0.2
|
||||
spacebars@1.0.2
|
||||
spiderable@1.0.3
|
||||
srp@1.0.0
|
||||
standard-app-packages@1.0.2
|
||||
templating@1.0.7
|
||||
tracker@1.0.2
|
||||
twitter@1.1.0
|
||||
ui@1.0.3
|
||||
underscore@1.0.0
|
||||
url@1.0.0
|
||||
|
13
README.md
13
README.md
@ -24,6 +24,19 @@ In the mails sent by Homework, the website links point to the `ROOT_URL`
|
||||
environment variable as
|
||||
[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
|
||||
The MIT License (MIT)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Homework - Client Side
|
||||
version = "1.1.4"
|
||||
version = "1.1.5"
|
||||
# Utilities
|
||||
tick = new Deps.Dependency()
|
||||
Meteor.setInterval (-> tick.changed();), 15000
|
||||
@ -8,9 +8,17 @@ notes = new Meteor.Collection "notes"
|
||||
userSub = Meteor.subscribe 'user'
|
||||
getUser = -> Meteor.user()
|
||||
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 = ->
|
||||
return no unless getUser()
|
||||
return yes if getUser().username
|
||||
return yes for mail in getUser().emails when mail.verified is yes; no
|
||||
|
||||
# Common Helpers for the Templates
|
||||
@ -18,7 +26,9 @@ UI.registerHelper "version", -> version
|
||||
UI.registerHelper "status", -> Meteor.status()
|
||||
UI.registerHelper "loading", -> Meteor.loggingIn() or !Meteor.status().connected
|
||||
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()
|
||||
|
||||
Meteor.startup ->
|
||||
@ -115,13 +125,18 @@ Router.map ->
|
||||
|
||||
# Some utility callbacks
|
||||
logoutCallback = (err) ->
|
||||
if err then errCallback err
|
||||
else Router.go 'home'; Meteor.unsubscribe "my-notes"
|
||||
if err then errCallback err else Router.go 'home'
|
||||
errCallback = (err) ->
|
||||
if err.reason
|
||||
showError msg: err.reason
|
||||
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 = ->
|
||||
tick.depend()
|
||||
if Meteor.status().retryTime
|
||||
@ -134,7 +149,7 @@ Template.menu.events
|
||||
'click .go-archive': -> Router.go 'archive'
|
||||
|
||||
# Account Page
|
||||
Template.account.dateformat = -> getUser().dateformat
|
||||
Template.account.dateformat = -> if getUser() then return getUser().dateformat
|
||||
Template.account.events
|
||||
'click #reset-settings': (e,t) ->
|
||||
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)
|
||||
'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
|
||||
errorDep = new Deps.Dependency; shownError = undefined
|
||||
showError = (err) ->
|
||||
if err?
|
||||
shownError = err; shownError.type = err.type or "danger"
|
||||
else shownError = undefined
|
||||
errorDep.changed()
|
||||
Template.error.error = -> errorDep.depend(); shownError
|
||||
Template.error.events 'click .close': -> showError()
|
||||
return unless err?
|
||||
type = err.type or 'error'
|
||||
if !err.title?
|
||||
title = if type is 'error' then 'Error' else 'Ok'
|
||||
else title = err.title
|
||||
swal title, err.msg, type
|
||||
|
||||
# Verify Email page
|
||||
Template.verifyEmail.token = -> Router.current().params.token
|
||||
|
@ -5,6 +5,10 @@ input {
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
#twitter {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
text-align: center;
|
||||
}
|
||||
|
@ -17,8 +17,8 @@
|
||||
</template>
|
||||
|
||||
<!-- /notes and /archive -->
|
||||
<template name="notes">{{> error }} {{> editor }} {{> notelist }} {{> menu}}</template>
|
||||
<template name="archive">{{> error}} {{> archivedlist }} {{> menu }}</template>
|
||||
<template name="notes">{{> editor }} {{> notelist }} {{> menu}}</template>
|
||||
<template name="archive"> {{> archivedlist }} {{> menu }}</template>
|
||||
|
||||
<!-- Note Adder -->
|
||||
<template name="noteadder">
|
||||
@ -104,7 +104,6 @@
|
||||
<template name="login">
|
||||
<div align="center">
|
||||
<h3 class="cool-header"><i class="fa fa-sign-in fa-2x"></i><br>Sign In</h3>
|
||||
{{> error}}
|
||||
{{#if loading}}
|
||||
{{> loading}}
|
||||
{{else}}
|
||||
@ -130,7 +129,6 @@
|
||||
{{> loading}}
|
||||
{{else}}
|
||||
<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="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">
|
||||
@ -146,7 +144,6 @@
|
||||
<template name="account">
|
||||
<div align="center">
|
||||
<h3 class="cool-header"><i class="fa fa-user fa-2x"></i><br>{{email}}</h3>
|
||||
{{> error}}
|
||||
<p class="lead">Settings</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}}">
|
||||
@ -174,7 +171,6 @@
|
||||
<h3 class="cool-header"><i class="fa fa-envelope fa-2x"></i><br>
|
||||
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>
|
||||
{{> error}}
|
||||
<input type="text" id="token-field" class="form-control" placeholder="Token" value="{{token}}">
|
||||
<div align="center" class="btn-group">
|
||||
<button type="button" class="btn btn-warning btn-ver" id="btn-resend">
|
||||
@ -189,26 +185,6 @@
|
||||
</div>
|
||||
</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">×</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">×</button>
|
||||
</div></div>
|
||||
{{/if}}
|
||||
</template>
|
||||
|
||||
<!-- Shows the "fork me on github" ribbon -->
|
||||
<template name="ribbon">
|
||||
<div class="github-fork-ribbon-wrapper right">
|
||||
@ -282,6 +258,9 @@
|
||||
</div>
|
||||
{{#unless loading}}
|
||||
<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">
|
||||
<i class="fa fa-sign-in"></i> Sign In
|
||||
</a>
|
||||
|
1
server/.gitignore
vendored
Normal file
1
server/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
settings.coffee
|
@ -12,6 +12,9 @@ Accounts.config {
|
||||
|
||||
# Code that checks if a new user request is valid
|
||||
Accounts.validateNewUser (user) ->
|
||||
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"
|
||||
|
@ -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
|
||||
userValidated = (user) ->
|
||||
return no unless user?
|
||||
return yes if user.services.twitter
|
||||
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.
|
||||
Meteor.publish "my-notes", ->
|
||||
if userValidated getUser(@userId)
|
||||
@ -26,6 +28,8 @@ Meteor.publish "archive", ->
|
||||
|
||||
# Custom new account default settings
|
||||
Accounts.onCreateUser (options, user) ->
|
||||
console.log options
|
||||
console.log user
|
||||
user.dateformat = options.dateformat or "MM/DD/YYYY"
|
||||
return user
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user