PluginProbe
ShiftController Employee Shift Scheduling / 2.2.5
ShiftController Employee Shift Scheduling v2.2.5
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / happ / application / controllers / auth.php

auth.php in ShiftController Employee Shift Scheduling 2.2.5, at happ/application/controllers/auth.php

275 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php defined('BASEPATH') OR exit('No direct script access allowed');
2 class Auth_controller extends Front_Controller {
3 function __construct()
4 {
5 $this->conf = array(
6 'path' => 'wall',
7 );
8 parent::__construct();
9 $this->load->helper('url');
10 $this->load->library('form_validation', 'hc_bootstrap');
11 $this->load->library( 'hc_form' );
12
13 $app = $this->config->item('nts_app');
14 if(
15 isset($GLOBALS['NTS_CONFIG'][$app]) &&
16 isset($GLOBALS['NTS_CONFIG'][$app]['REMOTE_INTEGRATION']) &&
17 $GLOBALS['NTS_CONFIG'][$app]['REMOTE_INTEGRATION']
18 )
19 {
20 $user_id = 0;
21 if( $test_user = $this->auth->user() )
22 {
23 $user_id = $test_user->id;
24 }
25 if( ! $user_id )
26 {
27 Modules::run( $GLOBALS['NTS_CONFIG'][$app]['REMOTE_INTEGRATION'] . '/auth/login' );
28 }
29 }
30 }
31
32 function index()
33 {
34 if( ! $this->auth->check() )
35 {
36 //redirect them to the login page
37 ci_redirect('auth/login', 'refresh');
38 }
39 return;
40 }
41
42 function notallowed()
43 {
44 $this->data['include'] = 'auth/notallowed';
45 $this->load->view( $this->template, $this->data);
46 }
47
48 function login()
49 {
50 $this->data['title'] = "Login";
51
52 //validate form input
53 $this->form_validation->set_rules('identity', 'lang:common_email', 'required');
54 $this->form_validation->set_rules('password', 'lang:common_password', 'required');
55
56 if ($this->form_validation->run() == true)
57 {
58 //check to see if the user is logging in
59 //check for "remember me"
60 $remember = (bool) $this->input->post('remember');
61
62 if ($this->auth->attempt($this->input->post('identity'), $this->input->post('password'), $remember))
63 {
64 // check if not archived
65 if( ! $this->auth->user()->active )
66 {
67 $this->auth->logout();
68 $this->session->set_flashdata('error', lang('login_unsuccessful_archived'));
69 ci_redirect('auth/login');
70 }
71 else
72 {
73 // $this->session->set_flashdata('message', lang('login_successful'));
74 ci_redirect('');
75 }
76 }
77 else
78 {
79 //if the login was un-successful
80 //redirect them back to the login page
81 $this->session->set_flashdata('error', lang('login_unsuccessful'));
82 ci_redirect('auth/login');
83 }
84 }
85 else
86 {
87 //the user is not logging in so display the login page
88 //set the flash data error message if there is one
89 $this->data['auth_message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
90
91 $this->data['identity'] = array(
92 'name' => 'identity',
93 'id' => 'identity',
94 'type' => 'text',
95 'value' => $this->form_validation->set_value('identity'),
96 );
97 $this->data['password'] = array(
98 'name' => 'password',
99 'id' => 'password',
100 'type' => 'password',
101 );
102
103 $this->data['include'] = 'auth/login';
104 $this->load->view( $this->template, $this->data);
105 }
106 }
107
108 function logout()
109 {
110 $logout = $this->auth->logout();
111 $this->session->set_flashdata('message', lang('logged_out'));
112 ci_redirect('');
113 }
114
115 //change password
116 function password()
117 {
118 $min_password_length = 2;
119 $max_password_length = 20;
120 $new_password = $this->input->post('new');
121 $this->form_validation->set_rules('new', lang('common_new_password'), 'required|min_length[' . $min_password_length . ']|max_length[' . $max_password_length . ']|matches[new_confirm]');
122 $this->form_validation->set_rules('new_confirm', lang('common_password_confirm'), 'required');
123
124 if ( ! $this->auth->check())
125 {
126 ci_redirect('auth/login', 'refresh');
127 }
128
129 if ($this->form_validation->run() == false)
130 {
131 $errors = array();
132 if( form_error('new') )
133 $errors['new'] = form_error('new');
134 if( form_error('new_confirm') )
135 $errors['new_confirm'] = form_error('new_confirm');
136
137 $this->hc_form->set_errors( $errors );
138 $this->hc_form->set_default( 'new', $this->input->post('new') );
139 $this->hc_form->set_default( 'new_confirm', $this->input->post('new_confirm') );
140
141 //display the form
142 //set the flash data error message if there is one
143 $this->data['email'] = array(
144 'name' => 'email',
145 'id' => 'email',
146 'type' => 'text',
147 );
148
149 $this->data['min_password_length'] = $min_password_length;
150 $this->data['old_password'] = array(
151 'name' => 'old',
152 'id' => 'old',
153 'type' => 'password',
154 );
155 $this->data['new_password'] = array(
156 'label' => 'lang:common_new_password',
157 'name' => 'new',
158 'id' => 'new',
159 'type' => 'password',
160 );
161 $this->data['new_password_confirm'] = array(
162 'label' => 'lang:common_password_confirm',
163 'name' => 'new_confirm',
164 'id' => 'new_confirm',
165 'type' => 'password',
166 );
167
168 //render
169 $this->data['include'] = 'auth/password';
170 $this->data['include_submenu'] = 'auth/password_menu';
171 $this->load->view( $this->template, $this->data);
172 }
173 else
174 {
175 $msg = array();
176 $new_password = $this->input->post('new');
177 if( $new_password ){
178 $change = $this->auth->change_password($new_password);
179 if ($change)
180 {
181 $msg[] = lang('auth_password_change_successful');
182 }
183 else
184 {
185 $msg[] = $this->auth->error;
186 }
187 }
188
189 $msg = join( '<br/>', $msg );
190 $this->session->set_flashdata('message', $msg);
191 ci_redirect('auth/profile');
192 }
193 }
194
195 function profile()
196 {
197 $email = $this->auth->user()->email;
198 $this->form_validation->set_rules('email', lang('common_email'), 'required|valid_email');
199
200 if ( ! $this->auth->check())
201 {
202 ci_redirect('auth/login', 'refresh');
203 }
204
205 $this->hc_form->set_defaults( array('email' => $email) );
206
207 if ($this->form_validation->run() == false)
208 {
209 //display the form
210 //set the flash data error message if there is one
211 $this->data['email'] = array(
212 'name' => 'email',
213 'id' => 'email',
214 'type' => 'text',
215 );
216
217 //render
218 $this->data['include'] = 'auth/profile';
219 $this->data['include_submenu'] = 'auth/profile_menu';
220 $this->load->view( $this->template, $this->data);
221 }
222 else
223 {
224 $msg = array();
225 $new_email = $this->input->post('email');
226 if( $new_email != $email ){
227 $this->auth->user()->email = $new_email;
228 $this->auth->user()->save();
229 $msg[] = lang('profile_updated');
230 }
231
232 $msg = join( '<br/>', $msg );
233 $this->session->set_flashdata('message', $msg);
234 ci_redirect('auth/profile');
235 }
236 }
237
238 //forgot password
239 function forgot_password()
240 {
241 $this->form_validation->set_rules('email', 'Email Address', 'required');
242 if ($this->form_validation->run() == false)
243 {
244 //setup the input
245 $this->data['email'] = array('name' => 'email',
246 'id' => 'email',
247 );
248
249 //set any errors and display the form
250 $this->data['auth_message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
251
252 $this->data['include'] = 'auth/forgot_password';
253 $this->load->view( $this->template, $this->data);
254 }
255 else
256 {
257 $supplied_email = $this->input->post('email');
258 //run the forgotten password method to email new one to the user
259 $forgotten = $this->auth->forgotten_password($supplied_email);
260
261 if ($forgotten)
262 {
263 //if there were no errors
264 $this->session->set_flashdata('message', lang('auth_forgot_password_successful'));
265 ci_redirect("auth/login", 'refresh'); //we should display a confirmation page here instead of the login page
266 }
267 else
268 {
269 $this->session->set_flashdata('message', $this->auth->error);
270 ci_redirect("auth/forgot_password", 'refresh');
271 }
272 }
273 }
274 }
275