Merge branch 'master' of disposed.de:scattport

This commit is contained in:
Karsten Heiken
2011-04-22 01:04:44 +02:00
5 changed files with 33 additions and 93 deletions

View File

@@ -30,7 +30,7 @@ class Auth extends CI_Controller {
}
/**
* Logs the user in.
* Logs the user in - or not ;-)
*/
public function login() {
if ($this->access->loggedIn()) {
@@ -41,53 +41,28 @@ class Auth extends CI_Controller {
$this->form_validation->set_rules('username', "Benutzername", 'required');
$this->form_validation->set_rules('password', "Passwort", 'required');
if ($this->form_validation->run() == true) { //check to see if the user is logging in
if ($this->form_validation->run() == true) {
// check for "remember me"
$remember = (boolean) $this->input->post('remember');
if ($this->access->login($this->input->post('username'), $this->input->post('password'), $remember)) { //if the login is successful
//redirect them back to the home page
$this->session->set_flashdata('message', $this->access->messages());
redirect('', 'refresh');
if ($this->access->login($this->input->post('username'), $this->input->post('password'), $remember)) {
$this->data['success'] = true;
} else { // if the login was un-successful
//redirect them back to the login page
$this->session->set_flashdata('message', $this->access->errors());
//redirect('auth/login', 'refresh'); //use redirects instead of loading views for compatibility with MY_Controller libraries
echo "{success: false}";
$this->data['success'] = false;
$this->data['message'] = $this->access->errors();
}
} else { //the user is not logging in so display the login page
//set the flash data error message if there is one
$this->data['message'] = validation_errors() ? validation_errors() : $this->session->flashdata('message');
// output json data
$this->output->set_content_type('application/json')
->set_output(json_encode($this->data));
} else {
$this->data['message'] = validation_errors() ? validation_errors() : null;
$this->data['username'] = $this->form_validation->set_value('username');
$this->load->view('auth/login', $this->data);
}
}
/**
* Logs the user in - or not ;-)
*/
public function do_login() {
$this->form_validation->set_rules('username', "Benutzername", 'required');
$this->form_validation->set_rules('password', "Passwort", 'required');
if ($this->form_validation->run() == true) {
$remember = (boolean) $this->input->post('remember');
if ($this->access->login($this->input->post('username'), $this->input->post('password'), $remember)) {
$this->session->set_flashdata('message', $this->access->messages());
$return['success'] = true;
} else { // if the login was un-successful
$this->session->set_flashdata('message', $this->access->errors());
$return['success'] = false;
$return['message'] = "Benutzername oder PW falsch";
}
}
$this->output->set_content_type('application/json')
->set_output(json_encode($return));
}
/**
* Logs the user out.
*/
@@ -229,31 +204,6 @@ class Auth extends CI_Controller {
}
}
private function _get_csrf_nonce() {
$this->load->helper('string');
$key = random_string('alnum', 8);
$value = random_string('alnum', 20);
$this->session->set_flashdata('csrfkey', $key);
$this->session->set_flashdata('csrfvalue', $value);
return array($key => $value);
}
private function _valid_csrf_nonce() {
if ($this->input->post($this->session->flashdata('csrfkey')) !== false &&
$this->input->post($this->session->flashdata('csrfkey')) == $this->session->flashdata('csrfvalue')) {
return true;
} else {
return false;
}
}
/**
* Logs the user out.
*/
public function do_logout() {
echo "{success: true}";
}
}
/* End of file auth.php */

View File

@@ -9,7 +9,7 @@ $lang['password_change_unsuccessful'] = "Unable to change password";
$lang['forgot_password_successful'] = "Password reset email sent";
$lang['forgot_password_unsuccessful'] = "Unable to reset password";
$lang['login_successful'] = "Logged in successfully";
$lang['login_unsuccessful'] = "In-correct login";
$lang['login_unsuccessful'] = "Incorrect username or password";
$lang['logout_successful'] = "Logged out successfully";
$lang['update_successful'] = "Account information successfully updated";
$lang['update_unsuccessful'] = "Unable to update account information";

View File

@@ -8,9 +8,9 @@ $lang['password_change_successful'] = "Password successfully changed";
$lang['password_change_unsuccessful'] = "Unable to change password";
$lang['forgot_password_successful'] = "Password reset email sent";
$lang['forgot_password_unsuccessful'] = "Unable to reset password";
$lang['login_successful'] = "Logged in successfully";
$lang['login_unsuccessful'] = "In-correct login";
$lang['logout_successful'] = "Logged out successfully";
$lang['login_successful'] = "Erfolgreich eingeloggt";
$lang['login_unsuccessful'] = "Benutzername oder Passwort falsch";
$lang['logout_successful'] = "Erfolgreich ausgeloggt";
$lang['update_successful'] = "Account information successfully updated";
$lang['update_unsuccessful'] = "Unable to update account information";
$lang['delete_successful'] = "User deleted";

View File

@@ -8,29 +8,22 @@
class Access {
/**
* CodeIgniter global
*
* @var string
**/
* Contains the CI instance.
*/
protected $ci;
protected $message_start_delimiter = '<p>';
protected $message_end_delimiter = '</p>';
protected $error_start_delimiter = '<p>';
protected $error_end_delimiter = '</p>';
/**
* message (uses lang file)
* Contains occured messages (using the language file).
*
* @var string
**/
*/
protected $messages = array();
/**
* error message (uses lang file)
* Contains occured errors (using the language file).
*
* @var string
**/
*/
protected $errors = array();
/**
@@ -45,9 +38,6 @@ class Access {
$this->ci->load->model('group');
$this->ci->load->helper('cookie');
$this->messages = array();
$this->errors = array();
// auto-login the user if they are remembered
if (!$this->loggedIn() && get_cookie('username') && get_cookie('remember_code')) {
$this->ci->access = $this;
@@ -179,11 +169,11 @@ class Access {
if ($this->ci->user->login($username, $password, $remember)) {
$this->setMessage('login_successful');
return true;
}
} else {
$this->setError('login_unsuccessful');
return false;
}
}
/**
* Logs the user out.
@@ -297,12 +287,12 @@ class Access {
* @return void
*/
public function messages() {
$_output = '';
$output = '';
foreach ($this->messages as $message) {
$_output .= $this->message_start_delimiter . $this->ci->lang->line($message) . $this->message_end_delimiter;
$output .= lang($message) . '<br />';
}
return $_output;
return $output;
}
/**
@@ -321,12 +311,12 @@ class Access {
* @return void
*/
public function errors() {
$_output = '';
$output = '';
foreach ($this->errors as $error) {
$_output .= $this->error_start_delimiter . $this->ci->lang->line($error) . $this->error_end_delimiter;
$output .= lang($error) . '<br />';
}
return $_output;
return $output;
}
}

View File

@@ -25,7 +25,7 @@ var loginForm = new Ext.form.FormPanel({
border: false,
width: 340,
labelWidth: 120,
url: BASE_URL + 'auth/do_login',
url: BASE_URL + 'auth/login',
method: 'POST',
items: [
new Ext.form.TextField({