Welcome Guest, Not a member yet? Register   Sign In
redux - no login despite successfull activation
#1

[eluser]sparbier[/eluser]
I am stuck with this:
- registration works fine
- activation works fine (checking the database shows that after activation the field - activation_code has been set to zero)

now when I try to login
- if I provide wrong (non-existen) e-mail or correct e-mail but wrong password, the login function correctly returns 'false'
- but if I provide correct e-mail with correct password, the login function returns 'NOT ACTIVATED'

I don't understand what's going on, especially since the password check is behind the check for activation

Any hints?

Code:
public function login ($email, $password)
        {
            # Grab hash, password, id, activation_code and banned_id from database.
            $result = $this->_login($this->users_table, $this->banned_table, $email);

            if ($result)
            {

                if(!empty($result->activation_code))
                {
                    $this->ci->session->set_flashdata('login', 'Your Account is Not Activated.');
                    return 'NOT_ACTIVATED';
                }
                elseif(!empty($result->banned_id))
                {
                    $this->ci->session->set_flashdata('login', 'Your Account has been banned for the following reason : '.$result->reason);
                    return 'BANNED';
                }
                else
                {
                    $password = sha1($this->salt.$result->hash.$password);

                    if ($password === $result->password)
                    {
                        $this->ci->session->set_userdata(array('id'=> $result->id));

                        return true;
                    }
                }
            }

            return false;
        }
#2

[eluser]jgdovin[/eluser]
it looks as though you are using the older version of Redux Auth.. Redux Auth 2 has gotten rid of the switch and case procedures. I forget what the exact code is or why your activation_code field is being set to 0, but if you notice,
if(!empty($result->activation_code))
{
$this->ci->session->set_flashdata('login', 'Your Account is Not Activated.');
return 'NOT_ACTIVATED';
}
is checking for if the field is empty.. not 0... anyway, if im not mistaken and you are using the older version of redux, I highly suggest you head over to popcorned's svn and get the up to date files.

http://redux.devjavu.com/browser/
#3

[eluser]sparbier[/eluser]
well, according to the documentation of CI empty() returns true if the field is empty *or zero* so it should work anyway. Besides, I tried also manually deleting the activation code in the database, so that it was definetely empty in the true sense of the word - didn't help either :-(

Thx for pointing me to version 2, didn't even notice it was available. Do the functions still work the same, so that just swapping the old library with the new does the job, or is there more work to migrate?
#4

[eluser]jgdovin[/eluser]
I have been testing the redux auth 2 as popcorned has been developing it. I really feel that the new way he returns status and messages works much better. Also email activation and forgotten password templates have been moved to view files instead of inside config files.

He has provided an example controller that should work for the most part as a basic example. I believe it just echos out what would happen if true and if false, but it should be easy enough to understand. Popcorned is very busy, If you have any questions im sure he will be around to answer questions, but if I can help in anyway, just post it on here and I will do my best.

Amouge

edit - my apologies on the empty() remark, I am 2 months into CI and have had little time to go through everything. I am learning as I go. I believe the problem before with it returning not active was his use of switch and case arguments. Im not sure exactly what the problem was but it turns out that was not the best way to run checks.
#5

[eluser]Mellis[/eluser]
[quote author="jgdovin" date="1224887939"]it looks as though you are using the older version of Redux Auth.. Redux Auth 2 has gotten rid of the switch and case procedures. I forget what the exact code is or why your activation_code field is being set to 0, but if you notice,
if(!empty($result->activation_code))
{
$this->ci->session->set_flashdata('login', 'Your Account is Not Activated.');
return 'NOT_ACTIVATED';
}
is checking for if the field is empty.. not 0... anyway, if im not mistaken and you are using the older version of redux, I highly suggest you head over to popcorned's svn and get the up to date files.

http://redux.devjavu.com/browser/[/quote]

The solution to the activation problem (for version 1.4x) can be found here:
http://ellislab.com/forums/viewthread/72...30/#436258
#6

[eluser]sparbier[/eluser]
thanx all!
after digging a bit deeper it turned out that the issue was actually related to the statement that calls the login() function. The switch statement there had some cases that check for the returned string (e.g. 'NOT_ACTIVATED') and other cases that just check TRUE or FALSE. I changed the switch statement to if and elseif, but that didn't help either.

Then I came to the solution: I am not really a programmer, but from the behavior observed it appears that if the login() function returns 'NOT_ACTIVATED', for the if-statement this at the same time means it returns TRUE (because it does return something, so 'not FALSE' = TRUE).

When I changed the if-statement that before was checking the condition by 'TRUE' to be now checking for a return value of 'LOGGED_IN' I got it working fine.
so now in the controller 'user' it is:

Code:
function login ()
    {
            $redux = $this->redux_auth->login($this->input->post('email'),$this->input->post('password'));

            if ($redux == 'LOGGED_IN')  {
            $this->index();
            }
            elseif ($redux == 'NOT_ACTIVATED')   {
                echo 'not active';
                echo $redux;
            }
            elseif ($redux == false) {
                echo 'unknown uid or wrong pwd';
                echo $redux;
            }

        }
        else
        {
            $this->index();
        }

which uses the slightly adapted login() function in the redux_auth lib:
Code:
public function login ($email, $password)
        {
            # Grab hash, password, id, activation_code and banned_id from database.
            $result = $this->_login($this->users_table, $this->banned_table, $email);

            if ($result)
            {

                if(!empty($result->activation_code))
                {
                    $this->ci->session->set_flashdata('login', 'Your Account is Not Activated.');
                    return 'NOT_ACTIVATED';
                }
                elseif(!empty($result->banned_id))
                {
                    $this->ci->session->set_flashdata('login', 'Your Account has been banned for the following reason : '.$result->reason);
                    return 'BANNED';
                }
                else
                {
                    $password = sha1($this->salt.$result->hash.$password);

                    if ($password === $result->password)
                    {
                        $this->ci->session->set_userdata(array('id'=> $result->id));

                        return 'LOGGED_IN';
                    }
                }
            }

            return false;
        }
#7

[eluser]Mellis[/eluser]
thanks for posting what works for you!




Theme © iAndrew 2016 - Forum software by © MyBB