Implement basic authentication
TODO: Forgot password, Registration, and so on
This commit is contained in:
@@ -46,14 +46,11 @@ class Auth extends CI_Controller {
|
|||||||
|
|
||||||
if ($this->access->login($this->input->post('username'), $this->input->post('password'), $remember)) {
|
if ($this->access->login($this->input->post('username'), $this->input->post('password'), $remember)) {
|
||||||
$this->data['success'] = true;
|
$this->data['success'] = true;
|
||||||
|
redirect('dashboard', 'refresh');
|
||||||
} else { // if the login was un-successful
|
} else { // if the login was un-successful
|
||||||
$this->data['success'] = false;
|
$this->data['success'] = false;
|
||||||
$this->data['message'] = $this->access->errors();
|
$this->data['message'] = $this->access->errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
// output JSON data
|
|
||||||
$this->output->set_content_type('application/json')
|
|
||||||
->set_output(json_encode($this->data));
|
|
||||||
} else {
|
} else {
|
||||||
$this->data['message'] = validation_errors() ? validation_errors() : null;
|
$this->data['message'] = validation_errors() ? validation_errors() : null;
|
||||||
$this->data['username'] = $this->form_validation->set_value('username');
|
$this->data['username'] = $this->form_validation->set_value('username');
|
||||||
@@ -68,9 +65,7 @@ class Auth extends CI_Controller {
|
|||||||
public function logout() {
|
public function logout() {
|
||||||
$logout = $this->access->logout();
|
$logout = $this->access->logout();
|
||||||
|
|
||||||
// output JSON data
|
redirect(base_url(), 'refresh');
|
||||||
$this->output->set_content_type('application/json')
|
|
||||||
->set_output(json_encode(array('success' => true)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,7 +73,7 @@ class Auth extends CI_Controller {
|
|||||||
*/
|
*/
|
||||||
public function register() {
|
public function register() {
|
||||||
if ($this->access->loggedIn()) {
|
if ($this->access->loggedIn()) {
|
||||||
redirect('welcome');
|
redirect('dashboard');
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate form input
|
// validate form input
|
||||||
|
|||||||
67
application/views/auth/login.php
Normal file
67
application/views/auth/login.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml"><head>
|
||||||
|
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
|
||||||
|
<title>ScattPort | Login</title>
|
||||||
|
|
||||||
|
<?=link_tag('assets/css/style.css');?>
|
||||||
|
<?=link_tag('assets/css/table.css');?>
|
||||||
|
<?=link_tag('assets/css/form.css');?>
|
||||||
|
|
||||||
|
<?=script_tag('assets/js/minmax.js');?>
|
||||||
|
<?=script_tag('https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js');?>
|
||||||
|
<?=script_tag('assets/js/scattport.js');?>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="header">
|
||||||
|
|
||||||
|
<h1><a href="<?=base_url()?>"><img src="<?=site_url('assets/images/logo.gif')?>" /></a></h1>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="wrapper">
|
||||||
|
|
||||||
|
<?
|
||||||
|
if(isset($error))
|
||||||
|
foreach($error as $e) echo "<div class=\"error\">".$e."</div>";
|
||||||
|
if(isset($notice))
|
||||||
|
foreach($notice as $n) echo "<div class=\"notice\">".$n."</div>";
|
||||||
|
if(isset($success))
|
||||||
|
foreach($success as $s) echo "<div class=\"success\">".$s."</div>";
|
||||||
|
?>
|
||||||
|
<div id="content">
|
||||||
|
|
||||||
|
<div class="title">
|
||||||
|
<h2>Login</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
<form action="<?=site_url('auth/login')?>" method="post" name="loginform">
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<h4>Benutzername</h4>
|
||||||
|
<input type="text" name="username" />
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<h4>Passwort</h4>
|
||||||
|
<input type="password" name="password" />
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#" onclick="document.forms.loginform.submit()" class="button big">Login</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div id="footer">
|
||||||
|
<span class="left"><a href="#">Dashboard</a> | <a href="#">Link</a> | <a href="#">Link</a> | <a href="#">Link</a></span>
|
||||||
|
<span class="right">© 2011 Karsten Heiken.</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user