Commit 56c6463f authored by Iswahyudi's avatar Iswahyudi
Browse files

Penambahan login, captcha dan penyesuaian menu sesuai Role name

parent f491005f
Pipeline #23814 passed with stages
in 7 minutes and 20 seconds
......@@ -89,7 +89,7 @@ $autoload['drivers'] = array();
|
| $autoload['helper'] = array('url', 'file');
*/
$autoload['helper'] = array('url','file','html','form','string','text');
$autoload['helper'] = array('url','file','html','form','string','text','captcha');
/*
| -------------------------------------------------------------------
......
......@@ -88,6 +88,11 @@ $route['default_controller'] = 'Main';
$route['users/user/usersave'] = 'Users/user_save';
$route['users/user/userdelete/(:any)']= 'Users/user_delete/$1';
$route['users/user/userput']= 'Users/user_put';
/*LOGIN*/
$route['login/signin'] = 'Login/login_post';
$route['login/signout'] = 'Login/logout';
$route['login/captcha'] = 'Login/captcha';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
//API URL
private $urlLogin = 'https://api.easy-parking.ourcode.site/api/user/login/';
function __construct(){
parent::__construct();
}
/*MANAGE LOGIN*/
function login_post(){
if ($this->input->post('captcha') == $this->session->userdata('captcha')) {
$email = $this->input->post('email');
$password = $this->input->post('password');
//create a new cURL resource
$ch = curl_init($this->urlLogin);
// //setup request to send json via POST
$data = array(
'email' => $email,
'password' => $password,
);
$param = json_encode($data);
print_r ($param);
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
// //attach encoded JSON string to the POST fields
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
//set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json','Content-Length: '. strlen($param)));
//return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//execute the POST request
$result = curl_exec($ch);
$responseCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
//close cURL resource
curl_close($ch);
$alert = 'alert-success';
$message = 'Login Berhasil';
if ($responseCode != 200) {
$message = "Username or password unidentified";
$alert = 'alert-danger';
$this->session->set_flashdata('error',$message);
} else {
$result = json_decode($result);
$this->session->set_userdata('nama',$result->name);
if ($result->userRole->name=='Administrator') {
$this->session->set_userdata('isLogin',1);
} else
if ($result->userRole->name=='Petugas Parkir') {
$this->session->set_userdata('isLogin',2);
} else
if ($result->userRole->name=='Kasir') {
$this->session->set_userdata('isLogin',3);
} else {
$this->session->set_userdata('isLogin',0);
}
}
} else {
$message = "Incorrect captcha code";
$alert = 'alert-danger';
$this->session->set_flashdata('error',$message);
}
redirect(base_url('Main'));
}
function logout() {
$this->session->sess_destroy();
redirect(base_url('Main'));
}
}
\ No newline at end of file
......@@ -14,11 +14,35 @@ class Main extends CI_Controller {
$this->load->view('main/dashboard');
}
// LOGOUT
function logout() {
$this->session->sess_destroy();
redirect(base_url('login'));
function captcha()
{
header('Content-type: image/jpeg');
$captcha_num = 'ABCDEFGHJKLMNPQRSTUVWXYZ123456789';
$captcha_num = substr(str_shuffle($captcha_num), 0, 6);
$this->session->set_userdata('captcha',$captcha_num);
$font_size = 35;
$img_width = 130;
$img_height = 45;
$image = imagecreate($img_width, $img_height); // create background image with dimensions
imagecolorallocate($image, 0, 200, 255); // set background color
$line_color = imagecolorallocate($image, 50,50,50);
for($i=0;$i<10;$i++) {
imageline($image,0,rand()%50,200,rand()%50,$line_color);
}
$pixel_color = imagecolorallocate($image, 0,0,0);
for($i=0;$i<1000;$i++) {
imagesetpixel($image,rand()%200,rand()%50,$pixel_color);
}
$text_color = imagecolorallocate($image, 0, 0, 0);
imagettftext($image, $font_size, 0, 15, 30, $text_color, FCPATH.'assets/fonts/youmurdererbb_reg.ttf', $captcha_num);
imagejpeg($image);
}
/////////////////////////////// END MODAl ////////////////////////////////////////////////////////
}
\ No newline at end of file
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
<?php $this->load->view('main/header.php')?>
<!-- Left side column. contains the logo and sidebar -->
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Home
<small>
<?php $this->view('main/viewdate.php')?>
</small>
</h1>
<!--
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
<li class="active">Dashboard</li>
</ol>
-->
</section>
<!-- Main content -->
<section class="content">
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-md-12">
<?php $this->load->view('main/header.php')?>
<!-- Left side column. contains the logo and sidebar -->
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Home
<small>
<?php $this->view('main/viewdate.php')?>
</small>
</h1>
</section>
<!-- Main content -->
<section class="content">
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-md-12">
<div class="box box-body box-default">
<!-- Callout -->
<!-- Callout -->
<div class="callout callout">
<h2><strong>Selamat Datang, </strong><?php echo $this->session->userdata('nama');?>
</h2>
<p></p>
<?php if($this->session->flashdata('error')){?>
<div class='alert alert-danger alert-dismissable'>
<i class='fa fa-info'></i>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
<b><?php echo $this->session->flashdata('error'); ?></b>
</div>
<?php }?>
<h2><strong>Selamat Datang, </strong><?php echo $this->session->userdata('nama');?>
</h2>
<p></p>
</div>
</div>
</div>
<!-- ./col -->
</div>
<!-- ./col -->
</div>
<!-- /.row -->
<!-- /.row -->
<!-- Small boxes (Stat box) -->
</section>
<!-- /.content -->
</div>
<!-- Small boxes (Stat box) -->
</section>
<!-- /.content -->
<?php $this->load->view('main/footer')?>
<div class="control-sidebar-bg"></div>
</div>
<?php $this->load->view('main/footer')?>
<!-- MODAL LOGIN -->
<div class="modal fade" id="modal_login" role="dialog" aria-labelledby="largeModal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h3 class="modal-title" id="myModalLabel"><center>Easy-Parking Login</center></h3>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<form action="<?php echo base_url()?>login/signin" id="form_login" enctype="multipart/form-data" method="POST">
<div class="form-group col-md-12">
<label>Username</label>
<input type="text" class="form-control" name="email" id="emailId">
</div>
<div class="form-group col-md-12">
<label>Password</label>
<input type="password" class="form-control" name="password" id="passwordId">
</div>
<!-- Control Sidebar -->
<p><img src="<?php echo base_url();?>main/captcha"></p>
<!-- /.control-sidebar -->
<!-- Add the sidebar's background. This div must be placed
immediately after the control sidebar -->
<div class="control-sidebar-bg"></div>
</div>
</body>
<div class="form-group col-md-4">
<label>Input Kode Captcha</label>
<input type="text" class="form-control" name="captcha" id="captchaId">
</div>
<div class="form-group col-md-2">
<br>
<right>
<button type="submit" id="btn_login" name="btn_login" class="btn btn-sm btn-primary"><h5><center>LOGIN</center></h5></button>
</right>
</div>
</form>
</div>
</div>
<br>
</div>
</div>
</div>
</div>
<!-- END MODAL -->
</body>
</html>
<script>
function refreshCaptcha()
{
var img = document.images['captchaimg'];
img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
}
</script>
<header class="main-header">
<!-- Logo -->
<a href="<?php echo base_url('index.php/main')?>" class="logo">
<!-- mini logo for sidebar mini 50x50 pixels -->
<span class="logo-mini"><img class="img-responsive" src="<?php echo base_url('img/logopendek.png')?>"></span>
<!-- logo for regular state and mobile devices -->
<span class="logo-lg"><img class="img-responsive" src="<?php echo base_url('img/logopanjang.png')?>"></span>
<a href="<?php echo base_url('index.php/main')?>" class="logo">
<!-- mini logo for sidebar mini 50x50 pixels -->
<span class="logo-mini"><img class="img-responsive" src="<?php echo base_url('img/logopendek.png')?>"></span>
<!-- logo for regular state and mobile devices -->
<span class="logo-lg"><img class="img-responsive" src="<?php echo base_url('img/logopanjang.png')?>"></span>
</a>
<!-- Header Navbar: style can be found in header.less -->
<nav class="navbar navbar-static-top">
<!-- Sidebar toggle button-->
<a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
<span class="sr-only">Toggle navigation</span>
</a>
<div class="navbar-custom-menu">
<ul class="nav navbar-nav">
<!-- Messages: style can be found in dropdown.less-->
<!-- User Account: style can be found in dropdown.less -->
<?php if($this->session->userdata('isLogin')!=0){?>
<li class="dropdown user user-menu">
<a href="#" onclick="location.href='<?php echo base_url('login/signout'); ?>'" class="dropdown-toggle">
<img src="<?php echo base_url('assets/dist/img/user2-160x160.jpg')?>" class="user-image" alt="User Image">
<span> Sign Out </span>
</a>
</li>
<?php } else {?>
<li class="dropdown user user-menu">
<a href="#" onclick="modal_show()" class="dropdown-toggle">
<img src="<?php echo base_url('assets/dist/img/user2-160x160.jpg')?>" class="user-image" alt="User Image">
<span> Sign In </span>
</a>
</li>
<?php } ?>
</ul>
</div>
</nav>
</header>
<script>
function modal_show(){
$('#modal_login').modal('show');
$('#form_login')[0].reset();
}
</script>
</a>
<!-- Header Navbar: style can be found in header.less -->
<nav class="navbar navbar-static-top">
<!-- Sidebar toggle button-->
<a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
<span class="sr-only">Toggle navigation</span>
</a>
<!-- <a class="navbar-brand"><b>PPIC</b><small> System</small></a>
-->
<div class="navbar-custom-menu">
<ul class="nav navbar-nav">
<!-- Messages: style can be found in dropdown.less-->
<!-- User Account: style can be found in dropdown.less -->
<li class="dropdown user user-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<img src="<?php echo base_url('assets/dist/img/user2-160x160.jpg')?>" class="user-image" alt="User Image">
<span class="hidden-xs">Sign Out</span>
</a>
<ul class="dropdown-menu">
<!-- The user image in the menu -->
<li class="user-header">
<img src="<?php echo base_url('')?>assets/dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">
<p>
<?php echo $this->session->userdata('nama'); ?>
<small> <?php echo $this->session->userdata('bagian'); ?></small>
</p>
</li>
<!-- Menu Footer-->
<li class="user-footer">
<div>
<a href="<?php echo base_url('index.php/main/logout'); ?>" ><button class="btn btn-danger btn-flat btn-block"> <i class="fa fa-sign-out"></i> Sign out</button></a>
</div>
</li>
</ul>
</ul>
</div>
</nav>
</header>
......@@ -51,7 +51,11 @@ defined('BASEPATH') OR exit('No direct script access allowed');
</div>
<div class="pull-left info">
<p><?php echo $this->session->userdata('nama'); ?></p>
<a href="#"><i class="fa fa-circle text-success"></i> Online</a>
<?php if($this->session->userdata('isLogin')!=0){?>
<a href="#"><i class="fa fa-circle text-success"></i> Online</a>
<?php } else {?>
<a href="#"><i class="fa fa-circle text-success"></i> Offline</a>
<?php } ?>
</div>
</div>
......@@ -65,68 +69,95 @@ defined('BASEPATH') OR exit('No direct script access allowed');
</a>
</li>
<li class="treeview">
<a href="#">
<i class="fa fa-folder"></i>
<span>Area Parkir & Rate</span>
<span class="pull-right-container">
<i class="fa fa-angle-left pull-right"></i>
</span>
</a>
<ul class="treeview-menu">
<li>
<a href="<?php echo base_url()?>master/rate">
<i class="fa fa-circle-o"></i>
Rate/Price
<?php
switch ($this->session->userdata('isLogin')){
case 1:?>
<li class="treeview">
<a href="#">
<i class="fa fa-folder"></i>
<span>Area Parkir & Rate</span>
<span class="pull-right-container">
<i class="fa fa-angle-left pull-right"></i>
</span>
</a>
<ul class="treeview-menu">
<li>
<a href="<?php echo base_url()?>master/rate">
<i class="fa fa-circle-o"></i>
Rate/Price
</a>
</li>
<li>
<a href="<?php echo base_url()?>master/location">
<i class="fa fa-circle-o"></i>
Location
</a>
</li>
<li>
<a href="<?php echo base_url()?>master/zone">
<i class="fa fa-circle-o"></i>
Zone
</a>
</li>
<li>
<a href="<?php echo base_url()?>master/slot">
<i class="fa fa-circle-o"></i>
Slot
</a>
</li>
</ul>
</li>
<li>
<a href="<?php echo base_url()?>master/location">
<i class="fa fa-circle-o"></i>
Location
<li class="treeview">
<a href="#">
<i class="fa fa-users"></i>
<span>User Management</span>
<span class="pull-right-container">
<i class="fa fa-angle-left pull-right"></i>
</span>
</a>
<ul class="treeview-menu">
<li>
<a href="<?php echo base_url()?>users/roleview">
<i class='fa fa-vcard'></i> <span>Role</span>
</a>
<li>
<a href="<?php echo base_url()?>users/userview">
<i class='fa fa-user'></i> <span>Users</span>
</a>
</li>
</ul>
</li>
<li>
<a href="<?php echo base_url()?>master/zone">
<i class="fa fa-circle-o"></i>
Zone
<a href="#">
<i class='fa fa-money'></i> <span>Financial Reports</span>
</a>
</li>
<?php
break;
case 2:?>
<li>
<a href="<?php echo base_url()?>master/slot">
<i class="fa fa-circle-o"></i>
Slot
<a href="#">
<i class='fa fa-money'></i> <span>View Available Slot</span>
</a>
</li>
</ul>
</li>
<li class="treeview">
<a href="#">
<i class="fa fa-users"></i>
<span>User Management</span>
<span class="pull-right-container">
<i class="fa fa-angle-left pull-right"></i>
</span>
</a>
<ul class="treeview-menu">
<li>
<a href="<?php echo base_url()?>users/roleview">
<i class='fa fa-vcard'></i> <span>Role</span>
</a>
<a href="#">
<i class='fa fa-money'></i> <span>Update Slot</span>
</a>
</li>
<?php
break;
case 3:?>
<li>
<a href="<?php echo base_url()?>users/userview">
<i class='fa fa-user'></i> <span>Users</span>
</a>
<a href="#">
<i class='fa fa-money'></i> <span>Exit Parking</span>
</a>
</li>
</ul>
</li>
<li>
<a href="#">
<i class='fa fa-money'></i> <span>Financial Reports</span>
</a>
</li>
<?php
break;
}?>
</section>
<!-- /.sidebar -->
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment