0

I use Codeigniter framework + Tank_Auth registiration library. They work great but I just need to change register form a bit.

I want to generate username from email address instead of getting it from registeration form. I added a simple function to libraries/Tank_auth.php file. Here is my username generator function:

function _create_username_from_email($email)
{
$user = strstr($email, '@', true); // As of PHP 5.3.0
return $user;
}
  1. Please let me know where I need to run my function and write it to database.

  2. I will also need to remove username field from register form. So I need how I can pass form validation for username field in my controller.

I will be really happy if any of you can help me about these problem.

Thanks

1 Answers1

1

At line 121 in application/models/tank_auth/users you have:

/**
 * Create new user record
 *
 * @param   array
 * @param   bool
 * @return  array
 */
function create_user($data, $activated = TRUE)
{
    $data['created'] = date('Y-m-d H:i:s');
    $data['activated'] = $activated ? 1 : 0;

    if ($this->db->insert($this->table_name, $data)) {
        $user_id = $this->db->insert_id();
        if ($activated) $this->create_profile($user_id);
        return array('user_id' => $user_id);
    }
    return NULL;
}

Just before the if ($this->db->insert($this->table_name, $data)) { insert:

$data['username'] = strstr($data['email'], '@', true);

P.S. I hope you understand it, but just in case - if you have two or more users with same email's username part like john@hotmail.com and john@gmail.com they both will have the same username, which may lead to unexpected behavior.

Sergey Telshevsky
  • 12,077
  • 6
  • 55
  • 78