Welcome Guest, Not a member yet? Register   Sign In
my own user registeration and login library!
#2

[eluser]A.M.F[/eluser]
here is the rest of Forms.php

Code:
//
    //Handling with the registration
    //
    function register()
    {    
        $this->load->library('validation');

        $rules['username']  = "trim|required|alpha_dash|min_length[2]|max_length[32]|prep_for_form|htmlspecialchars|xss_clean|callback_username_check";        
        $rules['password']  = "trim|required|min_length[4]|max_length[32]|matches[passconf]|prep_for_form|htmlspecialchars|xss_clean";
        $rules['passconf']  = "required|prep_for_form";
        $rules['email']     = "trim|required|valid_email|matches[emailconf]|prep_for_form|htmlspecialchars|xss_clean|callback_email_check";
        $rules['emailconf'] = "required|prep_for_form";

        $this->validation->set_rules($rules);
        $this->validation->set_error_delimiters('<b>שגיאה: </b>', '<br />');

        $fields['username']  = 'השם משתמש';
        $fields['password']  = 'הסיסמא';
        $fields['passconf']  = 'האישור סיסמא';
        $fields['email']     = 'הדואר אלקטרוני';
        $fields['emailconf'] = 'אימות הדוא"ל';

        $this->validation->set_fields($fields);


        if ($this->validation->run() == FALSE)
        {
            $data['message'] = $this->validation->error_string;

            if ((isset($_POST['send'])) && ($this->session->userdata('code') != strtoupper($_POST['securityimg']))) //security code is wrong?
            {
                $data['message'] .= "<b>שגיאה: </b>הקוד אבטחה שגוי.";
            }

            $this->layout->buildPage('register', $data);
        }

        else //all the form fields are fine
        {
            if ($this->session->userdata('code') != strtoupper($_POST['securityimg'])) //security code is wrong?
            {
                $data['message'] = "<b>שגיאה: </b>הקוד אבטחה שגוי.";
                $this->layout->buildPage('register', $data);
            }
            else
            {
                if ($this->user_m->register($_POST)) //adding the user
                {
                    redirect('/show/login'); //going to the login page
                }
                else
                {
                    show_error('An unexpected error occurred, please try again.');
                }
            }
            
        }
    }

    function username_check($str) //username allready exists in the DB?
    {
        if ($this->user_m->check_match($str, 'username') == TRUE)
        {
            $this->validation->set_message('username_check', '%s שבחרת כבר נמצא בשימוש.');
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }

    function email_check($str) //email allready exists in the DB?
    {
        if ($this->user_m->check_match($str, 'email') == TRUE)
        {
            $this->validation->set_message('email_check', '%s שבחרת כבר נמצא בשימוש.');
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }

}

now, i have a model called user_m.php that for now containes two functions: register() - putting the user data inside the DB, and check_match() - used in the emailcheck() and usercheck() functions that in my Forms.php controller.

user_m.php

Code:
class User_m extends Model
{
    
    var $object;

    function User_m()
    {
        // Call the Model constructor
        parent::Model();
        $this->object =& get_instance();
    }

    
    //
    //Adding the user to the database
    //
    function register($info)
    {
        $info['password'] = md5(sha1($info['password']));
        $data = array(  'username' => $info['username'],
                        'password' => $info['password'],
                        'email'    => $info['email']
                );

        if($this->object->db->insert('users', $data))
        {
            return TRUE;
        }
        else
        {
            return FALSE;
        }
    }

    // --------------------------------------------------------------------

    /**
     * Check Match
     *
     * @access    public
     * @param    string    value
     * @param    string    field name
     *
     * @return    boolean    true or false if there's a match
     */
    function check_match($var, $field)
    {
        $query = $this->object->db->getwhere('users', array($field => $var));

        if ($query->num_rows() > 0)
        {
            return TRUE;
        }
        else
        {
            return FALSE;
        }
    }

}


Messages In This Thread
my own user registeration and login library! - by El Forum - 12-09-2007, 07:11 AM
my own user registeration and login library! - by El Forum - 12-09-2007, 07:12 AM
my own user registeration and login library! - by El Forum - 12-09-2007, 07:14 AM
my own user registeration and login library! - by El Forum - 01-11-2008, 12:16 AM
my own user registeration and login library! - by El Forum - 01-11-2008, 03:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB