Welcome Guest, Not a member yet? Register   Sign In
Tank Auth with Facebook Connect Authentication
#21

[eluser]Ted S[/eluser]
Just finished installing your script for a new application I'm working on... great stuff, thank you!

Quick question... Have you tried modifying the post-connect page to just request a username to make a minimally invasive process? Can tank auth support a forged / faked email?

Alternatively what about using the facebook email system for users who sign up through that (i.e. [email protected])
#22

[eluser]RJ[/eluser]
It should be very easy to pre-populate the email field with the user info returned from Facebook. Then, if you really want to, make the email field hidden to the user and you'll have the desired result.

I will be pre-populating the email field this evening and post the mods here.
#23

[eluser]RJ[/eluser]
[quote author="Ted S" date="1304656973"]Just finished installing your script for a new application I'm working on... great stuff, thank you!

Quick question... Have you tried modifying the post-connect page to just request a username to make a minimally invasive process? Can tank auth support a forged / faked email?

Alternatively what about using the facebook email system for users who sign up through that (i.e. [email protected])[/quote]

and here's your card.. in fb_signin()
Code:
if( sizeof($user) == 0)
{
   $this->session->set_userdata('facebook_email', $fb_user['email']);
    redirect('/auth/auth_other/fill_user_info', 'refresh');
}

in fill_user_info()..
Code:
$data = array('email' => $this->session->userdata('facebook_email') ? $this->session->userdata('facebook_email') : '' );
$this->template->build('/auth_other/fill_user_info', $data);

in the view.. (make it hidden if you like)
Code:
<input type="text" name="email" id="email" value="<?php echo set_value('email', $email); ?>"/>

wait, wait, where's the button? "That was easy". ;-)

(Sorry i dont have line numbers, no time to figure out what they would be before all the modifications)
#24

[eluser]Dacus[/eluser]
[quote author="bullspit" date="1304710656"]
in fill_user_info()..
Code:
$data = array('email' => $this->session->userdata('facebook_email') ? $this->session->userdata('facebook_email') : '' );
$this->template->build('/auth_other/fill_user_info', $data);
[/quote]
That gives me the following error:
Code:
Message: Undefined property: auth_other::$template
Filename: controllers/auth_other.php
Line Number: 137
Any advice please?

Edited later
Instead of your proposed code (which gives the above error for me) I changed the line 10 from fill_user_info.php view like that:
Code:
<td>&lt;input type="text" name="email" id="email" value="&lt;?php echo set_value('email') != null ? set_value('email') : $this-&gt;session->userdata('facebook_email'); ?&gt;"/></td>
This of course works, but I am not sure it's ok to write pure PHP code when using CodeIgniter. I am newbie in CI and MVC development.
#25

[eluser]RJ[/eluser]
I can't see all the code you added but I used a template library to load my views. You can try $this->load->view instead of $this->template->build I used above.

Cheers
#26

[eluser]Dacus[/eluser]
[quote author="bullspit" date="1305855392"]You can try $this->load->view instead of $this->template->build[/quote]
That did the trick, thanks!
I am falling in love with CodeIgniter! Smile
#27

[eluser]Ted S[/eluser]
Made a couple hacks to make the process a little smoother and log a user in after registering. As of right now this only works with core registrations as the Facebook & Twitter systems seem to a better job with this.

Find:
Code:
if (!is_null($data = $this->tank_auth->create_user(

Right after that statement is a // success comment. Add the following below it and before the email / redirect rotuines:

Code:
// success --&gt; log them in
$this->session->set_userdata(array(
'user_id'    => $data['user_id'],
'username'    => $data['username'],
'status'    => STATUS_ACTIVATED
));

$this->users->update_login_info(
$data['user_id'],
$this->config->item('login_record_ip', 'tank_auth'),
$this->config->item('login_record_time', 'tank_auth'));

You should only use this if a registration is considered active immediately. Those with activation emails and similar settings will want to keep things as is.

If you want to pass the remember me cookie you can do that as well. I omitted it as it's a first sign in which is generally treated as short term.
#28

[eluser]RJ[/eluser]
That could be a useful config option for the lib.
#29

[eluser]codeignite_noob[/eluser]
Am I missing something?
If I have an application already using Tank_auth and then add this extension it does not seem to work as I would expect.
Example:
Suppose there is a user already registered with email [email protected] in the application using Tank_auth.
Also assume this is his FB email address as well.
1. Add xtension to Tank_Auth for FB
2. User now uses FB login instead of regular login.
3. FB authenticates/validates and redirects to "fill_user_info"
4. User is now confused. If he tries to enter the email address "[email protected]" he gets a message that the email address is already taken.

How it should work (ideally)
1. If a pre-existing registered user tries FB access, then on authentication/validation the user should be logged in.
- what this means is that there should be some way to fetch the existing user password and log the user in. Perhaps something in fb_login should handle for users who already exist in the database as regular (non-FB) users.
#30

[eluser]Dacus[/eluser]
[quote author="codeignite_noob" date="1306452389"]If a pre-existing registered user tries FB access, then on authentication/validation the user should be logged in.[/quote]
You have to do such functionality yourself. I did something similar but I am not at my home PC now to copy/paste the code changes which I made. The idea is as follows:
1. If you receive email from FB, first check this email using the get_user_by_email() method from user_model.php
Code:
$user = $this->user_model->get_user_by_email('put here user email from FB');
2. If user with such email exists than:
a) update his profile
Code:
$this->user_model->update_facebook_user_profile($user_id, 'put here user facebook id'));
b) simulate tank auth login
Code:
$this->session->set_userdata(array(
          'user_id' => $user[0]->id,
          'username' => $user[0]->username,
          'status' => ($user[0]->activated == 1) ? STATUS_ACTIVATED : STATUS_NOT_ACTIVATED));
$this->users->update_login_info(
          $user[0]->id,
          $this->config->item('login_record_ip', 'tank_auth'),
          $this->config->item('login_record_time', 'tank_auth'));
redirect('auth', 'refresh');




Theme © iAndrew 2016 - Forum software by © MyBB