Welcome Guest, Not a member yet? Register   Sign In
flexi auth - A user authentication library for CodeIgniter

[eluser]katanama[/eluser]
[quote author="jasonlally" date="1355899752"]I was able to find the root cause, but still searching for a solution. I have a core MY_Controller extending CI_Controller. I had switched the Auth controller to extend MY_Controller to take advantage of some template functions I'm using across my controllers. Anyway, when I switch Auth to extend CI_Controller again, everything is fine again. So I guess the key question is what happens to the __get($key) magic function when I extend the core CI_Controller? What is breaking? Do I need to declare something in my constructor for MY_Controller so $CI can get the main instance via get_instance still.

[/quote]

From my understanding : Your problem exist when Auth controller extends your MY_Controller, but not when it extends CI_Controller, true?


If you have a MY_Controller, and it has a constructor, maybe you forgot to invoke
Code:
parent::_constructor()
?

I had problem like yours when I used certain HMVC library.
$data is not visible inside models... that's why I asked wether you're using any HMVC extension and which one.

Before switching to Jens Segers HMVC, when calling any methods in my models, i pass $this as parameter.

In my model methods, I declare the method with the param received as reference.

example :

in controller :

Code:
$this->accounts_model->delete_accounts($this);

in model, when declaring delete_accounts method :

Code:
public function delete_accounts (&$that){
// do something, and :
$that->data->message['status'] = 'delete success' ;
}

I declare my $data as my controller property.

not by declaring in constructor

$this->data = null; or
$this->data = array(), or
$this->data = new stdClass

have you tried debugging using xDebug? follow the code flow...

[eluser]katanama[/eluser]
In the Model Class :

Code:
public function &__get($key)
{
  $CI = get_instance();
  return $CI->$key;
}

It calls get_instance() in Codeigniter.php

Code:
function &get;_instance()
{
  return CI_Controller::get_instance();
}

Which return a reference to the statice method in system/core/Controller.php

Code:
public static function &get;_instance()
{
  return self::$instance;
}

So I guess there's a disconnection between your MY_Controller and your CI_Controller.
Check if you do call parent::_construct() and invoke it the first thing in your MY_Controller construct.

Sorry if the way I answer is annoying. Expressing myself in English makes me feel 'limited'.

[eluser]haseydesign[/eluser]
@xuma

From your comment, I'm not 100% sure what the exact problem you are having is; however, some notes...

Firstly, both the flexi auth and flexi cart libraries require that the 'sess_use_database' MUST be set to TRUE as the session array for all the authentication and cart data is too big to store in a cookie, therefore its stored in the database instead.

Then from what I can understand of your problem, you are stating that the 'login()' function is working (Returning TRUE at least), but the 'is_logged_in()' function is returning FALSE. Am I right?

If you are calling the 'is_logged_in()' function immediately after calling the 'login()' function, then the 'is_logged_in()' function will return FALSE regardless of whether you are logged in as it is session dependent, and in CI when using sessions, changes do not become readable until after page reload. Therefore you need to do a page reload (You can use CI's 'redirect()' function) and then call the 'is_logged_in()' function to check a users status.

As a side note, typically you shouldn't need to check if a user is logged in immediately after calling the 'login()' function. If it returns TRUE, then they're logged in; there is no need to revalidate until after page load.

This reason why you say it works when you switch 'sess_use_database' to FALSE, is that maybe CI can read/return session data that has has been set within the same page load.

Hope that helps.
Rob

[eluser]haseydesign[/eluser]
@jasonlally

I also typically use MY_controller to extend the controllers within my own sites when using flexi auth, and it works fine for me.
My setup is something like the following:

MY_controller example (Located in /application/core/MY_Controller.php)
Code:
class MY_controller extends CI_Controller {

function __construct()
{
  parent::__construct();
  $this->auth = new stdClass;
  $this->load->library('flexi_auth');

  // Example flexi auth library call within extended controller.
  $this->data['login_status'] = $this->flexi_auth->is_logged_in();
}
}

Top level controller example
Code:
class Example_controller extends MY_controller {

function __construct()
{
  parent::__construct();
}

function index()
{
  $this->load->view('index', $this->data);
}
}

Does that help?

@katanama - thanks for joining in and trying to help others out with the library!

[eluser]xuma[/eluser]
[quote author="haseydesign" date="1355910819"]@xuma

From your comment, I'm not 100% sure what the exact problem you are having is; however, some notes...

Firstly, both the flexi auth and flexi cart libraries require that the 'sess_use_database' MUST be set to TRUE as the session array for all the authentication and cart data is too big to store in a cookie, therefore its stored in the database instead.

Then from what I can understand of your problem, you are stating that the 'login()' function is working (Returning TRUE at least), but the 'is_logged_in()' function is returning FALSE. Am I right?

If you are calling the 'is_logged_in()' function immediately after calling the 'login()' function, then the 'is_logged_in()' function will return FALSE regardless of whether you are logged in as it is session dependent, and in CI when using sessions, changes do not become readable until after page reload. Therefore you need to do a page reload (You can use CI's 'redirect()' function) and then call the 'is_logged_in()' function to check a users status.

As a side note, typically you shouldn't need to check if a user is logged in immediately after calling the 'login()' function. If it returns TRUE, then they're logged in; there is no need to revalidate until after page load.

This reason why you say it works when you switch 'sess_use_database' to FALSE, is that maybe CI can read/return session data that has has been set within the same page load.

Hope that helps.
Rob[/quote]

Thanks for your long answer

After spending hours , searching for answer , about 1 hour ago i setup new codeigniter/flexi_auth with same database.Demo was working fine.

After i include demo files to my main project , main project with demo files wasnt working again.Finally i changed config file and it was starting to work.There was only one difference;

Code:
$config['language'] = 'english';

My main project was using ;
Code:
$config['language'] = 'turkish';

How the hell that can be problem ? Smile I spend atleast 5-6 hours chasing set_userdata function in core files.

I had same language files in both english and turkish folders.I dont know how this effects but it was really annoying.

[eluser]haseydesign[/eluser]
@xuma

Well as you are probably aware, there isn't a Turkish language version within the flexi auth library - If you're happy to translate one, I'll gladly add it to the library with full credit to yourself.

Why that causes the exact problem you are having, I can only guess CI doesn't handle it to well if a required language is not available.
If you create a duplicate of the flexi auth English language file (Don't bother translating for the purpose of this test) and moved it to 'application/language/turkish/flexi_auth_lang.php' - does that work?

In any case, thanks for posting back the cause of your problem, hopefully it may help someone else out in future.

[eluser]xuma[/eluser]
[quote author="haseydesign" date="1355914872"]@xuma

If you create a duplicate of the flexi auth English language file (Don't bother translating for the purpose of this test) and moved it to 'application/language/turkish/flexi_auth_lang.php' - does that work?

[/quote]
I had translated flexi_auth_lang.php file in my turkish folder.(Copied from english folder)I changed to orginal one and starts working again.Definitely i have problem with my language file.I cant find any errors in file.Its just wierd.

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Name: flexi auth lang - English
*
* Author:
* Rob Hussey
* [email protected]
* haseydesign.com/flexi-auth
*
* Released: 13/09/2012
*
* Description:
* English language file for flexi auth
*
* Requirements: PHP5 or above and Codeigniter 2.0+
*/

// Account Creation
$lang['account_creation_successful']    = 'Hesabınız başarılı bir şekilde oluşturuldu.';
$lang['account_creation_unsuccessful']    = 'Hesabınız oluşturulamadı.';
$lang['account_creation_duplicate_email']   = 'Bu email adresine sahip bir hesap mevcut.';
$lang['account_creation_duplicate_username']  = 'Bu kullanıcı adına sahip bir hesap mevcut.';
$lang['account_creation_duplicate_identity']   = 'Bu kimliğe  sahip bir hesap mevcut.';
$lang['account_creation_insufficient_data']   = 'Insufficient data to create an account. Ensure a valid identity and password are submitted.';

// Password
$lang['password_invalid']       = "%s alanı geçersiz..";
$lang['password_change_successful']       = 'Şifre başarılı bir şekilde değiştirildi.';
$lang['password_change_unsuccessful']        = 'Göndermiş olduğunuz şifre kayıtlı şifre ile uyuşmuyor..';
$lang['password_token_invalid']       = 'Your submitted password token is invalid or has expired.';
$lang['email_new_password_successful']    = 'Yeni şifre email adresinize gönderildi.';
$lang['email_forgot_password_successful']    = 'Şifrenizi sıfırlamak için gerekli bilgiler email adresinize gönderildi.';
$lang['email_forgot_password_unsuccessful']    = 'Şifreniz sıfırlanamıyor.';

// Activation
$lang['activate_successful']      = 'Hesap aktivasyonu başarılı.';
$lang['activate_unsuccessful']      = 'Hesap aktivasyonu başarısız.';
$lang['deactivate_successful']      = 'Hesap deaktive edildi.';
$lang['deactivate_unsuccessful']     = 'Hesap deaktive edilemedi.';
$lang['activation_email_successful']      = 'Aktivasyon emaili gönderildi.';
$lang['activation_email_unsuccessful']      = 'Aktivasyon emaili gönderilemedi.';
$lang['account_requires_activation']     = 'Hesabınızın size gönderilen email ile aktive edilmesi gerekmektedir.';
$lang['account_already_activated']      = 'Hesap aktivasyonunuz zaten yapılmış.';
$lang['email_activation_email_successful']   = 'Yeni email adresinizi aktive etmek için email gönderildi.';
$lang['email_activation_email_unsuccessful']  = 'Yeni email adresiniz aktive etmek için gereken email gönderilemedi.';

// Login / Logout
$lang['login_successful']       = 'Başarılı bir şekilde giriş yaptınız.';
$lang['login_unsuccessful']       = 'Göndermiş olduğunuz giriş bilgileri hatalı.';
$lang['logout_successful']       = 'Başarılı bir şekilde çıkış yaptınız.';
$lang['login_details_invalid']       = 'Giriş bilgileriniz geçersiz.';
$lang['captcha_answer_invalid']      = 'CAPTCHA cevabı yanlış.';
$lang['login_attempts_exceeded']      = 'Maksimum giriş denemesine ulaştınız , lütfen bir süre bekleyip tekrar deneyiniz.';
$lang['login_session_expired']      = 'Oturum süreniz doldu.';
$lang['account_suspended']        = 'Hesabınız donduruldu.';

// Account Changes
$lang['update_successful']       = 'Hesap bilgileriniz başarılı şekilde güncellendi.';
$lang['update_unsuccessful']      = 'Hesap bilgilerinizi güncelleyemedik.';
$lang['delete_successful']       = 'Hesap bilgileri başarılı şekilde silindi.';
$lang['delete_unsuccessful']      = 'Hesap bilgileriniz silinemedi.';

// Form Validation
$lang['form_validation_duplicate_identity']   = "Bu email veya kullanıcı adı ile başka bir hesap bulunmakta..";
$lang['form_validation_duplicate_email']    = "The Email of %s field is not available.";
$lang['form_validation_duplicate_username']   = "The Username of %s field is not available.";

[eluser]xuma[/eluser]
It is working with below settings
Code:
$config['language'] = 'turkish';
$config['sess_use_database'] = FALSE;
[/code]
It is not working with below settings.
Code:
$config['language'] = 'turkish';
$config['sess_use_database'] = TRUE;
[/code]
It is working with below settings
Code:
$config['language'] = 'english';
$config['sess_use_database'] = TRUE;
[/code]

It is not working translated english/flexi_auth_lang.php
Code:
$config['language'] = 'english';
$config['sess_use_database'] = TRUE;
[/code]

So summary i am doing something wrong with language file but working with sess_use_database=false.You can check file content above post.

[eluser]haseydesign[/eluser]
@xuma

I just tested your posted language file on one of my own sites and it also doesn't work because of the characters used in the 'login_successful' message. This will no doubt also cause problems if flexi auth tries to use any of the other messages using these characters.

If I remove the characters 'ş' and 'ı', then the login works.

This seems to be some quirk in CI and possibly how it saves data to the database for sessions - to which I'm afraid I don't have a solution. Keep us posted if you find fix for this.

[eluser]xuma[/eluser]
Thanks @hasseydesign
Finally i solved problem.Changing ci_sessions table charset is the key.
Code:
ALTER TABLE  `ci_sessions` CHANGE  `user_data`  `user_data` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL

I think we can define it a codeigniter bug.




Theme © iAndrew 2016 - Forum software by © MyBB