I made a simple login app that checks to see if a username/password are the username/password in the controller and if they are it gives access to the members area. I was planning on just getting it working with the set username/password and then use ldap authentication with active directory. It was working with the set username/password in the controller but then all of a sudden it just stopped and I cant see why.
When you enter credentials, no matter what you enter, the validation errors dont show, and you dont get redirected if you enter the correct username/password. It always just goes to login/authenticate and loads the login view again with no errors
Here is my view - login.php
Code:
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div style="text-align: center; margin-top:60px; color: #df0000;"><?php echo validation_errors(); ?></div>
<div style="padding-top:0px; margin-top:20px;" class="login-panel panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Please Sign In</h3>
</div>
<div class="panel-body">
<?php echo form_open('login/authenticate'); ?>
<fieldset>
<div class="form-group">
<input style="color:#333;" class="form-control" placeholder="E-mail" name="email" type="email">
</div>
<div class="form-group">
<input style="color:#333;" class="form-control" placeholder="Password" name="password" type="password" value="">
</div>
<div class="checkbox">
<label>
<input name="remember" type="checkbox" value="Remember Me">Remember Me
</label>
</div>
<!-- Change this to a button or input when using this as a form -->
<!--<a href="index.html" class="btn btn-lg btn-success btn-block">Login</a>-->
<input type="submit" style="width:100%;" class="btn btn-success btn-lg" value="Login" />
</fieldset>
<?php echo form_close(); ?>
</div>
</div>
</div>
</div>
</div>
and here is my controller ( also called login.php)
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index() {
$this->load->view('login');
}
public function authenticate() {
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required');
if($this->form_validation->run() == false) {
$this->load->view('login');
} else {
$this->verifyUser();
}
}
public function verifyUser() {
$email = $this->input->post('email');
$password = $this->input->post('password');
if($email == '[email protected]' && $password == 'password') {
redirect('main/dashboard');
}
else {
$this->form_validation->set_message('verifyUser', 'Incorrect Email or Password. Please try again.');
$this->load->view('login');
}
}
}
Thank you!