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 Login extends CI_Controller
- {
- function __construct()
- {
- parent::__construct();
- $this->load->model('model_login');
- }
- public function index()
- {
- $data = array(
- 'action' => site_url('login/login'),
- 'username' => set_value('username'),
- 'password' => set_value('password'),
- 'captcha' => $this->recaptcha->getWidget(),
- 'script_captcha' => $this->recaptcha->getScriptTag(),
- );
- $this->load->view('login',$data);
- }
- public function login()
- {
- if (isset($_POST['login'])) {
- $this->form_validation->set_error_delimiters('<div class="text-danger">','</div>');
- $username = $this->input->post('username',true,'trim|required');
- $password = $this->input->post('password',true,'trim|required');
- $recaptcha = $this->input->post('g-recaptcha-response');
- $response = $this->recaptcha->verifyResponse($recaptcha);
- $cek = $this->model_login->proses($username,$password);
- $hasil = count($cek);
- if ($hasil > 0 || $this->form_validation->run() == TRUE || !isset($response['success']) || $response['success'] == true) {
- $logintest = $this->db->get_where('users',array('username'=>$username,'password'=>$password))->row();
- $data = array('success' => true,
- 'nama'=>$logintest->nama,
- 'username'=>$logintest->username
- );
- $this->session->set_userdata($data);
- if ($logintest->level == 'admin') {
- redirect('home_admin');
- }elseif ($logintest->level == 'user') {
- redirect('home_user');
- }
- }else{
- redirect('index','refresh');
- }
- /*if ($hasil > 0) {
- $logintest = $this->db->get_where('users',array('username'=>$username,'password'=>$password))->row();
- $data = array('success' => true,
- 'nama'=>$logintest->nama,
- 'username'=>$logintest->username
- );
- $this->session->set_userdata($data);
- if ($logintest->level == 'admin') {
- redirect('home_admin');
- }elseif ($logintest->level == 'user') {
- redirect('home_user');
- }
- }else{
- redirect('index','refresh');
- }*/
- //$this->form_validation->set_rules('username',' ','trim|required');
- //$this->form_validation->set_rules('password',' ','trim|required');
- }
- }
- function home_admin()
- {
- $this->load->view('admin',$data);
- }
- function home_user()
- {
- $this->load->view('user',$data);
- }
- function logout()
- {
- $this->session->sess_destroy();
- redirect('index');
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement