UserSchema: set default profile.name (either from facebook or username)

if not provided. This way we can remove the expensive username() helper
function throughout our html
This commit is contained in:
Tyler Renelle
2013-10-27 17:46:21 -07:00
parent a078889d58
commit 44d67ac9f8

View File

@@ -265,7 +265,16 @@ UserSchema.virtual('tasks').get(function () {
// Custom setter/getter virtuals?
UserSchema.pre('save', function(next) {
//this.markModified('tasks'); //FIXME
//this.markModified('tasks');
if (!this.profile.name) {
var fb = this.auth.facebook;
this.profile.name =
(this.auth.local && this.auth.local.username) ||
(fb && (fb.displayName || fb.name || fb.username || (fb.first_name && fb.first_name + ' ' + fb.last_name))) ||
'Anonymous';
}
//our own version incrementer
this._v++;
next();