Welcome Guest, Not a member yet? Register   Sign In
Tank Auth v1.0 (CI authentication library)

[eluser]shaffick[/eluser]
[quote author="Ted S" date="1304657122"]Couple questions about extending functionality...

1- Is there a way to automatically log a user in after they register (assuming everything passes and email validation is not required)?

2 - Has anyone modified the library to redirect to the page the user came from rather than back to the homepage after login?

Thanks![/quote]

Yes. This is for Tank Auth 1.0.9

In libraries/Tank_auth, change
Code:
private function create_autologin($user_id)
to
Code:
function create_autologin($user_id)


DONT copy paste the whole block BELOW, mine is slightly customised.

In controllers/auth, comment out $this->_show_message and check out the last 2 lines I added.

Code:
if ($this->form_validation->run()) {                                // validation ok
                if (!is_null($data = $this->tank_auth->create_user(
                        $use_username ? $this->form_validation->set_value('username') : '',
                        $this->form_validation->set_value('email'),
                        $this->form_validation->set_value('password'),
                        $email_activation,
                        $profile_array))) {                                        // success


                    $data['site_name'] = $this->config->item('website_name', 'tank_auth');

                    if ($email_activation) {                                    // send "activate" email
                        $data['activation_period'] = $this->config->item('email_activation_expire', 'tank_auth') / 3600;

                        $this->_send_email('activate', $data['email'], $data);

                        unset($data['password']); // Clear password (just for any case)

                        //$this->_show_message('<h1>Registration</h1>' . $this->lang->line('auth_message_registration_completed_1'));

                    } else {
                        if ($this->config->item('email_account_details', 'tank_auth')) {    // send "welcome" email

                            $this->_send_email('welcome', $data['email'], $data);
                        }
                        unset($data['password']); // Clear password (just for any case)

                        //$this->_show_message('<h1>Registration</h1>' . $this->lang->line('auth_message_registration_completed_2').' '.anchor('/auth/login/', 'Login'));
                    }
                    
                    /*
                     * Set autologin here
                     *
                     */
                    
                     $this->tank_auth->create_autologin($data['user_id']);
                     redirect('/profile/#ui-tabs-1');

[eluser]ninja.dude[/eluser]
installed tank auth, but the captcha is blank in other words there is no captcha but it tells me to enter the words i see??

[eluser]Unknown[/eluser]
Somebody asked a while back about allowing special characters in passwords but didn't get a response. I've got the same question as well. Is this limitation just on the count of the form validation or will allowing it break phpass or something? I haven't been able to find any info about it online. Thanks!

[eluser]arnaud.courbiere[/eluser]
For ninja.dude: if you want to see the captcha, make sure the captcha folder is writable.

It is written in the doc, step 4 of Installing Tank Auth.
Tank Auth

I missed it too the first time.

[eluser]Unknown[/eluser]
Thanks for the Tank Auth library. I was 4 hours into writing my own when I found yours as a much better option.

I have a question regarding the database schema though. Why is user_profiles.user_id not a FK of users.id but rather a copy of information?

[eluser]shadow3751[/eluser]
thanks, now it works!
the unreadable font was exactly the problem!!!
http://www.loyalma.com
major in lady's products(lingerie,uniform,adults products,shoes)
high quality,lowest prices,and free shipment,quick to order!

[eluser]Unknown[/eluser]
[quote author="vili" date="1304781517"]I use CodeIgniter + Tank Auth. "/auth/forgot_password" doesn't work. The result always is: "Your activation key is incorrect or expired. Please check your email again and follow the instructions."

The registration and activation are all right.[/quote]

Make sure you are setting the correct time zone in php.ini (eg: date.timezone = Europe/London)

If not the db query always return false because of mysql & php unix timestamp is different when comparing expire time.

[eluser]cyberjunkie[/eluser]
When retrieving a user's id, shouldn't it be converted to an int?

For example I'm doing this.

Code:
$user_id = (int) $this->tank_auth->get_user_id();

Would that be recommended?

[eluser]arnaud.courbiere[/eluser]
[quote author="cyberjunkie" date="1310950890"]When retrieving a user's id, shouldn't it be converted to an int?

For example I'm doing this.

Code:
$user_id = (int) $this->tank_auth->get_user_id();

Would that be recommended?[/quote]

Since php is loosely typed, I would say that it is not necessary unless you want to check for value + type (== vs ===) somewhere else in your code.

ex:
Code:
$int_id = 1;
$str_id = '1';

echo ($int_id == $str_id); // true
echo ($int_id === $str_id); // false, one is an int the other is a string

I hope I didn't say something you know already.

[eluser]Unknown[/eluser]
Hello,

I added a basic user level support in this way:

Added a field in the 'users'-table in MySQL
-------------------------------------------
field:user_level
type:tinyint(16)
attr:UNSIGNED
Null:No
Default:0

in the Tank_auth.php - library I changed this:

around line 71:

Code:
$this->ci->session->set_userdata(array(
    'user_id'    => $user->id,
    'username'    => $user->username,
    'status'    => ($user->activated == 1) ? STATUS_ACTIVATED : STATUS_NOT_ACTIVATED,
));

into this :

Code:
$this->ci->session->set_userdata(array(
    'user_id'    => $user->id,
    'username'    => $user->username,
    'userlevel'    => $user->user_level,
    'status'    => ($user->activated == 1) ? STATUS_ACTIVATED : STATUS_NOT_ACTIVATED,
));


And around line 587:
Code:
$this->ci->session->set_userdata(array(
    'user_id'    => $user->id,
    'username'    => $user->username,
    'status'    => STATUS_ACTIVATED,
));

into this:
Code:
$this->ci->session->set_userdata(array(
    'user_id'    => $user->id,
    'username'    => $user->username,
    'userlevel'    => $user->user_level,
    'status'    => STATUS_ACTIVATED,
));

and somewhere around line 155 (after get_username()-function) I added these 2 functions:

Code:
/**
* Get userlevel
*
* @return    string
*/
function get_userlevel()
{
    return $this->ci->session->userdata('userlevel');
}
    
/**
* Validate userlevel
*
* @return    bool
*/
function validate_userlevel($level = 0)
{
    if($this->ci->session->userdata('userlevel') >= $level)
    {
        return TRUE;
    }
    return FALSE;
}


Usage in your controllers:

To get the users level:

Code:
$data['user_id']    = $this->tank_auth->get_user_id();
            $data['username']    = $this->tank_auth->get_username();
            $data['userlevel']    = $this->tank_auth->get_userlevel();
            $this->load->view('welcome', $data);

To validate the userlevel:

Code:
if($this->tank_auth->validate_userlevel(1))
            {
            // show or do something...
            }

The validation is simple:

a standard user gets level 0, every higher level is allowed to see the lower levels.
So if you create an admin user and give it level 9, you have 10 levels. But you can make it as high as you want.
In the example code level 0 is blocked and level 1 and up are granted access.




Theme © iAndrew 2016 - Forum software by © MyBB