@@ -1,34 +1,34 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Sprint |
|
4 | - * |
|
5 | - * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
|
6 | - * |
|
7 | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 | - * of this software and associated documentation files (the "Software"), to deal |
|
9 | - * in the Software without restriction, including without limitation the rights |
|
10 | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
11 | - * copies of the Software, and to permit persons to whom the Software is |
|
12 | - * furnished to do so, subject to the following conditions: |
|
13 | - * |
|
14 | - * The above copyright notice and this permission notice shall be included in |
|
15 | - * all copies or substantial portions of the Software. |
|
16 | - * |
|
17 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
18 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
19 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
20 | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
21 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22 | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
23 | - * THE SOFTWARE. |
|
24 | - * |
|
25 | - * @package Sprint |
|
26 | - * @author Lonnie Ezell |
|
27 | - * @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
|
28 | - * @license http://opensource.org/licenses/MIT (MIT) |
|
29 | - * @link http://sprintphp.com |
|
30 | - * @since Version 1.0 |
|
31 | - */ |
|
3 | + * Sprint |
|
4 | + * |
|
5 | + * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
|
6 | + * |
|
7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 | + * of this software and associated documentation files (the "Software"), to deal |
|
9 | + * in the Software without restriction, including without limitation the rights |
|
10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
11 | + * copies of the Software, and to permit persons to whom the Software is |
|
12 | + * furnished to do so, subject to the following conditions: |
|
13 | + * |
|
14 | + * The above copyright notice and this permission notice shall be included in |
|
15 | + * all copies or substantial portions of the Software. |
|
16 | + * |
|
17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
23 | + * THE SOFTWARE. |
|
24 | + * |
|
25 | + * @package Sprint |
|
26 | + * @author Lonnie Ezell |
|
27 | + * @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
|
28 | + * @license http://opensource.org/licenses/MIT (MIT) |
|
29 | + * @link http://sprintphp.com |
|
30 | + * @since Version 1.0 |
|
31 | + */ |
|
32 | 32 | |
33 | 33 | use \Myth\Route as Route; |
34 | 34 | use \Myth\Auth\LocalAuthentication as LocalAuthentication; |
@@ -36,225 +36,225 @@ discard block |
||
36 | 36 | class Auth extends \Myth\Controllers\ThemedController |
37 | 37 | { |
38 | 38 | |
39 | - public function __construct() |
|
40 | - { |
|
41 | - parent::__construct(); |
|
42 | - |
|
43 | - $this->config->load('auth'); |
|
44 | - $this->lang->load('auth'); |
|
45 | - $this->load->library('session'); |
|
46 | - } |
|
47 | - |
|
48 | - //-------------------------------------------------------------------- |
|
49 | - |
|
50 | - public function login() |
|
51 | - { |
|
52 | - $this->load->helper('form'); |
|
53 | - |
|
54 | - $auth = new LocalAuthentication(); |
|
55 | - $this->load->model('user_model'); |
|
56 | - $auth->useModel($this->user_model); |
|
57 | - |
|
58 | - $redirect_url = $this->session->userdata('redirect_url'); |
|
59 | - |
|
60 | - // No need to login again if they are already logged in... |
|
61 | - if ($auth->isLoggedIn()) |
|
62 | - { |
|
63 | - unset($_SESSION['redirect_url']); |
|
64 | - redirect($redirect_url); |
|
65 | - } |
|
66 | - |
|
67 | - if ($this->input->post()) |
|
68 | - { |
|
69 | - $post_data = [ |
|
70 | - 'email' => $this->input->post('email'), |
|
71 | - 'password' => $this->input->post('password') |
|
72 | - ]; |
|
73 | - |
|
74 | - $remember = (bool)$this->input->post('remember'); |
|
75 | - |
|
76 | - if ($auth->login($post_data, $remember)) |
|
77 | - { |
|
78 | - // Is the user being forced to reset their password? |
|
79 | - if ($auth->user()['force_pass_reset'] == 1) |
|
80 | - { |
|
81 | - redirect( Route::named('change_pass') ); |
|
82 | - } |
|
83 | - |
|
84 | - unset($_SESSION['redirect_url']); |
|
85 | - $this->setMessage(lang('auth.did_login'), 'success'); |
|
86 | - redirect($redirect_url); |
|
87 | - } |
|
88 | - |
|
89 | - $this->setMessage(lang('auth.invalid_user'), 'danger'); |
|
90 | - } |
|
91 | - |
|
92 | - $this->themer->setLayout('login'); |
|
93 | - $this->render(); |
|
94 | - } |
|
95 | - |
|
96 | - //-------------------------------------------------------------------- |
|
97 | - |
|
98 | - public function logout() |
|
99 | - { |
|
100 | - $auth = new LocalAuthentication(); |
|
101 | - $this->load->model('user_model'); |
|
102 | - $auth->useModel($this->user_model); |
|
103 | - |
|
104 | - if ($auth->isLoggedIn()) |
|
105 | - { |
|
106 | - $auth->logout(); |
|
107 | - |
|
108 | - $this->setMessage(lang('auth.did_logout'), 'success'); |
|
109 | - } |
|
110 | - |
|
111 | - redirect('/'); |
|
112 | - } |
|
113 | - |
|
114 | - //-------------------------------------------------------------------- |
|
115 | - |
|
116 | - public function register() |
|
117 | - { |
|
118 | - $this->load->helper('form'); |
|
119 | - |
|
120 | - if ($this->input->post()) |
|
121 | - { |
|
122 | - $auth = new LocalAuthentication(); |
|
123 | - $this->load->model('user_model'); |
|
124 | - $auth->useModel($this->user_model); |
|
125 | - |
|
126 | - $post_data = [ |
|
127 | - 'first_name' => $this->input->post('first_name'), |
|
128 | - 'last_name' => $this->input->post('last_name'), |
|
129 | - 'email' => $this->input->post('email'), |
|
130 | - 'username' => $this->input->post('username'), |
|
131 | - 'password' => $this->input->post('password'), |
|
132 | - 'pass_confirm' => $this->input->post('pass_confirm') |
|
133 | - ]; |
|
134 | - |
|
135 | - if ($auth->registerUser($post_data)) |
|
136 | - { |
|
137 | - $this->setMessage(lang('auth.did_register'), 'success'); |
|
138 | - redirect( Route::named('login') ); |
|
139 | - } |
|
140 | - else |
|
141 | - { |
|
142 | - $this->setMessage($auth->error(), 'danger'); |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - $this->addScript('register.js'); |
|
147 | - $this->themer->setLayout('login'); |
|
148 | - $this->render(); |
|
149 | - } |
|
150 | - |
|
151 | - //-------------------------------------------------------------------- |
|
152 | - |
|
153 | - public function activate_user() |
|
154 | - { |
|
155 | - $this->load->helper('form'); |
|
156 | - |
|
157 | - if ($this->input->post()) |
|
158 | - { |
|
159 | - $auth = new LocalAuthentication(); |
|
160 | - $this->load->model('user_model'); |
|
161 | - $auth->useModel($this->user_model); |
|
162 | - |
|
163 | - $post_data = [ |
|
164 | - 'email' => $this->input->post('email'), |
|
165 | - 'code' => $this->input->post('code') |
|
166 | - ]; |
|
167 | - |
|
168 | - if ($auth->activateUser($post_data)) |
|
169 | - { |
|
170 | - $this->setMessage(lang('auth.did_activate'), 'success'); |
|
171 | - redirect( Route::named('login') ); |
|
172 | - } |
|
173 | - else |
|
174 | - { |
|
175 | - $this->setMessage($auth->error(), 'danger'); |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - $data = [ |
|
180 | - 'email' => $this->input->get('e'), |
|
181 | - 'code' => $this->input->get('code') |
|
182 | - ]; |
|
183 | - |
|
184 | - $this->themer->setLayout('login'); |
|
185 | - $this->render($data); |
|
186 | - } |
|
187 | - |
|
188 | - //-------------------------------------------------------------------- |
|
189 | - |
|
190 | - |
|
191 | - public function forgot_password() |
|
192 | - { |
|
193 | - $this->load->helper('form'); |
|
194 | - |
|
195 | - if ($this->input->post()) |
|
196 | - { |
|
197 | - $auth = new LocalAuthentication(); |
|
198 | - $this->load->model('user_model'); |
|
199 | - $auth->useModel($this->user_model); |
|
200 | - |
|
201 | - if ($auth->remindUser($this->input->post('email'))) |
|
202 | - { |
|
203 | - $this->setMessage(lang('auth.send_success'), 'success'); |
|
204 | - redirect( Route::named('reset_pass') ); |
|
205 | - } |
|
206 | - else |
|
207 | - { |
|
208 | - $this->setMessage($auth->error(), 'danger'); |
|
209 | - } |
|
210 | - } |
|
211 | - |
|
212 | - $this->themer->setLayout('login'); |
|
213 | - $this->render(); |
|
214 | - } |
|
215 | - |
|
216 | - //-------------------------------------------------------------------- |
|
217 | - |
|
218 | - public function reset_password() |
|
219 | - { |
|
220 | - $this->load->helper('form'); |
|
221 | - |
|
222 | - if ($this->input->post()) |
|
223 | - { |
|
224 | - $auth = new LocalAuthentication(); |
|
225 | - $this->load->model('user_model'); |
|
226 | - $auth->useModel($this->user_model); |
|
227 | - |
|
228 | - $credentials = [ |
|
229 | - 'email' => $this->input->post('email'), |
|
230 | - 'code' => $this->input->post('code') |
|
231 | - ]; |
|
232 | - |
|
233 | - $password = $this->input->post('password'); |
|
234 | - $pass_confirm = $this->input->post('pass_confirm'); |
|
235 | - |
|
236 | - if ($auth->resetPassword($credentials, $password, $pass_confirm)) |
|
237 | - { |
|
238 | - $this->setMessage(lang('auth.new_password_success'), 'success'); |
|
239 | - redirect( Route::named('login') ); |
|
240 | - } |
|
241 | - else |
|
242 | - { |
|
243 | - $this->setMessage($auth->error(), 'danger'); |
|
244 | - } |
|
245 | - } |
|
246 | - |
|
247 | - $data = [ |
|
248 | - 'email' => $this->input->get('e'), |
|
249 | - 'code' => $this->input->get('code') |
|
250 | - ]; |
|
251 | - |
|
252 | - $this->addScript('register.js'); |
|
253 | - $this->themer->setLayout('login'); |
|
254 | - $this->render($data); |
|
255 | - } |
|
256 | - |
|
257 | - //-------------------------------------------------------------------- |
|
39 | + public function __construct() |
|
40 | + { |
|
41 | + parent::__construct(); |
|
42 | + |
|
43 | + $this->config->load('auth'); |
|
44 | + $this->lang->load('auth'); |
|
45 | + $this->load->library('session'); |
|
46 | + } |
|
47 | + |
|
48 | + //-------------------------------------------------------------------- |
|
49 | + |
|
50 | + public function login() |
|
51 | + { |
|
52 | + $this->load->helper('form'); |
|
53 | + |
|
54 | + $auth = new LocalAuthentication(); |
|
55 | + $this->load->model('user_model'); |
|
56 | + $auth->useModel($this->user_model); |
|
57 | + |
|
58 | + $redirect_url = $this->session->userdata('redirect_url'); |
|
59 | + |
|
60 | + // No need to login again if they are already logged in... |
|
61 | + if ($auth->isLoggedIn()) |
|
62 | + { |
|
63 | + unset($_SESSION['redirect_url']); |
|
64 | + redirect($redirect_url); |
|
65 | + } |
|
66 | + |
|
67 | + if ($this->input->post()) |
|
68 | + { |
|
69 | + $post_data = [ |
|
70 | + 'email' => $this->input->post('email'), |
|
71 | + 'password' => $this->input->post('password') |
|
72 | + ]; |
|
73 | + |
|
74 | + $remember = (bool)$this->input->post('remember'); |
|
75 | + |
|
76 | + if ($auth->login($post_data, $remember)) |
|
77 | + { |
|
78 | + // Is the user being forced to reset their password? |
|
79 | + if ($auth->user()['force_pass_reset'] == 1) |
|
80 | + { |
|
81 | + redirect( Route::named('change_pass') ); |
|
82 | + } |
|
83 | + |
|
84 | + unset($_SESSION['redirect_url']); |
|
85 | + $this->setMessage(lang('auth.did_login'), 'success'); |
|
86 | + redirect($redirect_url); |
|
87 | + } |
|
88 | + |
|
89 | + $this->setMessage(lang('auth.invalid_user'), 'danger'); |
|
90 | + } |
|
91 | + |
|
92 | + $this->themer->setLayout('login'); |
|
93 | + $this->render(); |
|
94 | + } |
|
95 | + |
|
96 | + //-------------------------------------------------------------------- |
|
97 | + |
|
98 | + public function logout() |
|
99 | + { |
|
100 | + $auth = new LocalAuthentication(); |
|
101 | + $this->load->model('user_model'); |
|
102 | + $auth->useModel($this->user_model); |
|
103 | + |
|
104 | + if ($auth->isLoggedIn()) |
|
105 | + { |
|
106 | + $auth->logout(); |
|
107 | + |
|
108 | + $this->setMessage(lang('auth.did_logout'), 'success'); |
|
109 | + } |
|
110 | + |
|
111 | + redirect('/'); |
|
112 | + } |
|
113 | + |
|
114 | + //-------------------------------------------------------------------- |
|
115 | + |
|
116 | + public function register() |
|
117 | + { |
|
118 | + $this->load->helper('form'); |
|
119 | + |
|
120 | + if ($this->input->post()) |
|
121 | + { |
|
122 | + $auth = new LocalAuthentication(); |
|
123 | + $this->load->model('user_model'); |
|
124 | + $auth->useModel($this->user_model); |
|
125 | + |
|
126 | + $post_data = [ |
|
127 | + 'first_name' => $this->input->post('first_name'), |
|
128 | + 'last_name' => $this->input->post('last_name'), |
|
129 | + 'email' => $this->input->post('email'), |
|
130 | + 'username' => $this->input->post('username'), |
|
131 | + 'password' => $this->input->post('password'), |
|
132 | + 'pass_confirm' => $this->input->post('pass_confirm') |
|
133 | + ]; |
|
134 | + |
|
135 | + if ($auth->registerUser($post_data)) |
|
136 | + { |
|
137 | + $this->setMessage(lang('auth.did_register'), 'success'); |
|
138 | + redirect( Route::named('login') ); |
|
139 | + } |
|
140 | + else |
|
141 | + { |
|
142 | + $this->setMessage($auth->error(), 'danger'); |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + $this->addScript('register.js'); |
|
147 | + $this->themer->setLayout('login'); |
|
148 | + $this->render(); |
|
149 | + } |
|
150 | + |
|
151 | + //-------------------------------------------------------------------- |
|
152 | + |
|
153 | + public function activate_user() |
|
154 | + { |
|
155 | + $this->load->helper('form'); |
|
156 | + |
|
157 | + if ($this->input->post()) |
|
158 | + { |
|
159 | + $auth = new LocalAuthentication(); |
|
160 | + $this->load->model('user_model'); |
|
161 | + $auth->useModel($this->user_model); |
|
162 | + |
|
163 | + $post_data = [ |
|
164 | + 'email' => $this->input->post('email'), |
|
165 | + 'code' => $this->input->post('code') |
|
166 | + ]; |
|
167 | + |
|
168 | + if ($auth->activateUser($post_data)) |
|
169 | + { |
|
170 | + $this->setMessage(lang('auth.did_activate'), 'success'); |
|
171 | + redirect( Route::named('login') ); |
|
172 | + } |
|
173 | + else |
|
174 | + { |
|
175 | + $this->setMessage($auth->error(), 'danger'); |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + $data = [ |
|
180 | + 'email' => $this->input->get('e'), |
|
181 | + 'code' => $this->input->get('code') |
|
182 | + ]; |
|
183 | + |
|
184 | + $this->themer->setLayout('login'); |
|
185 | + $this->render($data); |
|
186 | + } |
|
187 | + |
|
188 | + //-------------------------------------------------------------------- |
|
189 | + |
|
190 | + |
|
191 | + public function forgot_password() |
|
192 | + { |
|
193 | + $this->load->helper('form'); |
|
194 | + |
|
195 | + if ($this->input->post()) |
|
196 | + { |
|
197 | + $auth = new LocalAuthentication(); |
|
198 | + $this->load->model('user_model'); |
|
199 | + $auth->useModel($this->user_model); |
|
200 | + |
|
201 | + if ($auth->remindUser($this->input->post('email'))) |
|
202 | + { |
|
203 | + $this->setMessage(lang('auth.send_success'), 'success'); |
|
204 | + redirect( Route::named('reset_pass') ); |
|
205 | + } |
|
206 | + else |
|
207 | + { |
|
208 | + $this->setMessage($auth->error(), 'danger'); |
|
209 | + } |
|
210 | + } |
|
211 | + |
|
212 | + $this->themer->setLayout('login'); |
|
213 | + $this->render(); |
|
214 | + } |
|
215 | + |
|
216 | + //-------------------------------------------------------------------- |
|
217 | + |
|
218 | + public function reset_password() |
|
219 | + { |
|
220 | + $this->load->helper('form'); |
|
221 | + |
|
222 | + if ($this->input->post()) |
|
223 | + { |
|
224 | + $auth = new LocalAuthentication(); |
|
225 | + $this->load->model('user_model'); |
|
226 | + $auth->useModel($this->user_model); |
|
227 | + |
|
228 | + $credentials = [ |
|
229 | + 'email' => $this->input->post('email'), |
|
230 | + 'code' => $this->input->post('code') |
|
231 | + ]; |
|
232 | + |
|
233 | + $password = $this->input->post('password'); |
|
234 | + $pass_confirm = $this->input->post('pass_confirm'); |
|
235 | + |
|
236 | + if ($auth->resetPassword($credentials, $password, $pass_confirm)) |
|
237 | + { |
|
238 | + $this->setMessage(lang('auth.new_password_success'), 'success'); |
|
239 | + redirect( Route::named('login') ); |
|
240 | + } |
|
241 | + else |
|
242 | + { |
|
243 | + $this->setMessage($auth->error(), 'danger'); |
|
244 | + } |
|
245 | + } |
|
246 | + |
|
247 | + $data = [ |
|
248 | + 'email' => $this->input->get('e'), |
|
249 | + 'code' => $this->input->get('code') |
|
250 | + ]; |
|
251 | + |
|
252 | + $this->addScript('register.js'); |
|
253 | + $this->themer->setLayout('login'); |
|
254 | + $this->render($data); |
|
255 | + } |
|
256 | + |
|
257 | + //-------------------------------------------------------------------- |
|
258 | 258 | |
259 | 259 | /** |
260 | 260 | * Allows a logged in user to enter their current password |
@@ -320,24 +320,24 @@ discard block |
||
320 | 320 | //-------------------------------------------------------------------- |
321 | 321 | |
322 | 322 | |
323 | - //-------------------------------------------------------------------- |
|
324 | - // AJAX Methods |
|
325 | - //-------------------------------------------------------------------- |
|
323 | + //-------------------------------------------------------------------- |
|
324 | + // AJAX Methods |
|
325 | + //-------------------------------------------------------------------- |
|
326 | 326 | |
327 | - /** |
|
328 | - * Checks the password strength and returns pass/fail. |
|
329 | - * |
|
330 | - * @param $str |
|
331 | - */ |
|
332 | - public function password_check($str) |
|
333 | - { |
|
334 | - $this->load->helper('auth/password'); |
|
327 | + /** |
|
328 | + * Checks the password strength and returns pass/fail. |
|
329 | + * |
|
330 | + * @param $str |
|
331 | + */ |
|
332 | + public function password_check($str) |
|
333 | + { |
|
334 | + $this->load->helper('auth/password'); |
|
335 | 335 | |
336 | - $strength = isStrongPassword($str); |
|
336 | + $strength = isStrongPassword($str); |
|
337 | 337 | |
338 | - $this->renderJSON(['status' => $strength ? 'pass' : 'fail']); |
|
339 | - } |
|
338 | + $this->renderJSON(['status' => $strength ? 'pass' : 'fail']); |
|
339 | + } |
|
340 | 340 | |
341 | - //-------------------------------------------------------------------- |
|
341 | + //-------------------------------------------------------------------- |
|
342 | 342 | |
343 | 343 | } |