/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to codeigniter/application/models/user.php

  • Committer: b11johgu
  • Date: 2013-05-14 12:30:38 UTC
  • mto: This revision was merged to the branch mainline in revision 65.
  • Revision ID: b11johgu@student.his.se-20130514123038-rthxj3f34o32gpxy
ExamplesController:
- Added expand/collapse arrows for categories/subcategories.
- Added category positioning (incomplete).

more general changes made.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
                        
30
30
                        //If a matching DB record is found.
31
31
                        if($result) {
32
 
                            foreach($result as $row) {
33
 
                                $hint = $row->passwdHint;
34
 
                                
35
 
                                //Return hint
36
 
                                return $hint;
37
 
                            }
 
32
                                foreach($result as $row) {
 
33
                                        $hint = $row->passwdHint;
 
34
                                        
 
35
                                        //Return hint
 
36
                                        return $hint;
 
37
                                }
38
38
                        }
39
39
                        
40
40
                        //No such user
51
51
                        $hash = $this->getSaltedHash($password);
52
52
        
53
53
                        //Query-structure
54
 
                        $this->db->select('userName, name, passwd, userType, ssn');
 
54
                        $this->db->select('userName, name, passwd, userType, ssn'); // Tog bort firstLogin här.
55
55
                        $this->db->from('Users');
56
56
                        $this->db->where('userName', $username);
57
57
                        $this->db->where('passwd', $hash);
70
70
                                                'username' => $row->userName,
71
71
                                                'name' => $row->name,
72
72
                                                'usertype' => $row->userType,
73
 
                                                'ssn' => $row->ssn
 
73
                                                'ssn' => $row->ssn,
 
74
                                        //      'firstLogin' => $row->firstLogin
74
75
                                        );
75
76
                                }
76
77
                                
95
96
                /*
96
97
                 *      This function logs the user out.
97
98
                 *  RESTRICTED-LEVEL: Self
98
 
                 */ 
99
 
                public function logout() {              
 
99
                 */
 
100
                public function logout() {
100
101
                        //Unset session data
101
102
                        $this->session->unset_userdata('authenticated');
102
103
                }
103
 
                
 
104
 
104
105
 
105
106
                /*
106
107
                 *      This function changes the users password.
107
108
                 *  RESTRICTED-LEVEL: Self
108
 
                 */ 
 
109
                 */
109
110
                public function changePassword($pwdOld, $pwdNew, $pwdHint) {
110
111
                        //Check that a user is logged in.
111
112
                        if($this->isLoggedIn()) {
133
134
                                        $this->db->update('Users', $data);
134
135
                                        
135
136
                                        //Return Success!
136
 
                                        return TRUE;                                                    
 
137
                                        return TRUE;
137
138
                                }
138
139
                        }
139
140
                        
165
166
                                if($result) {
166
167
                                        //Return success
167
168
                                        return TRUE;
168
 
                                } 
 
169
                                }
169
170
                        }
170
171
                        
171
172
                        //Return error
172
173
                        return FALSE;
173
174
                }
174
 
                
175
 
                
 
175
 
 
176
 
176
177
                /*
177
178
                 *      This function removes users from the database.
178
179
                 *  RESTRICTED-LEVEL: Teacher
179
 
                 */ 
 
180
                 */
180
181
                public function removeUser($userName) {
181
182
                        //Check that a user is logged in, has the right privileges (is teacher) and not is the users own username.
182
183
                        if($this->isLoggedIn() && $this->getUserType() === 'Teacher' && $this->getUserName() != $userName) {
183
184
                                //Query-structure
184
185
                                $this->db->where('userName', $userName);
185
 
                                $result = $this->db->delete('Users');            
 
186
                                $result = $this->db->delete('Users');
186
187
                                
187
188
                                //Check for my-sql error
188
189
                                if($result) {
189
190
                                        //Return success
190
191
                                        return TRUE;
191
 
                                } 
 
192
                                }
192
193
                        }
193
194
                        
194
195
                        //Return error
195
196
                        return FALSE;
196
197
                }
197
 
                
198
 
                
 
198
 
 
199
 
199
200
                /*
200
201
                 *      This reset the password for the user.
201
202
                 *  RESTRICTED-LEVEL: Teacher
227
228
                                        //Execute reset
228
229
                                        $data = array(
229
230
                                                'passwd' => $newPwdHash,
230
 
                                                'passwdHint' => 'default'
 
231
                                                'passwdHint' => 'default',
 
232
                                                'firstLogin' => 1
231
233
                                        );
232
234
                                        
233
235
                                        $this->db->where('userName', $userName);
241
243
                        //Return error
242
244
                        return FALSE;
243
245
                }
244
 
                
245
 
                
 
246
 
 
247
 
246
248
                /*
247
 
                 *      This parses a user list from ladok and returns an array with users.
 
249
                 *      This parser a user list from ladok.
248
250
                 *  RESTRICTED-LEVEL: Teacher
249
251
                 */
250
 
                public function parseLadok($string) {
251
 
                        //Check that a user is logged in and has the right privileges (is teacher).
252
 
                        if($this->isLoggedIn() && $this->getUserType() === 'Teacher') {
253
 
                                $userArray = array();
254
 
                                
255
 
                                //Populate array with users from ladok
256
 
                                $ladokUsers = preg_split( '/\r\n|\r|\n/', $string);
257
 
                                
258
 
                                //Trim lines
259
 
                                foreach ($ladokUsers as $key => &$value) {
260
 
                                        $ladokUsers[$key] = trim($ladokUsers[$key]);
261
 
                                }
262
 
                                
263
 
                                //Split after last name
264
 
                                foreach ($ladokUsers as $key => &$value) {
265
 
                                        $ladokUsers[$key] = explode(',', trim($ladokUsers[$key]));
266
 
                                }
267
 
                                
268
 
                                //Replace whitespaces and tabs with divider.
269
 
                                foreach ($ladokUsers as $key => &$value) {
270
 
                                        foreach ($ladokUsers[$key] as $key2 => &$value2) {
271
 
                                                $ladokUsers[$key][$key2] = preg_replace('/\s+/', ' ', trim($ladokUsers[$key][$key2]));
272
 
                                        }
273
 
                                }
274
 
                                
275
 
                                //Explode on whitespace on second split
276
 
                                foreach ($ladokUsers as $key => &$value) {
277
 
                                        $ladokUsers[$key][1] = explode(' ', trim($ladokUsers[$key][1]));
278
 
                                }       
279
 
                                
280
 
                                //Generate user array
281
 
                                $i = 0;
282
 
                                foreach ($ladokUsers as $key => $value) {
283
 
                                        $userArray[$i]['ssn'] = substr($ladokUsers[$key][0], 0, 11);
284
 
                                        $userArray[$i]['lastname'] = substr($ladokUsers[$key][0], 12, strlen($ladokUsers[$key][0]));
285
 
                                        $userArray[$i]['firstname'] = $ladokUsers[$key][1][0];
286
 
                                        $userArray[$i]['email'] = $ladokUsers[$key][1][3];
287
 
                                        $i++;
288
 
                                }
289
 
                                
290
 
                                //Return parsed user array
291
 
                                return $userArray;
 
252
                public function parseLadok() {
 
253
                        //Check that a user is logged in, has the right privileges (is teacher) and not is the users own username.
 
254
                        if($this->isLoggedIn() && $this->getUserType() === 'Teacher' && $this->getUserName() != $userName) {
292
255
                        }
293
 
                        
294
 
                        //If not authed
295
 
                        return FALSE;
296
256
                }
297
 
                
 
257
 
298
258
 
299
259
                /*
300
260
                 *      Generates a salted password hash, encrypted with sha1.
320
280
                                'userName' => $userName,
321
281
                                'userAgent' => $this->session->userdata('user_agent'),
322
282
                                'userIP' => $this->session->userdata('ip_address'),
323
 
                                'browserID' => $this->session->userdata('session_id'), //TODO: change later?
 
283
                                'browserID' => $this->session->userdata('session_id'),
324
284
                                'success' => $valid
325
285
                        );
326
286
                        
327
287
                        $this->db->insert('logUserLoginAttempts', $data);
328
288
                }
329
 
                
330
 
                
 
289
 
 
290
 
331
291
                /*
332
292
                 *      This function return TRUE if the user is logged in and FALSE otherwise.
333
293
                 *  RESTRICTED-LEVEL: System
334
 
                 */ 
335
 
                public function isLoggedIn() {  
 
294
                 */
 
295
                public function isLoggedIn() {
336
296
                        if ($this->session->userdata('authenticated')) {
337
297
                                return TRUE;
338
298
                        }
339
 
                        
340
 
                        return FALSE;
 
299
                        else{
 
300
                                return FALSE;
 
301
                        }
341
302
                }
342
 
                
343
 
                
 
303
 
 
304
 
344
305
                /*
345
306
                 *      This function returns the users type (or FALSE if user isn't logged in).
346
307
                 *  RESTRICTED-LEVEL: System
347
 
                 */ 
348
 
                public function getUserType() { 
 
308
                 */
 
309
                public function getUserType() {
349
310
                        if($this->isLoggedIn()) {
350
311
                                $temp = $this->session->userdata('authenticated');
351
312
                                return $temp['usertype'];
353
314
                        
354
315
                        return FALSE;
355
316
                }
356
 
                
357
 
                
 
317
 
 
318
 
358
319
                /*
359
320
                 *      This function returns a boolean containing information if it is the first login.
360
321
                 *  RESTRICTED-LEVEL: System
369
330
                        
370
331
                        return FALSE;
371
332
                }
372
 
                
373
 
                
 
333
 
 
334
 
374
335
                /*
375
336
                 *      This function returns the username (or FALSE if user isn't logged in).
376
337
                 *  RESTRICTED-LEVEL: System
377
338
                 */ 
378
 
                public function getUserName() { 
 
339
                public function getUserName() {
379
340
                        if($this->isLoggedIn()) {
380
341
                                $temp = $this->session->userdata('authenticated');
381
342
                                return $temp['username'];
384
345
                        return FALSE;
385
346
                }
386
347
        }
 
348
        
387
349
?>
 
 
b'\\ No newline at end of file'