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

updated deps, added facebook support, bumped ver 1.2

This commit is contained in:
Enrico Fasoli 2015-03-02 15:55:29 +01:00
parent 50fff6b5e9
commit 91c9aac89d
10 changed files with 137 additions and 93 deletions

1
.gitignore vendored Normal file
View File

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

View File

@ -16,3 +16,5 @@ kevohagan:sweetalert
accounts-twitter accounts-twitter
fazo96:paginator fazo96:paginator
service-configuration
accounts-facebook

View File

@ -1 +1 @@
METEOR@1.0 METEOR@1.0.3.2

View File

@ -1,79 +1,80 @@
accounts-base@1.1.2 accounts-base@1.1.3
accounts-oauth@1.1.2 accounts-facebook@1.0.3
accounts-password@1.0.4 accounts-oauth@1.1.3
accounts-twitter@1.0.2 accounts-password@1.0.6
application-configuration@1.0.3 accounts-twitter@1.0.3
autoupdate@1.1.3 application-configuration@1.0.4
base64@1.0.1 autoupdate@1.1.5
binary-heap@1.0.1 base64@1.0.2
blaze-tools@1.0.1 binary-heap@1.0.2
blaze@2.0.3 blaze@2.0.4
boilerplate-generator@1.0.1 blaze-tools@1.0.2
callback-hook@1.0.1 boilerplate-generator@1.0.2
check@1.0.2 callback-hook@1.0.2
coffeescript@1.0.4 check@1.0.4
ctl-helper@1.0.4 coffeescript@1.0.5
ctl@1.0.2 ddp@1.0.14
ddp@1.0.11 deps@1.0.6
deps@1.0.5 ejson@1.0.5
ejson@1.0.4 email@1.0.5
email@1.0.4 facebook@1.1.3
fastclick@1.0.1 fastclick@1.0.2
fazo96:paginator@0.1.0 fazo96:paginator@0.1.0
follower-livedata@1.0.2 follower-livedata@1.0.3
geojson-utils@1.0.1 geojson-utils@1.0.2
html-tools@1.0.2 html-tools@1.0.3
htmljs@1.0.2 htmljs@1.0.3
http@1.0.8 http@1.0.10
id-map@1.0.1 id-map@1.0.2
iron:controller@1.0.0 iron:controller@1.0.7
iron:core@1.0.0 iron:core@1.0.7
iron:dynamic-template@1.0.0 iron:dynamic-template@1.0.7
iron:layout@1.0.0 iron:layout@1.0.7
iron:location@1.0.1 iron:location@1.0.7
iron:middleware-stack@1.0.0 iron:middleware-stack@1.0.7
iron:router@1.0.1 iron:router@1.0.7
iron:url@1.0.0 iron:url@1.0.7
jquery@1.0.1 jquery@1.11.3
json@1.0.1 json@1.0.2
kevohagan:sweetalert@0.3.1 kevohagan:sweetalert@0.4.2
launch-screen@1.0.0 launch-screen@1.0.1
livedata@1.0.11 livedata@1.0.12
localstorage@1.0.1 localstorage@1.0.2
logging@1.0.5 logging@1.0.6
meteor-platform@1.2.0 meteor@1.1.4
meteor@1.1.3 meteor-platform@1.2.1
minifiers@1.1.2 minifiers@1.1.3
minimongo@1.0.5 minimongo@1.0.6
mizzao:bootstrap-3@3.3.0 mizzao:bootstrap-3@3.3.1_1
mobile-status-bar@1.0.1 mobile-status-bar@1.0.2
mongo@1.0.8 mongo@1.0.11
mrt:moment@2.8.1 mrt:moment@2.8.1
natestrauser:font-awesome@4.2.0 natestrauser:font-awesome@4.3.0
npm-bcrypt@0.7.7 npm-bcrypt@0.7.7
oauth1@1.1.2 oauth@1.1.3
oauth@1.1.2 oauth1@1.1.3
observe-sequence@1.0.3 oauth2@1.1.2
ordered-dict@1.0.1 observe-sequence@1.0.4
random@1.0.1 ordered-dict@1.0.2
reactive-dict@1.0.4 random@1.0.2
reactive-var@1.0.3 reactive-dict@1.0.5
reload@1.1.1 reactive-var@1.0.4
retry@1.0.1 reload@1.1.2
routepolicy@1.0.2 retry@1.0.2
service-configuration@1.0.2 routepolicy@1.0.4
session@1.0.4 service-configuration@1.0.3
sha@1.0.1 session@1.0.5
spacebars-compiler@1.0.3 sha@1.0.2
spacebars@1.0.3 spacebars@1.0.5
spiderable@1.0.5 spacebars-compiler@1.0.4
srp@1.0.1 spiderable@1.0.6
standard-app-packages@1.0.3 srp@1.0.2
templating@1.0.9 standard-app-packages@1.0.4
tracker@1.0.3 templating@1.0.11
twitter@1.1.2 tracker@1.0.5
ui@1.0.4 twitter@1.1.3
underscore@1.0.1 ui@1.0.5
url@1.0.2 underscore@1.0.2
webapp-hashing@1.0.1 url@1.0.3
webapp@1.1.4 webapp@1.1.6
webapp-hashing@1.0.2

View File

@ -44,7 +44,7 @@ Meteor.startup ->
### License ### License
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2014 Enrico Fasoli Copyright (c) 2014-2015 Enrico Fasoli
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -1,5 +1,5 @@
# Homework - Client Side # Homework - Client Side
version = "1.1.8" version = "1.2"
# Utilities # Utilities
tick = new Tracker.Dependency() tick = new Tracker.Dependency()
Meteor.setInterval (-> tick.changed();), 15000 Meteor.setInterval (-> tick.changed();), 15000
@ -25,6 +25,10 @@ amIValid = ->
UI.registerHelper "version", -> version 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 "facebookAvailable", ->
Accounts.loginServicesConfigured() and ServiceConfiguration.configurations.find(service: "facebook").count() > 0
UI.registerHelper "twitterAvailable", ->
Accounts.loginServicesConfigured() and ServiceConfiguration.configurations.find(service: "twitter").count() > 0
UI.registerHelper "email", -> UI.registerHelper "email", ->
if getUser() if getUser()
if getUser().username then return getUser().username if getUser().username then return getUser().username
@ -62,8 +66,8 @@ loggedInController = RouteController.extend
@render 'loading' @render 'loading'
else @render() else @render()
onBeforeAction: -> onBeforeAction: ->
if not getUser() then Router.go 'home' if not getUser() then Router.redirect 'home'
else if not amIValid() then Router.go 'verifyEmail' else if not amIValid() then Router.redirect 'verifyEmail'
@next() @next()
guestController = RouteController.extend guestController = RouteController.extend
@ -73,7 +77,7 @@ guestController = RouteController.extend
else @render() else @render()
onBeforeAction: -> onBeforeAction: ->
if getUser() if getUser()
if amIValid() is no then Router.go 'verifyEmail' else Router.go 'notes' if amIValid() is no then Router.redirect 'verifyEmail' else Router.redirect 'notes'
@next() @next()
# Page Routing # Page Routing
@ -84,7 +88,7 @@ Router.route '/',
onBeforeAction: -> onBeforeAction: ->
# Dispatch user to the right landing page based on his account status # Dispatch user to the right landing page based on his account status
if getUser() if getUser()
if amIValid() is yes then Router.go 'notes' else Router.go 'verifyEmail' if amIValid() is yes then Router.redirect 'notes' else Router.redirect 'verifyEmail'
@next() @next()
Router.route '/login', controller: guestController Router.route '/login', controller: guestController
Router.route '/register', controller: guestController Router.route '/register', controller: guestController
@ -104,7 +108,8 @@ Router.route '/verify/:token?',
onBeforeAction: -> onBeforeAction: ->
if getUser() if getUser()
if amIValid() if amIValid()
Router.go 'home'; @next() Router.redirect 'home'
@next()
else if @params.token? and @params.token isnt "" else if @params.token? and @params.token isnt ""
# Automatic verification # Automatic verification
@render 'loading' @render 'loading'
@ -116,7 +121,8 @@ Router.route '/verify/:token?',
Router.go 'home' Router.go 'home'
@next() @next()
else else
Router.go 'home'; @next() Router.redirect 'home'
@next()
Router.route '/archive/:_id?', Router.route '/archive/:_id?',
name: 'archive' name: 'archive'
waitOn: -> @notes = Meteor.subscribe 'notes', yes waitOn: -> @notes = Meteor.subscribe 'notes', yes
@ -132,14 +138,18 @@ logoutCallback = (err) ->
errCallback = (err) -> errCallback = (err) ->
if err.reason if err.reason
showError msg: err.reason showError msg: err.reason
else showErrror msg: err else showError msg: err
Template.homepage.events loginCallback = (e) ->
'click #twitter': -> Meteor.loginWithTwitter (e) ->
if e? then errCallback e if e? then errCallback e
else else
Router.go 'notes' Router.go 'notes'
swal 'Ok', 'Logged In', 'success' swal 'Ok', 'Logged In', 'success'
Template.homepage.events
'click #facebook': -> Meteor.loginWithFacebook loginCallback
'click #twitter': -> Meteor.loginWithTwitter loginCallback
Template.reconnect.helpers Template.reconnect.helpers
time : -> time : ->
tick.depend() tick.depend()

View File

@ -5,7 +5,7 @@ input {
max-width: 400px; max-width: 400px;
} }
#twitter { #twitter, #facebook {
margin-bottom: 1em; margin-bottom: 1em;
} }

View File

@ -272,9 +272,16 @@
</div> </div>
{{#unless loading}} {{#unless loading}}
<div align="center" style="margin-top:20px;"> <div align="center" style="margin-top:20px;">
{{#if twitterAvailable}}
<a id="twitter" class="btn btn-primary"> <a id="twitter" class="btn btn-primary">
<i class="fa fa-twitter"></i> Log In with Twitter <i class="fa fa-twitter"></i> Log In with Twitter
</a><br> </a><br>
{{/if}}
{{#if facebookAvailable}}
<a id="facebook" class="btn btn-primary">
<i class="fa fa-facebook"></i> Log In with Facebook
</a><br>
{{/if}}
<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>

View File

@ -10,11 +10,34 @@ Accounts.config {
loginExpirationInDays: 30 loginExpirationInDays: 30
} }
# Login via external services
if Meteor.settings.facebook
ServiceConfiguration.configurations.upsert { service: "facebook" }, $set: {
service: "facebook"
appId: Meteor.settings.facebook.appId
#loginStyle: "popup"
secret: Meteor.settings.facebook.secret
}
else ServiceConfiguration.configurations.remove { service: "facebook" }
if Meteor.settings.twitter
ServiceConfiguration.configurations.upsert { service: "twitter" }, $set: {
service: "twitter"
consumerKey: Meteor.settings.twitter.consumerKey
#loginStyle: "popup"
secret: Meteor.settings.twitter.secret
}
else ServiceConfiguration.configurations.remove { service: "twitter" }
# 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? if user.services.twitter?
user.username = user.services.twitter.screenName user.username = user.services.twitter.screenName
return yes return yes
if user.services.facebook?
user.username = user.services.facebook.name
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,7 +13,7 @@ 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 if user.services.twitter or user.services.facebook
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.publish 'user', ->