Skip to content

Commit

Permalink
commit file based compatible for auth
Browse files Browse the repository at this point in the history
  • Loading branch information
yllumi committed Feb 4, 2015
1 parent 2d9cf1b commit 960ddbf
Show file tree
Hide file tree
Showing 7 changed files with 502 additions and 153 deletions.
8 changes: 4 additions & 4 deletions sites/default/users/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
"phone": "+628986818780",
"id": 1422957127,
"username": "toni haryanto",
"password": "$2y$08$6D0EKSfGuwPzKJFZlOaGpe7fAOQlCv1NxrrHTLxEWW5n8SE6xPKQe",
"password": "$2y$08$m412nWKLJFmcCBgwxgctpetJFk5nCUXJ2vLNU129IpzVXF38vgjlK",
"salt": null,
"email": "[email protected]",
"ip_address": "127.0.0.1",
"created_on": 1422957127,
"last_login": 1422957127,
"active": 1,
"groups": [
"1",
"2"
]
],
"activation_code": null
},
{
"id": 1,
Expand All @@ -30,7 +30,7 @@
"forgotten_password_time": null,
"remember_code": null,
"created_on": 1268889823,
"last_login": 1422961929,
"last_login": 1423011804,
"active": 1,
"groups": [
"1",
Expand Down
57 changes: 40 additions & 17 deletions system/application/modules/users/controllers/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@ function __construct()
{
parent::__construct();

$this->load->database();
if(! $this->config->item('filebased', 'ion_auth'))
$this->load->database();

$this->form_validation->set_error_delimiters($this->config->item('error_start_delimiter', 'ion_auth'), $this->config->item('error_end_delimiter', 'ion_auth'));

$this->lang->load('users/auth');
$this->load->helper('language');

if(! is_writable(SITE_PATH.'users/users.json') || ! is_writable(SITE_PATH.'users/groups.json'))
show_error('Files users.json and groups.json in folder '.SITE_PATH.'users/ must be writable.');
}

//redirect if needed, otherwise display the user list
function index()
{

$this->login();
if (!$this->ion_auth->logged_in())
redirect('users/auth/login');
else
redirect('panel/users');
}

//log the user in
Expand Down Expand Up @@ -102,7 +108,11 @@ function change_password()
redirect('users/auth/login', 'refresh');
}

$user = $this->ion_auth->user()->row();
if($this->config->item('filebased', 'ion_auth')){
$user = $this->ion_auth->user();
} else {
$user = $this->ion_auth->user()->row_array();
}

if ($this->form_validation->run() == false)
{
Expand Down Expand Up @@ -132,7 +142,7 @@ function change_password()
'name' => 'user_id',
'id' => 'user_id',
'type' => 'hidden',
'value' => $user->id,
'value' => $user['id'],
);

//render
Expand Down Expand Up @@ -185,20 +195,29 @@ function forgot_password()
{
// get identity from username or email
if ( $this->config->item('identity', 'ion_auth') == 'username' ){
$identity = $this->ion_auth->where('username', strtolower($this->input->post('email')))->users()->row();
if($this->config->item('filebased', 'ion_auth')){
$identity = $this->ion_auth->user_where('username', strtolower($this->input->post('email')));
} else {
$identity = $this->ion_auth->where('username', strtolower($this->input->post('email')))->users()->row_array();
}
}
else
{
$identity = $this->ion_auth->where('email', strtolower($this->input->post('email')))->users()->row();
if($this->config->item('filebased', 'ion_auth')){
$identity = $this->ion_auth->user_where('email', strtolower($this->input->post('email')));
} else {
$identity = $this->ion_auth->where('email', strtolower($this->input->post('email')))->users()->row_array();
}
}

if(empty($identity)) {
$this->ion_auth->set_message('forgot_password_email_not_found');
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect("users/auth/forgot_password", 'refresh');
}
if(empty($identity)) {
$this->ion_auth->set_message('forgot_password_email_not_found');
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect("users/auth/forgot_password", 'refresh');
}

//run the forgotten password method to email an activation code to the user
$forgotten = $this->ion_auth->forgotten_password($identity->{$this->config->item('identity', 'ion_auth')});
$forgotten = $this->ion_auth->forgotten_password($identity[$this->config->item('identity', 'ion_auth')]);

if ($forgotten)
{
Expand Down Expand Up @@ -255,7 +274,7 @@ public function reset_password($code = NULL)
'name' => 'user_id',
'id' => 'user_id',
'type' => 'hidden',
'value' => $user->id,
'value' => $user['id'],
);
$this->data['csrf'] = $this->_get_csrf_nonce();
$this->data['code'] = $code;
Expand All @@ -266,7 +285,7 @@ public function reset_password($code = NULL)
else
{
// do we have a valid request?
if ($this->_valid_csrf_nonce() === FALSE || $user->id != $this->input->post('user_id'))
if ($this->_valid_csrf_nonce() === FALSE || $user['id'] != $this->input->post('user_id'))
{

//something fishy might be up
Expand All @@ -278,7 +297,7 @@ public function reset_password($code = NULL)
else
{
// finally change the password
$identity = $user->{$this->config->item('identity', 'ion_auth')};
$identity = $user[$this->config->item('identity', 'ion_auth')];

$change = $this->ion_auth->reset_password($identity, $this->input->post('new'));

Expand Down Expand Up @@ -344,7 +363,11 @@ function deactivate($id = NULL)
{
// insert csrf check
$this->data['csrf'] = $this->_get_csrf_nonce();
$this->data['user'] = $this->ion_auth->user($id)->row();

if($this->config->item('filebased', 'ion_auth'))
$this->data['user'] = $this->ion_auth->user($id);
else
$this->data['user'] = $this->ion_auth->user($id)->row_array();

$this->_render_page('users/deactivate_user', $this->data);
}
Expand Down
Loading

0 comments on commit 960ddbf

Please sign in to comment.