|
48 | 48 | $continue = true; |
49 | 49 |
|
50 | 50 | if(isset($_POST['username']) && $_POST['username'] != '' && $_POST['email'] != '' && $_POST['username'] != 'admin') { |
51 | | - |
52 | 51 | if(!preg_match("/^[\w\.\-\_]{1,64}$/", $_POST['username'])) { |
53 | 52 | $app->tpl->setVar("error", $wb['user_regex_error']); |
54 | 53 | $continue = false; |
55 | 54 | } |
56 | | - if(!preg_match("/^\w+[\w.-]*\w+@\w+[\w.-]*\w+\.[a-z]{2,10}$/i", $_POST['email'])) { |
| 55 | + if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { |
57 | 56 | $app->tpl->setVar("error", $wb['email_error']); |
58 | 57 | $continue = false; |
59 | 58 | } |
60 | 59 |
|
61 | 60 | $username = $_POST['username']; |
62 | 61 | $email = $_POST['email']; |
63 | 62 |
|
64 | | - $client = $app->db->queryOneRecord("SELECT client.*, sys_user.lost_password_function FROM client,sys_user WHERE client.username = ? AND client.email = ? AND client.client_id = sys_user.client_id", $username, $email); |
| 63 | + $client = $app->db->queryOneRecord("SELECT client.*, sys_user.lost_password_function, sys_user.lost_password_hash, IF(sys_user.lost_password_reqtime IS NOT NULL AND DATE_SUB(NOW(), INTERVAL 15 MINUTE) < sys_user.lost_password_reqtime, 1, 0) as `lost_password_wait` FROM client,sys_user WHERE client.username = ? AND client.email = ? AND client.client_id = sys_user.client_id", $username, $email); |
| 64 | + |
| 65 | + if($client['lost_password_function'] == 0) { |
| 66 | + $app->tpl->setVar("error", $wb['lost_password_function_disabled_txt']); |
| 67 | + } elseif($client['lost_password_wait'] == 1) { |
| 68 | + $app->tpl->setVar("error", $wb['lost_password_function_wait_txt']); |
| 69 | + } elseif ($continue) { |
| 70 | + if($client['client_id'] > 0) { |
| 71 | + $username = $client['username']; |
| 72 | + $password_hash = sha1(uniqid('ispc_pw')); |
| 73 | + $app->db->query("UPDATE sys_user SET lost_password_reqtime = NOW(), lost_password_hash = ? WHERE username = ?", $password_hash, $username); |
| 74 | + $app->tpl->setVar("message", $wb['pw_reset_act']); |
| 75 | + |
| 76 | + $server_domain = (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST']); |
| 77 | + if($server_domain == '_') { |
| 78 | + $tmp = explode(':',$_SERVER["HTTP_HOST"]); |
| 79 | + $server_domain = $tmp[0]; |
| 80 | + unset($tmp); |
| 81 | + } |
| 82 | + if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on') $server_domain = 'http://' . $server_domain; |
| 83 | + else $server_domain = 'https://' . $server_domain; |
| 84 | + |
| 85 | + if(isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != '443') $server_domain .= ':' . $_SERVER['SERVER_PORT']; |
| 86 | + |
| 87 | + $app->uses('getconf,ispcmail'); |
| 88 | + $mail_config = $server_config_array['mail']; |
| 89 | + if($mail_config['smtp_enabled'] == 'y') { |
| 90 | + $mail_config['use_smtp'] = true; |
| 91 | + $app->ispcmail->setOptions($mail_config); |
| 92 | + } |
| 93 | + $app->ispcmail->setSender($mail_config['admin_mail'], $mail_config['admin_name']); |
| 94 | + $app->ispcmail->setSubject($wb['pw_reset_act_mail_title']); |
| 95 | + $app->ispcmail->setMailText($wb['pw_reset_act_mail_msg'].$server_domain . '/login/password_reset.php?username=' . urlencode($username) . '&hash=' . urlencode($password_hash)); |
| 96 | + $app->ispcmail->send(array($client['contact_name'] => $client['email'])); |
| 97 | + $app->ispcmail->finish(); |
| 98 | + |
| 99 | + $app->tpl->setVar("msg", $wb['pw_reset_act']); |
| 100 | + } else { |
| 101 | + $app->tpl->setVar("error", $wb['pw_error']); |
| 102 | + } |
| 103 | + } |
| 104 | +} elseif(isset($_GET['username']) && $_GET['username'] != '' && $_GET['hash'] != '') { |
| 105 | + |
| 106 | + if(!preg_match("/^[\w\.\-\_]{1,64}$/", $_GET['username'])) { |
| 107 | + $app->tpl->setVar("error", $wb['user_regex_error']); |
| 108 | + $continue = false; |
| 109 | + } |
| 110 | + |
| 111 | + $username = $_GET['username']; |
| 112 | + $hash = $_GET['hash']; |
| 113 | + |
| 114 | + $client = $app->db->queryOneRecord("SELECT client.*, sys_user.lost_password_function, sys_user.lost_password_hash, IF(sys_user.lost_password_reqtime IS NULL OR DATE_SUB(NOW(), INTERVAL 1 DAY) > sys_user.lost_password_reqtime, 1, 0) as `lost_password_expired` FROM client,sys_user WHERE client.username = ? AND client.client_id = sys_user.client_id", $username); |
65 | 115 |
|
66 | 116 | if($client['lost_password_function'] == 0) { |
67 | 117 | $app->tpl->setVar("error", $wb['lost_password_function_disabled_txt']); |
| 118 | + } elseif($client['lost_password_expired'] == 1) { |
| 119 | + $app->tpl->setVar("error", $wb['lost_password_function_expired_txt']); |
| 120 | + } elseif($client['lost_password_hash'] != $hash) { |
| 121 | + $app->tpl->setVar("error", $wb['lost_password_function_denied_txt']); |
68 | 122 | } elseif ($continue) { |
69 | 123 | if($client['client_id'] > 0) { |
70 | 124 | $server_config_array = $app->getconf->get_global_config(); |
|
75 | 129 | $new_password_encrypted = $app->auth->crypt_password($new_password); |
76 | 130 |
|
77 | 131 | $username = $client['username']; |
78 | | - $app->db->query("UPDATE sys_user SET passwort = ? WHERE username = ?", $new_password_encrypted, $username); |
| 132 | + $app->db->query("UPDATE sys_user SET passwort = ?, lost_password_hash = '', lost_password_reqtime = NULL WHERE username = ?", $new_password_encrypted, $username); |
79 | 133 | $app->db->query("UPDATE client SET password = ? WHERE username = ?", $new_password_encrypted, $username); |
80 | 134 | $app->tpl->setVar("message", $wb['pw_reset']); |
81 | 135 |
|
|
0 commit comments