Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Auth extends CI_Controller {
- public function __construct(){
- parent::__construct();
- $this->load->library('form_validation');
- }
- public function index(){
- $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
- $this->form_validation->set_rules('password', 'Password', 'trim|required');
- if ($this->form_validation->run() == false){
- $data['judul'] = 'Halaman Login';
- $this->load->view('template/auth_header', $data);
- $this->load->view('auth/login');
- $this->load->view('template/auth_footer');
- }
- else{
- //ketika validasi lolos atau sukses
- $this->_login();
- }
- }
- private function _login(){
- $email = $this->input->post('email'); //ngambil email yang ada di elemen email
- $passwordd = $this->input->post('password'); //ngambil password yang ada di elemen email
- $user = $this->db->get_where('user',['email=> $email'])->row_array();
- var_dump($user);
- die;
- }
- public function registration(){
- //aturan untuk kolom inputan pada form
- $this->form_validation->set_rules('name', 'Name', 'required|trim');
- $this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email|is_unique[user.email]',[
- 'is_unique' => 'This Email has already registered'
- ]);
- $this->form_validation->set_rules('password1', 'Password', 'required|trim|
- min_length[3]|matches[password2]',[
- 'min_lenght' => 'Password too short!',
- 'matches' => 'Password dont matches'
- ]);
- $this->form_validation->set_rules('password2', 'Password', 'required|trim|matches[password1]');
- //logika untuk mengembalikan tampilan apabila form_validasi nya gagal
- if ($this->form_validation->run() == false ){
- $data['judul'] = 'Halaman Registration';
- $this->load->view('template/auth_header', $data);
- $this->load->view('auth/registration');
- $this->load->view('template/auth_footer');
- } else {
- //membuat sebuah variabel utk isian perintah memasukkan apa yang diinputkan di form input
- //lalu memasukkan di tabel database
- $data = [
- 'name' => htmlspecialchars($this->input->post('name',true)),
- 'email' => htmlspecialchars($this->input->post('email',true)),
- 'image' => 'default.jpg',
- 'password' => password_hash($this->input->post('password'), PASSWORD_DEFAULT),
- 'role_id' => 2,
- 'is_active' => 1,
- 'date_created' => time()
- ];
- //memasukkan variabel tadi ke tabel user
- $this->db->insert('user',$data);
- //Kasih pesan sebelum redirect Buat flashdata pakai session
- $this->session->set_flashdata('massage','<div class="alert alert-success" role="alert">
- Congrats your account has been ceated!
- </div>');
- //setelah database berhasil masuk, kita redirect ke halaman index auth.
- redirect('auth');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement