1 <?php |
1 <?php |
2 |
2 |
3 require('includes/starthere.php'); |
3 require('includes/starthere.php'); |
4 |
4 |
|
5 if ( isset($_POST['action']) ) |
|
6 { |
|
7 switch($_POST['action']) |
|
8 { |
|
9 case 'change-password': |
|
10 try |
|
11 { |
|
12 // verify old password |
|
13 $result = @ldap_bind($_ldapconn, ldap_make_user_dn($_SERVER['REMOTE_USER']), $_POST['old_password']); |
|
14 if ( !$result ) |
|
15 throw new Exception("Your old password was incorrect."); |
|
16 |
|
17 if ( ($result = test_password($_POST['password'])) !== true ) |
|
18 throw new Exception("Your new password $result."); |
|
19 |
|
20 if ( $_POST['password'] !== $_POST['password_confirm'] ) |
|
21 throw new Exception("The passwords you entered did not match."); |
|
22 |
|
23 if ( reset_password($_SERVER['REMOTE_USER'], $_POST['password']) ) |
|
24 { |
|
25 // rebind to LDAP as manager, since we did a bind to verify the old password |
|
26 ldap_bind($_ldapconn, $ldap_manager['dn'], $ldap_manager['password']); |
|
27 queue_message(E_NOTICE, "Your password has been changed."); |
|
28 break; |
|
29 } |
|
30 else |
|
31 { |
|
32 throw new Exception("Internal error when performing password reset."); |
|
33 } |
|
34 } |
|
35 catch ( Exception $e ) |
|
36 { |
|
37 queue_message(E_ERROR, $e->getMessage()); |
|
38 |
|
39 // rebind to LDAP as manager, since we did a bind to verify the old password |
|
40 ldap_bind($_ldapconn, $ldap_manager['dn'], $ldap_manager['password']); |
|
41 } |
|
42 break; |
|
43 case 'profile-update': |
|
44 // header('Content-type: text/plain'); print_r(!empty($_POST['sshPublicKey']) ? $_POST['sshPublicKey'] : array()); exit; |
|
45 $result = ldap_mod_replace($_ldapconn, ldap_make_user_dn($_SERVER['REMOTE_USER']), array( |
|
46 'mail' => array($_POST['mail']) |
|
47 , 'sshPublicKey' => !empty($_POST['sshPublicKey']) ? array_unique($_POST['sshPublicKey']) : array() |
|
48 )); |
|
49 |
|
50 if ( $result || ldap_error($_ldapconn) === 'Success' ) |
|
51 { |
|
52 queue_message(E_NOTICE, "Your information has been updated."); |
|
53 redirect('/'); |
|
54 } |
|
55 else |
|
56 { |
|
57 queue_message(E_ERROR, ldap_error($_ldapconn)); |
|
58 } |
|
59 break; |
|
60 } |
|
61 } |
|
62 |
5 display_template('index'); |
63 display_template('index'); |