Skip to content

Commit b943039

Browse files
author
danmontgomery
committed
* View work, change in lockout logic
1 parent 12416b3 commit b943039

12 files changed

Lines changed: 465 additions & 114 deletions

File tree

application/config/bitauth.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
* Default: 1, 1, 0
6565
*/
6666
$config['pwd_complexity'] = array(
67-
'uppercase' => 1,
68-
'number' => 1,
67+
'uppercase' => 0,
68+
'number' => 0,
6969
'special' => 0
7070
);
7171

@@ -88,16 +88,24 @@
8888
$config['log_logins'] = TRUE;
8989

9090
/**
91-
* Number of invalid logins before account is locked
91+
* Number of invalid logins before account is locked.
92+
* Set this to 0 to disable this functionality.
9293
* Default: 3
9394
*/
9495
$config['invalid_logins'] = 3;
9596

97+
/**
98+
* Number of minutes between invalid login attemps where a user will be locked
99+
* out
100+
* Default: 5
101+
*/
102+
$config['mins_login_attempts'] = 5;
103+
96104
/**
97105
* Number of minutes before a locked account is unlocked.
98106
* Default: 10
99107
*/
100-
$config['lockout_time'] = 10;
108+
$config['mins_locked_out'] = 10;
101109

102110
/**
103111
* Tables used by BitAuth

application/controllers/example.php

Lines changed: 194 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,7 @@ public function __construct()
2323
}
2424

2525
/**
26-
* Example::index()
27-
*
28-
*/
29-
public function index()
30-
{
31-
if( ! $this->bitauth->logged_in())
32-
{
33-
$this->session->set_userdata('redir', 'example');
34-
redirect('example/login');
35-
}
36-
37-
$this->load->view('example/users', array('bitauth' => $this->bitauth, 'users' => $this->bitauth->get_users()));
38-
}
39-
40-
/**
41-
* Example::groups()
42-
*
43-
*/
44-
public function groups()
45-
{
46-
if( ! $this->bitauth->logged_in())
47-
{
48-
$this->session->set_userdata('redir', 'example/groups');
49-
redirect('example/login');
50-
}
51-
52-
$this->load->view('example/groups', array('bitauth' => $this->bitauth, 'groups' => $this->bitauth->get_groups()));
53-
}
54-
55-
/**
56-
* Bitauth_example::login()
26+
* Example::login()
5727
*
5828
*/
5929
public function login()
@@ -93,9 +63,201 @@ public function login()
9363
$this->load->view('example/login', $data);
9464
}
9565

66+
/**
67+
* Example::index()
68+
*
69+
*/
70+
public function index()
71+
{
72+
if( ! $this->bitauth->logged_in())
73+
{
74+
$this->session->set_userdata('redir', current_url());
75+
redirect('example/login');
76+
}
77+
78+
$this->load->view('example/users', array('bitauth' => $this->bitauth, 'users' => $this->bitauth->get_users()));
79+
}
80+
81+
/**
82+
* Example::register()
83+
*
84+
*/
85+
public function register()
86+
{
87+
if($this->input->post())
88+
{
89+
$this->form_validation->set_rules('username', 'Username', 'trim|required|bitauth_unique_username');
90+
$this->form_validation->set_rules('fullname', 'Fullname', '');
91+
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
92+
$this->form_validation->set_rules('password', 'Password', 'required|bitauth_valid_password');
93+
$this->form_validation->set_rules('password_conf', 'Password Confirmation', 'required|matches[password]');
94+
95+
if($this->form_validation->run() == TRUE)
96+
{
97+
unset($_POST['submit'], $_POST['password_conf']);
98+
$this->bitauth->add_user($this->input->post());
99+
redirect('example/login');
100+
}
101+
102+
}
103+
104+
$this->load->view('example/add_user', array('title' => 'Register'));
105+
}
106+
107+
/**
108+
* Example::add_user()
109+
*
110+
*/
111+
public function add_user()
112+
{
113+
if( ! $this->bitauth->logged_in())
114+
{
115+
$this->session->set_userdata('redir', current_url());
116+
redirect('example/login');
117+
}
118+
119+
if ( ! $this->bitauth->has_role('admin'))
120+
{
121+
$this->load->view('example/no_access');
122+
return;
123+
}
124+
125+
if($this->input->post())
126+
{
127+
$this->form_validation->set_rules('username', 'Username', 'trim|required|bitauth_unique_username');
128+
$this->form_validation->set_rules('fullname', 'Fullname', '');
129+
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
130+
$this->form_validation->set_rules('password', 'Password', 'required|bitauth_valid_password');
131+
$this->form_validation->set_rules('password_conf', 'Password Confirmation', 'required|matches[password]');
132+
133+
if($this->form_validation->run() == TRUE)
134+
{
135+
unset($_POST['submit'], $_POST['password_conf']);
136+
$this->bitauth->add_user($this->input->post());
137+
redirect('example');
138+
}
139+
140+
}
141+
142+
$this->load->view('example/add_user', array('title' => 'Add User', 'bitauth' => $this->bitauth));
143+
}
144+
145+
146+
/**
147+
* Example::edit_user()
148+
*
149+
*/
150+
public function edit_user($user_id)
151+
{
152+
if( ! $this->bitauth->logged_in())
153+
{
154+
$this->session->set_userdata('redir', current_url());
155+
redirect('example/login');
156+
}
157+
158+
if ( ! $this->bitauth->has_role('admin'))
159+
{
160+
$this->load->view('example/no_access');
161+
return;
162+
}
163+
164+
if($this->input->post())
165+
{
166+
$this->form_validation->set_rules('username', 'Username', 'trim|required|bitauth_unique_username['.$user_id.']');
167+
$this->form_validation->set_rules('fullname', 'Fullname', '');
168+
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
169+
$this->form_validation->set_rules('active', 'Active', '');
170+
$this->form_validation->set_rules('enabled', 'Enabled', '');
171+
$this->form_validation->set_rules('password_never_expires', 'Password Never Expires', '');
172+
$this->form_validation->set_rules('groups[]', 'Groups', '');
173+
174+
if($this->input->post('password'))
175+
{
176+
$this->form_validation->set_rules('password', 'Password', 'bitauth_valid_password');
177+
$this->form_validation->set_rules('password_conf', 'Password Confirmation', 'required|matches[password]');
178+
}
179+
180+
if($this->form_validation->run() == TRUE)
181+
{
182+
unset($_POST['submit'], $_POST['password_conf']);
183+
$this->bitauth->update_user($user_id, $this->input->post());
184+
redirect('example');
185+
}
186+
187+
}
188+
189+
$groups = array();
190+
foreach($this->bitauth->get_groups() as $_group)
191+
{
192+
$groups[$_group->group_id] = $_group->name;
193+
}
194+
195+
196+
$this->load->view('example/edit_user', array('bitauth' => $this->bitauth, 'groups' => $groups, 'user' => $this->bitauth->get_user_by_id($user_id)));
197+
}
198+
199+
/**
200+
* Example::groups()
201+
*
202+
*/
203+
public function groups()
204+
{
205+
if( ! $this->bitauth->logged_in())
206+
{
207+
$this->session->set_userdata('redir', current_url());
208+
redirect('example/login');
209+
}
210+
211+
$this->load->view('example/groups', array('bitauth' => $this->bitauth, 'groups' => $this->bitauth->get_groups()));
212+
}
213+
214+
/**
215+
* Example::add_group()
216+
*
217+
*/
218+
public function add_group()
219+
{
220+
if( ! $this->bitauth->logged_in())
221+
{
222+
$this->session->set_userdata('redir', current_url());
223+
redirect('example/login');
224+
}
225+
226+
if ( ! $this->bitauth->has_role('admin'))
227+
{
228+
$this->load->view('example/no_access');
229+
return;
230+
}
231+
232+
if($this->input->post())
233+
{
234+
235+
}
236+
237+
$this->load->view('example/add_group', array('roles' => $this->bitauth->get_roles(), 'users' => $this->bitauth->get_users()));
238+
}
239+
240+
/**
241+
* Example:edit_group()
242+
*
243+
*/
244+
public function edit_group($group_id)
245+
{
246+
if( ! $this->bitauth->logged_in())
247+
{
248+
$this->session->set_userdata('redir', current_url());
249+
redirect('example/login');
250+
}
251+
252+
if ( ! $this->bitauth->has_role('admin'))
253+
{
254+
$this->load->view('example/no_access');
255+
return;
256+
}
257+
}
96258

97259
/**
98-
* Bitauth_example::logout()
260+
* Example::logout()
99261
*
100262
*/
101263
public function logout()

application/language/english/bitauth_lang.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
$lang['bitauth_login_failed'] = 'Invalid %s or Password';
1919
$lang['bitauth_user_inactive'] = 'You must activate this account before you can login.';
20-
$lang['bitauth_user_locked_out'] = 'This account has been locked out.';
20+
$lang['bitauth_user_locked_out'] = 'You have been locked out for %d minutes for too many invalid login attempts, please try again later.';
2121
$lang['bitauth_pwd_expired'] = 'Your password has expired.';
2222

2323
/**
@@ -40,7 +40,8 @@
4040
/**
4141
* General Error Messages
4242
*/
43-
$lang['bitauth_data_error'] = 'You can\'t overwrite default BitAuth properties with custom userdata. Please change the name of the field: ';
43+
$lang['bitauth_instance_na'] = "BitAuth was unable to get the CodeIgniter instance.";
44+
$lang['bitauth_data_error'] = 'You can\'t overwrite default BitAuth properties with custom userdata. Please change the name of the field: %s';
4445
$lang['bitauth_enable_gmp'] = 'You must enable php_gmp to use Bitauth.';
4546
$lang['bitauth_user_not_found'] = 'User not found: %d';
4647
$lang['bitauth_activate_failed'] = 'Unable to activate user with this activation code.';

0 commit comments

Comments
 (0)