Socialize profiles

Hey @copleykj,

I saw your socialize meteor packages and I definitely want to start using them and contribute. Any chance you can get my started on using the socialize-profiles package?

2 Likes

Sure, so right now the profile package is basically just a starting point for you to build on. The Idea is to get away from the profile key on the user document as it’s easy to leave a large security hole in your app.

To get started you can append to the schema in a shared space file.

Profile.appendSchema({
    firstName:{
        type: String,
        max: 20,
        optional: true
    },
    lastName:{
        type: String,
        max: 25,
        optional: true
    }
});

And then you can add methods to the model like so

Profile.methods({
    fullName: function(){
        return this.firstName +" "+this.lastName;
    }
});

As a note, you may need to run a package update as I just added the .methods() function to the BaseModel object in a release about 30 minutes ago.

4 Likes

So this all makes sense to me. What I don’t understand: Your package automatically includes, when installed, the creation of the users profile?

I’m new to Meteor, so bare with me :smiley:

All of the examples I’ve done so far, it’s all about creating a “post” or submitting an “article” which all can be created multiple times by the user. This is the first thing in meteor that I’ve had to deal with an object that is NOT created by the user, only one profile can exist per user, but they have control over the customization.

Yes, a new profile record is created on behalf of the user when a new user record is inserted. You can then customize the schema and create a way for the user to update their profile. This makes sense to me, but if there is enough feedback that this is any issue for others I can remove the automatic profile creation.

2 Likes

How would profile picture, I guess images work? Are they of type string and I just need to figure out the code to upload the photo?

I’m working on more packages, one of which would handle this situation, but until then my personal preference is to use cloudinary to upload the image and then store the ID returned from cloudinary and use their API via URL to request the image in the size I need with any adjustments already made to it. This is likely what the package I create will do as well.

1 Like

I know this is how you would link to a post:

Router.route('/posts/:_id', { name: 'postPage' });

How do I access the path for the users profile?

This is what I have so far

Router.route('/:_id.profile.userName', { name: 'profile' });
I want to make the url be the user’s userName.

This should get you started…

Router.route('/:username', {
    name: 'profile',
    data: function() {
        return Meteor.profiles.findOne({username:this.params.username);
    },
    subscriptions: function() {
        return Meteor.subscribe("profileFor", this.params.username);
    }
});

Ug, I think I’m in too deep with what I want to make. This doesn’t seem to be working. :frowning:

I’ve done two Meteor tutorial books, Discover Meteor and My First Meteor Application. Both were a bit of a challenge to complete, with not a complete understanding of everything that I coded following along. I may not be ready to be using your awesome package yet.

Which part are you having trouble with?

Well I have a lot of the concepts scrambled up in my brain. Routing, templates, and helpers are what I feel good about. But I’m not quite sure what I’m missing. I keep Googling tons of different tutorials and try to mesh the tutorial code with my own project, but that just makes things worst because everyone has a different way on how they structure the files on their app.

Well if you have a code repo I can clone and you can point me to specific parts you are having trouble with, I can help. For now though I’m off to sleep. I’ll be back around in about 9 hours

Okay I think I’m getting somewhere.

I believe I implemented all the code properly, but now I’m getting an error the the command line :frowning:

 I20150612-21:58:30.227(-7)? Exception while invoking method 'ATCreateUserServer' TypeError: Cannot read property 'username' of null
I20150612-21:58:30.228(-7)?     at Object.Profile.appendSchema.username.autoValue (packages/socialize:user-profile/common/profile-model.js:28:1) 

Does that have to do with your package?

Okay. When I restart the data, make a new account, the app gives me that error. When I restart the server I can log in with the account I just created. But no profiles are created.

Meteor.profiles.find().count();
0

I need to subscribe to the profiles correct?

Ok, should be fixed now.

From an API design point of view, I’d suggest using a route more like:

Router.route('/profile/:username'...)

Otherwise, if you have a user with a username that is a key in your API space, you’ll have issues. For example, if someone has the username ‘home’, or ‘post’, your routes are suddenly ambiguous.

Hi. I have standard meteor app with installed accounts-ui accounts-password accounts-google and socialize:user-profile

In my main.js I added

Profile.appendSchema({ "firstName":{ type:String, required: true }, "lastName":{ type:String, required: true } })

now when register a user in my mondodb I have profiles collection but without firstName and lastName fields… what should I do to get them?

Hello Kelly Copley, is there a tutorial on your profile package? I would love to take an online course or something about it.

2 Likes

A video going thru it would be really nice :slight_smile:

There currently is not, but I’ve recently been acquiring the equipment necessary to do this, and there’s chance that it could be coming with content I’m looking to create as part of my Meteor Ambassadorship. Kids go back to school in couple of weeks so stay tuned.