Last active
August 29, 2015 14:20
-
-
Save sunocean-sand/f45770cd563d539b585c to your computer and use it in GitHub Desktop.
trying to show the post creator's name on the list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import Firebase from 'firebase'; | |
function parseAuthData(authData) { | |
var parsedData = {}; | |
switch(authData.provider) { | |
case 'facebook': | |
parsedData.provider = authData.provider; | |
parsedData.id = authData.facebook.id; | |
parsedData.displayName = authData.facebook.displayName; | |
parsedData.gender = authData.facebook.cachedUserProfile.gender; | |
parsedData.language = authData.facebook.cachedUserProfile.locale; | |
parsedData.imageThumbUrl = authData.facebook.cachedUserProfile.picture.data.url; | |
parsedData.website = authData.facebook.cachedUserProfile.link; | |
return parsedData; | |
/* | |
case 'github': | |
parsedData.provider = authData.provider; | |
parsedData.id = authData.github.id; | |
parsedData.username = authData.github.username; | |
parsedData.displayName = authData.github.displayName; | |
parsedData.description = authData.github.cachedUserProfile.bio; | |
parsedData.email = authData.github.email; | |
parsedData.company = authData.github.cachedUserProfile.company; | |
parsedData.location = authData.github.cachedUserProfile.location; | |
parsedData.imageThumbUrl = authData.github.cachedUserProfile.avatar_url; | |
parsedData.website = authData.github.cachedUserProfile.html_url; | |
return parsedData; | |
case 'google': | |
parsedData.provider = authData.provider; | |
parsedData.id = authData.google.id; | |
parsedData.displayName = authData.google.displayName; | |
parsedData.gender = authData.google.cachedUserProfile.gender; | |
parsedData.language = authData.google.cachedUserProfile.locale; | |
parsedData.imageThumbUrl = authData.google.cachedUserProfile.picture; | |
parsedData.website = authData.google.cachedUserProfile.link; | |
return parsedData; | |
*/ | |
case 'twitter': | |
parsedData.provider = authData.provider; | |
parsedData.id = authData.twitter.id; | |
parsedData.username = authData.twitter.username; | |
parsedData.displayName = authData.twitter.displayName; | |
parsedData.description = authData.twitter.cachedUserProfile.description; | |
parsedData.location = authData.twitter.cachedUserProfile.location; | |
parsedData.language = authData.twitter.cachedUserProfile.lang; | |
parsedData.imageThumbUrl = authData.twitter.cachedUserProfile.profile_image_url_https || authData.twitter.cachedUserProfile.profile_image_url; | |
parsedData.website = authData.twitter.cachedUserProfile.url; | |
return parsedData; | |
} | |
} | |
var session = Ember.Object.extend({ | |
ref : new Firebase("https://nutella.firebaseio.com"), | |
addFirebaseCallback: function() { | |
var session = this; | |
var ref = this.get('ref'); | |
ref.onAuth(function(authData) { | |
if (authData) { | |
var user = parseAuthData(authData); | |
session.set("isAuthenticated", true); | |
session.set('uid', authData.uid); | |
session.set('user', user); | |
ref.child('users').child(authData.uid).set(user); | |
} else { | |
session.set("isAuthenticated", false); | |
} | |
}); | |
}.on("init"), | |
loginFacebook: function() { | |
var session = this; | |
return new Ember.RSVP.Promise(function (resolve, reject) { | |
session.get("ref").authWithOAuthPopup("facebook", function(error, user) { | |
if (user) { | |
resolve(user); | |
} else { | |
reject(error); | |
} | |
}, | |
{ | |
remember: "sessionOnly", | |
scope: "email" | |
}); | |
}); | |
}, | |
loginTwitter: function() { | |
var session = this; | |
return new Ember.RSVP.Promise(function(resolve, reject) { | |
session.get('ref').authWithOAuthPopup('twitter', function(error, user) { | |
if (user) { resolve(user); } | |
else { reject(error); } | |
}); | |
}); | |
}, | |
login: function() { | |
return new Ember.RSVP.Promise((resolve, reject) => { | |
this.get('ref').authWithPassword({ | |
email: "", | |
password: "" | |
}, function(error, user) { | |
if (user) { resolve(user); } | |
else { reject(error); } | |
}); | |
}); | |
}, | |
createUser: function() { | |
var session = this; | |
var properties = { | |
name: this.get('name'), | |
email: this.get('email'), | |
password: this.get('password') | |
} | |
this.get('ref').createUser(properties, function(error, user) { | |
if (!error) { | |
console.log('User name: ' + user.name + ', Email: ' + user.email); | |
var userRef = new Firebase(usersPath + '/simplelogin:' + user.id); | |
userRef.set({email: user.email}); // This is where you'd add Display Name, phone #, whatever | |
session.login('password', email, password); | |
} | |
} | |
)}, | |
logout: function() { | |
this.get("ref").unauth(); | |
}, | |
currentUser: Ember.computed('isAuthenticated', function() { | |
return this.get('ref').getAuth(); | |
}) | |
}); | |
export default { | |
name: "Session", | |
initialize: function (container, app) { | |
app.register("session:main", session); | |
app.inject("controller", "session", "session:main"); | |
app.inject("route", "session", "session:main"); | |
} | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//models/list.js | |
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
title: DS.attr('string'), | |
todos: DS.hasMany('todo', {async: true}), | |
user: DS.belongsTo('user', {async: true}) | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model: function() { | |
return this.store.find('list'); | |
}, | |
actions: { | |
createList: function() { | |
var newListTitle = this.controllerFor('lists').get('newListTitle'); | |
var user = this.get('session.user.displayName'); | |
alert(this.get('session.user.displayName')); | |
if (Ember.isBlank(newListTitle)) { return false; } | |
//1 | |
var list = this.store.createRecord('list', { | |
title: newListTitle, | |
user: user, | |
}); | |
console.log(user.get('lists')); | |
//2 | |
this.controllerFor('lists').set('newListTitle', ''); | |
/* | |
this.controllerFor('lists').setProperties({ | |
title: newListTitle, | |
user: username, | |
}); | |
*/ | |
var _this = this; | |
console.log(user.get('lists')); | |
//3 | |
list.save().then(function(list) { | |
user.get('lists').addObject(list); | |
user.save(); | |
//_this.transitionTo('lists.show', list); //4 | |
}); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
displayName: DS.attr('string'), | |
email: DS.attr('string'), | |
list: DS.hasMany('list', {async: true}), | |
todo: DS.hasMany('todo', {async: true}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment