Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Login extends CI_Controller
- {
- function __construct()
- {
- parent::__construct();
- }
- function index()
- {
- $data_session = $this->session->all_userdata();
- if(!empty($data_session)){
- redirect('admin/main');
- }else{
- $this->load->view('login_view');
- }
- }
- function dologin()
- {
- $rules = array(
- array(
- 'field' => 'username',
- 'label' => 'Username',
- 'rules' => 'required|callback_cek_username'
- ),
- array(
- 'field' => 'password',
- 'label' => 'Password',
- 'rules' => 'required'
- )
- );
- $this->form_validation->set_rules($rules);
- $this->form_validation->set_error_delimiters('<div class="alert alert-error">','</div>');
- $data = array(
- 'username' => $this->input->post('username'),
- 'password' => $this->input->post('password')
- );
- if($this->form_validation->run() == FALSE){
- $this->load->view('login_view');
- }else{
- //set session
- $this->session->set_userdata($data['username']);
- redirect('admin/main');
- }
- }
- function cek_username($str){
- if($str != 'admin'){
- $this->form_validation->set_message('cek_username','%s Salah! Coba Lagi.');
- return FALSE;
- }else{
- return TRUE;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment