Tank Auth Adding Fields

后端 未结 3 1755
日久生厌
日久生厌 2021-01-07 03:50

I\'ve been working with the Tank Auth library all day and have a question about it. I added two fields to the registration form: first_name and last_name respectively and I\

相关标签:
3条回答
  • 2021-01-07 03:58

    Check the Tank_auth file in the library, there is another "create_user" function that you have to modify. To manage properly the variables. 3 hours breaking my head with this.

    0 讨论(0)
  • 2021-01-07 04:00

    I noticed a couple things:

    private function create_profile($user_id, $data)
    {
        $this->db->set('user_id', $user_id);
        $this->db->set('first_name', $first_name);
        $this->db->set('last_name', $last_name);
        return $this->db->insert($this->profile_table_name);
    }
    

    $data is an array, I'm assuming you SHOULD pass first_name and last_name here (which you do not).

    Also TANK AUTH requires you to updated the columns you need for profile database schema (did you do this? didn't mention).

    To correct the code above, you would need to pass more details in the array ($data) like so:

    $data['first_name'] = "Bob";
    $data['last_name']  = "Smith";
    
    create_profile($user_id, $data); // which would then use the first & last names 
    

    Not that I want to keep a conversation going about this but...*

    You need to do just what I showed you:

    • define 2 variables (first & last name) and pass them to the create_profile fn.
    • properly USE the variables (don't use $data[0] that is SLOPPY, do $data['first_name'] if that is what you called the array value. There is no reason to be sloppy and do $data[0] -- guessing no less at the key value of your array).
    • its not hard, read your code (understand it, if you don't then step back and try to break it down line by line what is happening, I am getting the sense you have NO idea what any of these functions are doing).
    0 讨论(0)
  • 2021-01-07 04:07

    What You should do is put the two columns you want in the user_profiles table, then add a function to the models/tank_auth/users.php with something like:

    function UpdateProfileInfo ($userID, $firstname, $lastname)
    {
        return $this->db->update('user_profiles', array('firstname'=>$firstname, 'lastname'=>$lastname), array('user_id' => $userID)); 
    }
    

    Then replace (in /libraries/Tank_auth.php)
    function create_user($username, $email, $password, $email_activation)
    With
    function create_user($username, $email, $password, $email_activation, $userInfo)

    Then right beneath (in /libraries/Tank_auth.php)
    if (!is_null($res = $this->ci->users->create_user($data, !$email_activation))) { Add
    $this->users->UpdateProfileInfo($userInfo["firstname"],$userInfo["lastname"]);

    Then replace (in /controllers/auth.php)

            if ($this->form_validation->run()) {                                // validation ok
                if (!is_null($data = $this->tank_auth->create_user(
                        $use_username ? $this->form_validation->set_value('username') : '',
                        $this->form_validation->set_value('email'),
                        $this->form_validation->set_value('password'),
                        $email_activation))) {                                  // success
    

    with:

    $userInfo["firstname"] = $this->form_validation->set_value("firstname");
    $userInfo["lastname"]  = $this->form_validation->set_value("lastname");
    
    if ($this->form_validation->run()) {                                // validation ok
        if (!is_null($data = $this->tank_auth->create_user(
                $use_username ? $this->form_validation->set_value('username') : '',
                $this->form_validation->set_value('email'),
                $this->form_validation->set_value('password'),
                $email_activation, $userInfo))) {                                   // success
    

    This isn't tested though it should work, tell me how it goes
    Max

    0 讨论(0)
提交回复
热议问题