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

[eluser]Unknown[/eluser]
Hi!

What would be the best way to localize/change urls when using TankAuth.

I would like to have
http://mydomain.com/auth/login/ changed to http://mydomain.com/konto/zaloguj

I can use routes facility, but Auth class redirects to "auth/*" methods on certain events.
I would like also to keep original code of TankAuth.

Regards,
Maciek
#32

[eluser]Gromozeka[/eluser]
Why don't you change the controller code according to your needs?

When I was developing the library I supposed that 'auth' controller is a part that will be modified from one project to another. It is just a sample; many libraries are being distributed without such controller at all. So if its behavior doesn't safisfy you then you're free to change it. For example, if you don't want user to be redirected to server root after successful login, just change this redirect in 'login' method to something else.

While correcting controller behavior is easy, changing names of controller's methods may be a little bit complicated. If you want to change the name of 'login' method, don't forget to correct it in all redirects to login (or at least to change this code to something else). Renaming other methods (such as 'activate' or 'reset_password') requires you to fix corresponding email templates also.

And renaming controller leads to fixing names in all view-files and redirects. Or you may use CI routing.

I don't know is it possible to resolve this problem without touching the controller at all, using some tricks like <a href="http://ellislab.com/codeigniter/user-guide/general/controllers.html#remapping">remap</a> functions or Redirect commands in htaccess-file. As for me, the best way is to change the code than to build struts. Smile
#33

[eluser]Gromozeka[/eluser]
Hi guys,

New version of the library (Tank Auth 1.0.3) is available. The download link is the same:
http://konyukhov.com/soft/tank_auth/tank_auth.zip

There are no new features in this version, only minor bug fixes. The database structure is not affected, all the changes were in the code, in the folders 'libraries', 'models' and 'views'.


PS: I can't explain why they made
Code:
empty("0")
returning TRUE, but they did it. Did you know that? Me neither.
#34

[eluser]RaZoR LeGaCy[/eluser]
Hi,

I keep getting "Registration is disabled." even though I set $config['allow_registration'] = TRUE;
#35

[eluser]Gromozeka[/eluser]
Could you post your instances of config/tank_auth.php and controllers/auth.php?
#36

[eluser]RaZoR LeGaCy[/eluser]
Auth
Code:
function register()
    {
        if ($this->tank_auth->is_logged_in()) {                                    // logged in
            redirect('');

        } elseif ($this->tank_auth->is_logged_in(FALSE)) {                        // logged in, not activated
            redirect('/auth/send_again/');

        } elseif (!$this->config->item('allow_registration', 'tank_auth')) {    // registration is off
            $this->_show_message($this->lang->line('auth_message_registration_disabled'));
            return;

        } else {
            $use_username = $this->config->item('use_username', 'tank_auth');
            if ($use_username) {
                $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length['.$this->config->item('username_min_length', 'tank_auth').']|max_length['.$this->config->item('username_max_length', 'tank_auth').']|alpha_dash');
            }
            $this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean|valid_email');
            $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|min_length['.$this->config->item('password_min_length', 'tank_auth').']|max_length['.$this->config->item('password_max_length', 'tank_auth').']|alpha_dash');
            $this->form_validation->set_rules('confirm_password', 'Confirm Password', 'trim|required|xss_clean|matches[password]');

            $captcha_registration    = $this->config->item('captcha_registration', 'tank_auth');
            $use_recaptcha            = $this->config->item('use_recaptcha', 'tank_auth');
            if ($captcha_registration) {
                if ($use_recaptcha) {
                    $this->form_validation->set_rules('recaptcha_response_field', 'Confirmation Code', 'trim|xss_clean|required|callback__check_recaptcha');
                } else {
                    $this->form_validation->set_rules('captcha', 'Confirmation Code', 'trim|xss_clean|required|callback__check_captcha');
                }
            }
            $data['errors'] = array();

            $email_activation = $this->config->item('email_activation', 'tank_auth');

            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))) {                                    // 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($this->lang->line('auth_message_registration_completed_1'));
                        return;

                    } 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($this->lang->line('auth_message_registration_completed_2').' '.anchor(site_url('/auth/login/'), 'Login'));
                        return;
                    }
                } else {
                    $errors = $this->tank_auth->get_error_message();
                    foreach ($errors as $k => $v)    $data['errors'][$k] = $this->lang->line($v);
                }
            }
            if ($captcha_registration) {
                if ($use_recaptcha) {
                    $data['recaptcha_html'] = $this->_create_recaptcha();
                } else {
                    $data['captcha_html'] = $this->_create_captcha();
                }
            }
            $data['use_username'] = $use_username;
            $data['captcha_registration'] = $captcha_registration;
            $data['use_recaptcha'] = $use_recaptcha;
            $this->load->view('auth/register_form', $data);
        }
    }

tank_auth
Code:
$config['allow_registration'] = TRUE;
$config['captcha_registration'] = FALSE;
$config['email_activation'] = FALSE;
$config['email_activation_expire'] = 60*60*24*2;
$config['email_account_details'] = TRUE;
$config['use_username'] = TRUE;
#37

[eluser]Gromozeka[/eluser]
Everything seems to be ok.

The only way to get 'Registration is disabled' message instead of registration form is to set this condition to TRUE:

Code:
} elseif (!$this->config->item('allow_registration', 'tank_auth')) {    // registration is off
    $this->_show_message($this->lang->line('auth_message_registration_disabled'));
    return;

Probably 'allow_registration' option is overwritten to FALSE somewhere after it is set to TRUE. Or config-file isn't loaded at all. Would you comment these 3 lines of code in 'register' and see what happen? Will everything else work fine?
#38

[eluser]RaZoR LeGaCy[/eluser]
your right it is not loading the config file

auto_load
Code:
$autoload['libraries'] = array('database', 'tank_auth','Multicache');
$autoload['helper'] = array('url', 'form', 'array', 'html', 'date', 'text', 'string', 'common', 'file');
$autoload['config'] = array('tank_auth', 'pagination');
#39

[eluser]RaZoR LeGaCy[/eluser]
found it

does not work
Code:
$this->config->item('password_max_length', 'tank_auth')

does work
Code:
$this->config->item('password_max_length')


Why??
#40

[eluser]Gromozeka[/eluser]
Errr... probably defining specific name for config-file doesn't work when config is auto-loaded.

I recommend you to remove tank_auth from this line:
Code:
$autoload['config'] = array('tank_auth', 'pagination');

Only auth-controller needs this file and loads it in constructor. There's no need to keep it autoloaded.




Theme © iAndrew 2016 - Forum software by © MyBB