Welcome Guest, Not a member yet? Register   Sign In
Redux Auth 2 Beta - How to check if email / username already exists in database when registering
#1

[eluser]Oskar Smith[/eluser]
Hello all. I'm using the newer (Beta) version of Redux Auth. It would appear that when registering it doesn't automatically check to see if a username or email already exists in the database. (i.e. "Sorry, that username is already taken"). I know it's still in Beta so perhaps this isn't implemented yet, but does anyone else have experience of this?

I see there is a function email_check and username_check in the redux_auth model (redux_auth_model.php) but don't see that it gets called anywhere. Perhaps I'm supposed to call it manually from my controller?

Anyway, thanks for any tips that anyone has for me.
#2

[eluser]Oskar Smith[/eluser]
Ah! Shortly after posting the above I think I've answered my own question. I think Redux expects the email_check and username_check to be used as a callback within the form validation routine. i.e.

Code:
$this->form_validation->set_rules('username', 'Username', 'required|callback_username_check');
$this->form_validation->set_rules('email', 'Email Address', 'required|callback_email_check|valid_email');


Then in your controller there needs to be two extra functions:

Code:
public function email_check($email)
    {
        $check = $this->redux_auth_model->email_check($email);

        if ($check)
        {
            $this->form_validation->set_message('email_check', 'The email "'.$email.'" already exists.');
            return false;
        }
        else
        {
            return true;
        }
    }


public function username_check($username)
    {
        $check = $this->redux_auth_model->username_check($username);

        if ($check)
        {
            $this->form_validation->set_message('username_check', 'The username "'.$username.'" already exists.');
            return false;

        }
        else
        {
            return true;
        }
    }


Knew it would be something simple. Having said that, I'd have half thought that Redux Auth would have a fail-safe check at the point at which the new user gets stored to the database to prevent duplicate emails/usernames. Anyway, as long as the above is there I guess I should be fine.




Theme © iAndrew 2016 - Forum software by © MyBB