Olá Pessoal, tudo bem ?
Preciso de ajuda para verificar um erro que eu devo estar fazendo, eu preciso que meu sistema de login faça a verificação se o usuário é adm ou cliente, caso ele seja cliente preciso que seja redirecionado para outra tela de membros que é só para clientes, o meu painel adm já está ok e funcionando, porém quando eu faço ligin com o usuário que é cliente sou direcionado para o painel adm: abaixo está os códigos utilizados até agora em suas devidas pastas:
Banco de Dados MySql criado:
CREATE TABLE IF NOT EXISTS `tb_users` (
`id_users` int(11) NOT NULL AUTO_INCREMENT,
`nome_user` varchar(45) DEFAULT NULL,
`nome_comp` varchar(150) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`cpf` varchar(50) DEFAULT NULL,
`rg` varchar(50) DEFAULT NULL,
`data_nascimento` date DEFAULT NULL,
`telefone` varchar(15) DEFAULT NULL,
`celular` varchar(15) DEFAULT NULL,
`rua` varchar(45) DEFAULT NULL,
`bairro` varchar(45) DEFAULT NULL,
`cidade` varchar(45) DEFAULT NULL,
`observacao` text,
`senha` varchar(16) DEFAULT NULL,
`status` varchar(15) DEFAULT NULL, --Verifica se o usuário é adm ou cliente--
PRIMARY KEY (`id_users`),
UNIQUE KEY `id_users_UNIQUE` (`id_users`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
Tela de cadastro e Login (pasta vw_login.php):
<?php
$form=array('id' => 'form-login', 'class' => 'form-horizontal','role'=>'form');
$usuario=array('name' => 'nome', 'id' => 'nome', 'class' => 'form-control');
$password=array('name' => 'password', 'id' => 'password', 'class' => 'form-control');
?>
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<link rel="stylesheet" href="<?php echo base_url();?>bootstrap/css/reset.css">
<link rel="stylesheet" href="<?php echo base_url();?>css/bootstrap.min.css">
<link rel="stylesheet" href="<?=base_url()?>css/bootstrap-theme.min.css">
<link rel="stylesheet" href="<?=base_url()?>css/bootstrap.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="<?=base_url()?>bootstrap/js/bootstrap.min.js"></script>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="809554514027-n7euis1fvpb3l8vs783t8f197prffl2s.apps.googleusercontent.com">
<!-- <script>
//Funções após a leitura do documento
$(document).ready(function() {
//Select para mostrar e esconder divs
$('#SelectOptions').on('change',function(){
var SelectValue='.'+$(this).val();
$('.DivPai div').hide();
$(SelectValue).toggle();
});
});
</script> -->
</head>
<body>
<!--
<form action="#">
<select name="SelectOptions" id="SelectOptions" required="">
<option value="">Selecione</option>
<option value="Cadastro">Cadastro</option>
<option value="Login">Lodin</option>
</select>
</form> -->
<!-- <div class="g-signin2" data-onsuccess="onSignIn"></div>
<script>
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
}
if (auth2.isSignedIn.get()) {
var profile = auth2.currentUser.get().getBasicProfile();
console.log('ID: ' + profile.getId());
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
}
</script> -->
<div class="estilo-login">
<div class="Cadastro">
<div id="page-wrapper">
<div class="row-login">
<div class="col-lg-12">
<h1>Cliente <small>Cadastro</small></h1>
<ol class="breadcrumb">
<li class="active"><i class="fa fa-users"></i><a href="<?php echo base_url() . "index.php/home/cliente" ?>"> Cliente</a> / Cadastro</li>
</ol>
</div>
</div><!-- /.row-login -->
<div>
<ul class="nav nav-tabs" role="tablist">
<li class="active"><a href="#fisico" role="tab" data-toggle="tab">Pessoa Física</a></li>
<li><a href="#juridica" role="tab" data-toggle="tab">Pessoa Jurídica</a></li>
<li><a href="#login" role="tab" data-toggle="tab">Login</a></li>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade in active" id="fisico"><!--Listagem de agendamentos-->
<div class="row-login">
<h3>Cadastrar Pessoa Física</h3>
<?php
echo form_open('home/cadastroValidacaoCliente');
echo validation_errors();
echo "<div class='row-login'>";
echo "<div class='col-md-2'>";
echo form_label('Nome de Usuário: ');
echo "<input type='text' name='nome_user' id='nome_user' class='form-control input-sm'>";
echo '</div>';
echo "<div class='col-md-5'>";
echo form_label('Nome: ');
echo "<input type='text' name='nome_comp' id='nome_comp' class='form-control input-sm'>";
echo '</div>';
echo "<div class='col-md-1'>";
echo form_label('Data Nasc.: ');
echo "<input type='text' name='data_nascimento' id='data_nascimento' class='form-control input-sm'>";
echo '</div>';
echo "<div class='col-md-2'>";
$opcao = array(
'f' => 'Feminino',
'm' => 'Masculino'
);
echo form_label('Genero: ');
echo form_dropdown('sexo', $opcao, 'f', 'class=form-control');
echo '</div>';
echo "<div class='col-md-1'>";
echo form_label('RG: ');
echo "<input type='text' name='rg' id='rg' class='form-control input-sm'>";
echo '</div>';
echo "<div class='col-md-2'>";
echo form_label('CPF: ');
echo "<input type='text' name='cpf' id='cpf' class='form-control input-sm'>";
echo '</div>';
echo '</div>';
echo "<div class='row-login'>";
echo "<div class='col-md-3'>";
echo form_label('E-mail: ');
echo "<input type='text' name='email' id='email' class='form-control input-sm'>";
echo '</div>';
echo "<div class='col-md-2'>";
echo form_label('Telefone: ');
echo "<input type='text' name='telefone' id='telefone' class='form-control input-sm' value=''>";
echo '</div>';
echo "<div class='col-md-2'>";
echo form_label('Celular: ');
echo "<input type='text' name='celular' id='celular' class='form-control input-sm' value=''>";
echo '</div>';
echo "<div class='col-md-4'>";
echo form_label('Rua: ');
echo "<input type='text' name='rua' id='rua' class='form-control input-sm'>";
echo '</div>';
echo '</div>';
echo "<div class='row-login'>";
echo "<div class='col-md-3'>";
echo form_label('Bairro: ');
echo "<input type='text' name='bairro' id='bairro' class='form-control input-sm'>";
echo '</div>';
echo "<div class='col-md-2'>";
echo form_label('Cidade: ');
echo "<input type='text' name='cidade' id='cidade' class='form-control input-sm'>";
echo '</div>';
echo "<div class='col-md-3'>";
echo '</div>';
echo "</div>";
echo "<div class='row-login'>";
echo "<div class='col-md-8'>";
echo form_label('Observação: ');
echo "<input type='text' name='observacao' id='observacao' class='form-control input-sm'>";
echo '</div>';
echo "</div>";
echo "<br>";
echo "<div class='row-login'>";
echo "<div class='col-md-2'>";
echo form_label('Senha: ');
echo "<input type='password' name='senha'>";
echo '</div>';
echo "</div>";
echo '<input type="submit" class="btn btn-primary" value="Cadastrar">';
echo form_close();
?>
<!--Fim da Panel verde-->
</div>
</div><!--Pessoa fisica FIM-->
<div class="tab-pane fade" id="juridica">
<div class="row-login">
<h3>Cadastrar Pessoa Jurídica</h3>
<?php
echo form_open('home/cadastroValidacaoClienteJuridico');
echo validation_errors();
echo "<div class='row-login'>";
echo "<div class='col-md-5'>";
echo form_label('Razão Social: ');
echo "<input type='text' name='nome' id='nome' class='form-control input-sm'>";
echo '</div>';
echo "<div class='col-md-5'>";
echo form_label('Responsável: ');
echo "<input type='text' name='responsavel' id='responsavel' class='form-control input-sm'>";
echo '</div>';
echo '</div>';
echo "<div class='row-login'>";
echo "<div class='col-md-2'>";
echo form_label('CNPJ: ');
echo "<input type='text' name='cnpj' id='cnpj' class='form-control input-sm'>";
echo '</div>';
echo "<div class='col-md-3'>";
echo form_label('E-mail: ');
echo "<input type='text' name='email' id='email' class='form-control input-sm'>";
echo '</div>';
echo "<div class='col-md-2'>";
echo form_label('Telefone: ');
echo "<input type='text' name='telefonej' id='telefonej' class='form-control input-sm' value='67 '>";
echo '</div>';
echo "<div class='col-md-2'>";
echo form_label('Celular: ');
echo "<input type='text' name='celularj' id='celularj' class='form-control input-sm' value='67 '>";
echo '</div>';
echo '</div>';
echo "<div class='row-login'>";
echo "<div class='col-md-4'>";
echo form_label('Rua: ');
echo "<input type='text' name='rua' id='rua' class='form-control input-sm'>";
echo '</div>';
echo "<div class='col-md-3'>";
echo form_label('Bairro: ');
echo "<input type='text' name='bairro' id='bairro' class='form-control input-sm'>";
echo '</div>';
echo "<div class='col-md-2'>";
echo form_label('Cidade: ');
echo "<input type='text' name='cidade' id='cidade' class='form-control input-sm'>";
echo '</div>';
echo "</div>";
echo "<div class='row-login'>";
echo "<div class='col-md-8'>";
echo '<br>';
echo form_label('Contatos: ');
echo '<br>';
echo '</div>';
echo "</div>";
echo "<div class='row-login'>";
echo "<div class='col-md-4'>";
echo form_label('Nome: ');
echo "<input type='text' name='contato1' id='contato1' class='form-control input-sm'>";
echo '</div>';
echo "<div class='col-md-2'>";
echo form_label('Telefone: ');
echo "<input type='text' name='cont_tel1' id='cont_tel1' class='form-control input-sm' value='67 '>";
echo '</div>';
echo "<div class='col-md-3'>";
echo form_label('E-mail: ');
echo "<input type='text' name='cont_email1' id='cont_email1' class='form-control input-sm'>";
echo '</div>';
echo "</div>";
echo "<div class='row-login'>";
echo "<div class='col-md-4'>";
echo form_label('Nome: ');
echo "<input type='text' name='contato2' id='contato2' class='form-control input-sm'>";
echo '</div>';
echo "<div class='col-md-2'>";
echo form_label('Telefone: ');
echo "<input type='text' name='cont_tel2' id='cont_tel2' class='form-control input-sm' value='67 '>";
echo '</div>';
echo "<div class='col-md-3'>";
echo form_label('E-mail: ');
echo "<input type='text' name='cont_email2' id='cont_email2' class='form-control input-sm'>";
echo '</div>';
echo "</div>";
echo "<div class='row-login'>";
echo "<div class='col-md-4'>";
echo form_label('Nome: ');
echo "<input type='text' name='contato3' id='contato3' class='form-control input-sm'>";
echo '</div>';
echo "<div class='col-md-2'>";
echo form_label('Telefone: ');
echo "<input type='text' name='cont_tel3' id='cont_tel3' class='form-control input-sm' value='67 '>";
echo '</div>';
echo "<div class='col-md-3'>";
echo form_label('E-mail: ');
echo "<input type='text' name='cont_email3' id='cont_email3' class='form-control input-sm'>";
echo '</div>';
echo "</div>";
echo "<br>";
echo '<input type="submit" class="btn btn-primary" value="Cadastrar">';
echo form_close();
?>
<!--Fim da Panel verde-->
</div>
</div>
<div class="tab-pane fade" id="login"><!--Listagem de agendamentos-->
<div class="row-login">
<h2 style="margin-left:40%;">Fazer Login</h2>
<div style="width:200px; height:200px; position:absolute;
top:80%;
left:50%;
margin-top:-270px;
margin-left:-145px;">
<div class="form-group">
<img class="col-xs-15 col-md-15 pull-center" src="#">
<?php
echo form_open('home/loginValidation',$form);
echo validation_errors();
echo form_label('Login:','nome_user');
echo form_input($usuario);
?>
</div>
<br>
<div class="form-group">
<?php
echo form_label('Senha:','senha');
echo form_password($password);
echo "<div class='form-group'>";
echo "<div class='col-sm-offset-2 col-sm-10'>";
echo "<br>";
echo '<input type="submit" class="btn btn-lg btn-success pull-right" value="Entrar">';
echo "</div>";
echo "</div>";
echo form_close();
?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div><!-- /#page-wrapper -->
</div>
<!-- JavaScript -->
<script src="<?= base_url() ?>js/jquery-1.10.2.js"></script>
<script src="<?= base_url() ?>js/bootstrap.js"></script>
<!-- Page Specific Plugins -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="http://cdn.oesmith.co.uk/morris-0.4.3.min.js"></script>
<script src="<?= base_url() ?>js/morris/chart-data-morris.js"></script>
<script src="<?= base_url() ?>js/tablesorter/jquery.tablesorter.js"></script>
<script src="<?= base_url() ?>js/tablesorter/tables.js"></script>
<script src="<?= base_url() ?>js/jquery.mask.min.js"></script>
<script src="<?= base_url() ?>js/jquery-ui.js"></script>
<script type="text/javascript">
$(function () {
$('#cpf').mask('000.000.000-00', {placeholder: "___.___.___-__"});
$('#rg').mask('00.000.000-0', {placeholder: "__.___.___-_"});
$('#telefone').mask('(00)0000-0000', {placeholder: "(00) 0000-0000"});
$('#celular').mask('(00)00000-0000', {placeholder: "(00) 00000-0000"});
$('#data_nascimento').mask('00/00/0000', {placeholder: "__/__/____"});
$('#cnpj').mask('00.000.000/0000-00', {placeholder: "__.___.___/____-__"});
$('#telefonej').mask('(00)0000-0000', {placeholder: "(__) ____-____"});
$('#celularj').mask('(00)0000-0000', {placeholder: "(__) ____-____"});
$('#cont_tel1').mask('(00)0000-0000', {placeholder: "(__) ____-____"});
$('#cont_tel2').mask('(00)0000-0000', {placeholder: "(__) ____-____"});
$('#cont_tel3').mask('(00)0000-0000', {placeholder: "(__) ____-____"});
});
</script>
</body>
</html>
Tela home (funciona como o controller), (pasta: home.php):
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Home extends CI_Controller {
public function index() {
if ($this->session->userdata('is_logged_in') == 1) {
$this->db->where('status','administrador');
$this->load->view('vw_principal');
// }
//
// if ($this->db->where('status','cliente')) {
// $this->load->view('Membros');
// }
} else {
$this->load->view("vw_login");
}
}
public function members() {
if ($this->session->userdata('is_logged_in')) {//verificando se esta logado no sistema
$this->db->where('status','administrador' == TRUE);
$this->load->view('vw_principal');
} else {
redirect('home/restricted');
}
}
public function membersCliente() {
if ($this->session->userdata('is_logged_in')) {//verificando se esta logado no sistema
$this->db->where('status','cliente' == TRUE);
$this->load->view('Membros');
} else {
redirect('home/restricted');
}
}
public function restricted() {
$this->load->view('vw_restricted');
}
public function loginValidation() {
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('nome_usere', 'Login', 'required|trim|callback_validate_credentials');
$this->form_validation->set_rules('senha', 'Senha', 'required|md5|trim');
if ($this->form_validation->run() == FALSE) {
$usuario = array(
'nome_user' => $this->input->post('nome_user'),
'is_logged_in' => 1
);
if ($this->db->where('status','administrador')){
$this->session->set_userdata($usuario);
redirect('home/members');
}
if ($this->db->where('status','cliente')){
$this->session->set_userdata($usuario);
redirect('home/membersCliente');
}
} else {
$this->load->view('vw_login');
}
}
public function validate_credentials() {
$this->load->model('md_users');
if ($this->md_users->can_log_in() || $this->md_users->can_log_in_cliente()) {
return true;
} else {
$this->form_validation->set_message('validate_credentials', 'Usuario/Senha incorretos');
return false;
}
}
public function logout() {
$this->session->sess_destroy(); //destroi a sessão
redirect('home/index');
}
public function cadastroValidaçãoAdm(){
$this->load->library('form_validation');
if($this->form_validation->set_rules('nome', 'nome', 'status', 'administrador', 'required|trim')){
if ($this->form_validation->run()) {
$this->load->model('md_users');
$this->md_users->addCliente();
$this->load->view('vw_cliente');
} else {
$this->load->view('vw_clienteCadastro');
}
}
}
public function cadastroValidacaoCliente() {
$this->load->library('form_validation');
if($this->form_validation->set_rules('nome_user', 'nome_user', 'status', 'cliente', 'required|trim')){
if ($this->form_validation->run()) {
$this->load->model('md_users');
$this->md_users->addCliente();
$this->load->view('vw_ireserveArea');
} else {
$this->load->view('vw_ireserveArea');
}
}
}
espero muito que possam me ajudarTexto pré-formatado