waktu tersisa untuk klaim DISKON 40% dalam program Full Stack Membership. Klaim Promo!

[Tanya] Kenapa emailnya masih tetap bisa teregistrasi ?

Ditanyakan pada tanggal 24 May 2020 oleh Yudi Edit  Hapus  Tandai Selesai  Tandai 

Kak, kenapa pada registasi ini tetap memasukkan email yang sudah teregistasi dan melakukan registasi ulang masih tetap masuk dan menjadi double didalam database ?

dibawah ini controller nya


class Register extends MY_Controller {

        public function _construct()
        {
            parent::_construct();

            $is_login = $this->session->userdata('is_login');

            if ($is_login) {

                redirect(base_url());
                return;

            }

        }

        public function index() {

            // ! = not (jika bukan)

            if(!$_POST) {

                $input =  (object) $this->register->getDefaultValues();
            } else {
                $input = (object) $this->input->post(null, true);
            }

            if (!$this->register->validate()) {

                $data['title'] = 'Register';
                $data['input'] = $input;
                $data['page'] = 'pages/auth/register';
                $this->view($data);
                return;
            }

            if ($this->register->run($input)) {

                $this->session->set_flashdata('success', 'Selamat telah berhasil melakukan registrasi ...');

                redirect(base_url());

            }else {
                $this->session->flashdata('error', 'Ooopss proses registasi anda gagal !!!' );

                // maka kita akan redirect user ke register kembali

                redirect(base_url('/register'));

            }

        }

}

dibawah ini Register_model


    protected $table = 'user';

    public function getDefaultValues(){

        return [
                    'name'      => '',
                    'email'     => '',  
                    'password'  => '',
                    'role'      => '',
                    'is_active' => '',
                ];
    }

    public function getValidationRules() {

        $validationRules = [
                            [
                                'field' => 'name',   
                                'label' => 'Nama',
                                'rules' => 'trim|required',
                            ],
                            [
                                'field' => 'email',   
                                'label' => 'E-Mail',          
                                'rules' => 'trim|required|valid_email|is_unique[user.email]',  
                                'error' => [
                                            'is_unique' => 'This %s already exists.',
                                            'required'  => 'You must provide a %s',
                                ],
                            ],

                            [
                                'field' => 'password',  
                                'label' => 'Password',
                                'rules' => 'required|min_length[8]|is_unique[user.password]',
                                'erorr' => [
                                            'required' => 'You must provide a %s',
                                ],
                            ],

                            [
                                'field' => 'password_confirmation',   
                                'label' => 'Konfirmasi Password',
                                'rules' => 'required | matches[password]',
                            ],
                        ];

                        return  $validationRules;
    }

    public function run($input) {

        $data = [
                   'name'       => $input->name,
                   'email'      => strtolower($input->email),
                   'password'   => hashEncrypt($input->password),   
                   'role'       => 'member',
                ];

        // var user dibawah hanya mengebalikan nilanya saja
        $user = $this->create($data);    // create($data) 

        $sess_data = [
                        'id'        => $user,
                        'name'      => $data['name'],  
                        'email'     => $data['email'],
                        'role'      => $data['role'],
                        'is_login'  => true,

                    ];

                    $this->session->set_userdata($sess_data);
                    return true;
    }

}
BUAT KOMENTAR

1 JAWABAN / 0 KOMENTAR

User avatar
Ahmad Oriza menjawab pada tanggal 26 May 2020 Jadikan Jawaban Terbaik  Edit  Hapus  Ubah ke Komentar 

Coba dicek lagi kode Register_model nya kak. Di kami sih tidak bisa double kok.

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Register_model extends MY_Model 
{

    protected $table = 'user';

    public function getDefaultValues()
    {
        return [
            'name'      => '',
            'email'     => '',
            'password'  => '',
            'role'      => '',
            'is_active' => ''   
        ];
    }

    public function getValidationRules()
    {
        $validationRules = [
            [
                'field' => 'name',
                'label' => 'Nama',
                'rules' => 'trim|required',
            ],
            [
                'field'     => 'email',
                'label'     => 'E-Mail',
                'rules'     => 'trim|required|valid_email|is_unique[user.email]',
                'errors'    => [
                    'is_unique' => 'This %s already e'
                ]
            ],
            [
                'field' => 'password',
                'label' => 'Password',
                'rules' => 'required|min_length[8]',
            ],
            [
                'field' => 'password_confirmation',
                'label' => 'Konfirmasi Password',
                'rules' => 'required|matches[password]',
            ],
        ];

        return $validationRules;
    }

    public function run($input)
    {
        $data       = [
            'name'      => $input->name,
            'email'     => strtolower($input->email),
            'password'  => hashEncrypt($input->password),
            'role'      => 'member'
        ];

        $user       = $this->create($data);

        $sess_data  = [
            'id'        => $user,
            'name'      => $data['name'],
            'email'     => $data['email'],
            'role'      => $data['role'],
            'is_login'  => true
        ];

        $this->session->set_userdata($sess_data);
        return true;
    }

}

/* End of file Register_model.php */

BUAT KOMENTAR