Welcome Guest, Not a member yet? Register   Sign In
Redux Authentication 2 Beta Released
#61

[eluser]Packe[/eluser]
Not sure if I should post in this thread of create a new one, but I try here first.

I put up a site on my webhost using CI with Redux Auth beta 2. I entered the correct information in config\email.php. Then I try registrating a new user, but am not getting any activation mail.

I made a test with the code below (from the CI userguide) and a mail was received, so the details in the config file is correct.

Code:
$this->email->from('[email protected]', 'Your Name');
$this->email->to('[email protected]');
$this->email->cc('[email protected]');
$this->email->bcc('[email protected]');

$this->email->subject('Email Test');
$this->email->message('Testing the email class.');

$this->email->send();

echo $this->email->print_debugger();

What could be the reason behind no mail being sent by Redux Auth? It works fine when doing the same on my local machine.

EDIT: Nevermind, found the problem which was an non-set "from" address.
#62

[eluser]Kirkjoserey[/eluser]
User Groups
-----------

With Redux I can set Level (group_id) for a Page ??? (Group Access for a page)

I say: List of Products -->Access to Group: member
List of Cities ---> Aceess to Group: manager


Then; when UserOne (belong Group: member) logins in the main menu only see List Of Products.
when UserAdmin (belong Group: manager) logins in the main menos see everything.


best regards.
#63

[eluser]Spir[/eluser]
that auth lib is one of the best it needs to keep active. I see last update has 9 month now. Does the beta version is good enough to start with? I only work with 1.x for now.
#64

[eluser]Phil Sturgeon[/eluser]
I'll be keeping an eye on the progress of this project. Keep up the good work.
#65

[eluser]Kirkjoserey[/eluser]
[quote author="Spir" date="1253540007"]that auth lib is one of the best it needs to keep active. I see last update has 9 month now. Does the beta version is good enough to start with? I only work with 1.x for now.[/quote]

I take my chances with the beta version.

;-)
#66

[eluser]trenchard[/eluser]
[quote author="Spir" date="1253540007"]that auth lib is one of the best it needs to keep active. I see last update has 9 month now. Does the beta version is good enough to start with? I only work with 1.x for now.[/quote]

I just implemented the beta in a new site. I essentially had to walk though the whole code base to configure the forms the way I need and to debug the email activation code. Some functions don't seem to be in use and can be stripped out. I have the registration, activation, and login working decently.

On the whole it is pretty straight forward even if you are just starting out.
#67

[eluser]Isern Palaus[/eluser]
[quote author="trenchard" date="1257348560"][quote author="Spir" date="1253540007"]that auth lib is one of the best it needs to keep active. I see last update has 9 month now. Does the beta version is good enough to start with? I only work with 1.x for now.[/quote]

I just implemented the beta in a new site. I essentially had to walk though the whole code base to configure the forms the way I need and to debug the email activation code. Some functions don't seem to be in use and can be stripped out. I have the registration, activation, and login working decently.

On the whole it is pretty straight forward even if you are just starting out.[/quote]

Hello trenchard,

Could you bring us the code for the activation? I can't get it working fine... And do you coded the recovery password? It will be nice to have this functions working.

Thank you in advance,
Isern
#68

[eluser]trenchard[/eluser]
Here is the modified code for the activation functionality. Note that I use $email as the username throughout the code. I've added a few comments were I remember having to debug the code.

Controller Functions

Code:
function add()
    {
        $data = array();
        
        $this->form_validation->set_rules('first_name','First Name','trim|required');
        $this->form_validation->set_rules('last_name','Last Name','trim|required');
        $this->form_validation->set_rules('email','Email','trim|required|valid_email');
        $this->form_validation->set_rules('password','Password','trim|required|min_length[4]|max_length[32]');
        $this->form_validation->set_rules('validate','Validated Password','trim|required|matches[password]');
        $this->form_validation->set_error_delimiters('<p class="error">', '</p>');
        if ($this->form_validation->run() == FALSE)
        {
            $data = array(
                  'content'=>$this->load->view('register', NULL, TRUE),
                'title'=>'Create Your Account'
               );
            $this->load->view('template', $data);
        }
        else
        {
            $first_name = $this->input->post('first_name');
            $last_name  = $this->input->post('last_name');
            $email      = $this->input->post('email');
            $password   = $this->input->post('password');
          
               //register the user and return a boolean success variable
               $register = $this->redux_auth->register($password, $email);
        
            if ($register)
            {
                $this->session->set_flashdata('message', '<p class="success">Blah. ');
                redirect('user/activate');
            }
            else
            {
                $this->session->set_flashdata('message', '<p class="error">Our system failed during your registration.  Please accept our apologies and try to register again.</p>');
                redirect('user/register');
            }
        }
    }

function activate()
    {
        $data = array();
        
        $this->form_validation->set_rules('code', 'Activation Code', 'required');
        $this->form_validation->set_error_delimiters('<p class="error">', '</p>');
        if ($this->form_validation->run() == FALSE)
        {
            $data = array('content'=>$this->load->view('activate', NULL, TRUE),
                    'title'=>'Activate Your Account');
            $this->load->view('template', $data);
        }
        else
        {
            $code = $this->input->post('code');
            $activate = $this->redux_auth->activate($code);
            if ($activate)
       {
                $this->session->set_flashdata('message', '<p class="error">Your account is activated.  You may log in.</p>');
        redirect('user/login');
        }
      else
       {
        $this->session->set_flashdata('message', '<p class="error">Your activation code was entered incorrectly.  Please try again.</p>');
            redirect('user/activate');
            }
        }
    }



Library Function
Code:
public function register($password, $email)
    {
       $data = array();
       $config = array();
        
        $email_activation = $this->ci->config->item('email_activation');
        $email_folder     = $this->ci->config->item('email_templates');

        if (!$email_activation)
        {
            return $this->ci->redux_auth_model->register($password, $email);
        }
        else
        {
            $register = $this->ci->redux_auth_model->register($password, $email);
            
            if ($register == FALSE) { return FALSE; }  //this was messed in the Beta code

            //create an activation code for the new account
            $deactivate = $this->ci->redux_auth_model->deactivate($email);
            
            if ($deactivate == FALSE) { return FALSE; } //this was messed up in the Beta code

            $activation_code = $this->ci->redux_auth_model->activation_code;

            $data = array('password'   => $password,
                        'email'      => $email,
                        'activation' => $activation_code);
            
            //Setup and send activation email
            $message = $this->ci->load->view($email_folder.'activation', $data, TRUE);
            
            $config = Array('mailtype'  => 'html',
                        'charset'   => 'iso-8859-1');
                   $this->ci->email->initialize($config);  
            $this->ci->email->clear();
            $this->ci->email->set_newline("\r\n");
            $this->ci->email->from('[email protected]');
            $this->ci->email->to($email);
            $this->ci->email->subject(' XXX Account Activation (Registration)');
            $this->ci->email->message($message);
            return $this->ci->email->send();
        }
    }

Primary Model Functions

Code:
public function deactivate($email = FALSE)
    {
        $users_table = $this->tables['users'];
        
        if ($email === FALSE)
        {
            return FALSE;
        }
        
        $activation_code = sha1(md5(microtime()));
        $this->activation_code = $activation_code;
        
        $data = array('activation_code' => $activation_code);
        
        $this->db->update($users_table, $data, array('email' => $email));
        
        return ($this->db->affected_rows() >= 1) ? TRUE : FALSE; //Watch this if you are in development and allowing duplicate emails in the user table.  I just made this to equal one or more since this check was not doing much in this location.
    }

public function activate($code = FALSE)
    {
        //same as Beta (running out of room on this post
}
#69

[eluser]Isern Palaus[/eluser]
Hello!

Thank you trenchard, this is very useful! Will try it tomorrow :-)!

Regards,
Isern
#70

[eluser]trenchard[/eluser]
Hope it gets you closer. There are many moving parts on this and they all need to be synched. Without documentation, you have to just go line by line to get it to work.

I have noticed that there really should be more granularity in the functional responses. In other words, it will be necessary to know why a function returned FALSE so that the flash messages can be configured to be more helpful and other classes can be launched. I will eventually rewrite the functions to return status messages that can be used in conditional logic.

By the way, I'm just now implementing the password reset functionality and I can tell you that I'm not optimistic it will work out of the box. I'm going to try today, but I may end up rewriting much of it to be a better process. I think the two email method is far from best in class.

I'll post more as I build this out.

Mark




Theme © iAndrew 2016 - Forum software by © MyBB