PluginProbe
ShiftController Employee Shift Scheduling / 2.1.2
ShiftController Employee Shift Scheduling v2.1.2
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.1.2, at happ/application/controllers/auth.php

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