Welcome Guest, Not a member yet? Register   Sign In
flexi auth - A user authentication library for CodeIgniter
#85

[eluser]haseydesign[/eluser]
@x2blue

Here's the most basic demo example I can come up with for the basics for logging in via the flexi-auth library.

You will still need to install the demo database table and content for the example to work.
The login details are the same as given via the demo.

Once you get these basics of the library understood, you can then progress to developing your code further with validation and user redirects based on login status - as demonstrated via the demo.

controllers/your_controller.php
Code:
class Your_controller extends CI_Controller {

    function __construct()
    {
        parent::__construct();

  $this->auth = new stdClass;
  $this->load->library('flexi_auth');
}

    function login()
    {
  // If 'Login' form has been submited, attempt to log the user in.
  if ($this->input->post('login_user'))
  {
   // Verify login data.
   $result = $this->flexi_auth->login($this->input->post('login_identity'), $this->input->post('login_password'), $this->input->post('remember_me'));

   if ($result)
   {
    die('Login Successful');
   }
   else
   {
    die('Login Failed | <a href="'.$_SERVER['PHP_SELF'].'">Retry Login</a>');
   }
  }
  else
  {
   $this->load->view('login_view');
  }
    }
}

views/login_view.php
Code:
<!doctype html>
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;flexi auth login example&lt;/title&gt;
&lt;/head&gt;
&lt;body id="login"&gt;
&lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="POST"&gt;
  <label for="identity">Email or Username:</label>
  &lt;input type="text" id="identity" name="login_identity" value="[email protected]"/&gt;
  <hr>
  <label for="password">Password:</label>
  &lt;input type="password" id="password" name="login_password" value="password123"/&gt;
  <hr>
  <label for="remember_me">Remember Me:</label>
  &lt;input type="checkbox" id="remember_me" name="remember_me" value="1"/&gt;
  <hr>
  <label for="submit">Login:</label>
  &lt;input type="submit" name="login_user" id="submit" value="Submit"/&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;


Messages In This Thread
flexi auth - A user authentication library for CodeIgniter - by El Forum - 10-26-2012, 04:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB