EllisLab text mark
Advanced Search
     
API - Create New Entry for non-logged in user?
Posted: 16 July 2012 04:50 PM   [ Ignore ]
Avatar
Joined: 2010-01-12
181 posts

Greetings

I’m using the “member_member_register” hook to create a channel entry based on the user’s input during a signup process, however this hook is triggered before the user gets logged in, so I get the “unauthorised posting” message.

The only way I can seem to get past this is to either add a new hook into the “register_member” method after the code that logs the user in, or allow the Guest member group to post to the channel in question, both of which are not ideal.

I need to create the channel entry at this point so is there another way to do this?

Thanks!

 
Posted: 17 July 2012 01:01 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2010-01-12
181 posts

I actually figured out another way round it that did not involve hacking the member module or granting post privileges to Guests. Just by changing the user’s session group_id in my extension before submitting the entry and then changing it back again afterwards:

$this->EE->session->userdata('group_id') = 5

If anyone knows of a better or more elegant way I would love to hear it.

 
Posted: 17 July 2012 04:26 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2008-01-31
4773 posts

Hi David,

Would you like me to move this thread to the Development & Programming forum so that other developers can toss in with their ideas?

 Signature 

Need some help? | Current Versions: EE 2.6.1 // MM 1.2.1

 
Posted: 17 July 2012 04:30 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2010-01-12
181 posts

Hey Kevin, yes please that would be great smile

 
Posted: 17 July 2012 05:03 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2008-01-31
4773 posts

Sure thing!

 Signature 

Need some help? | Current Versions: EE 2.6.1 // MM 1.2.1

 
Posted: 18 July 2012 03:37 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2011-03-18
632 posts

Hi David,

As you are getting the registered member id within this hook so you can make this member as entry author. Use this code before the entry submission code:

$this->EE->session->create_new_session($member_id);
$this->EE->session->fetch_session_data();
$this->EE->session->fetch_member_data(); 

and use $member_id for the author id.


Hope it would work for you.


Best Regards,

 Signature 

Bhashkar Yadav
http://www.sidd3.com

 
Posted: 18 July 2012 04:25 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2010-01-12
181 posts

Bhashkar, I know that theoretically this should work as it’s setting all the session data but it doesn’t work for me, I still get “Unauthorised posting” messages.

 
Posted: 19 July 2012 12:52 AM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2011-03-18
632 posts

Hi David,

I have implemented it and it worked well for me.

Could you please check that member group preference if having authorize to add/edit entry into the channel.

Thanks,

 Signature 

Bhashkar Yadav
http://www.sidd3.com

 
Posted: 20 July 2012 11:41 PM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2010-01-12
181 posts

Yeah it’s all good now, thanks for your help!