# # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . global $_USER; if ($_USER) header('Location: '.BASE.'notes'); define('TITLE', __('Having trouble while logging in?')); global $db; global $mailing; echo '
'.__('Having trouble while logging in?').'
'; if ($_POST) { if (isset($_GET['forgot'])) { if (!empty($_POST['group']) && (!empty($_POST['content']))) { if ($_POST['group'] == 'email') { $userInfo = $db->getUserInfo(false, false, $_POST['content']); if (!$userInfo) echo showStatus(__('That email doesn\'t exist in our database'), 'error'); } elseif ($_POST['group'] == 'username') { $userInfo = $db->getUserInfo(false, $_POST['content']); if (!$userInfo) echo showStatus(__("There's no user with that username"), 'error'); } if ($userInfo) { $token = substr(md5(rand()), 0, 12); $db->newKey($userInfo['ID'], 'password', $token); $mailing->forgottenPassword($userInfo['email'], $userInfo['ID'], $token); echo showStatus(__('We have just sent an e-mail with instructions!'), 'ok'); } } else { echo showStatus(__("Please fill all the inputs"), 'error'); } } elseif (isset($_GET['resend'])) { if (empty($_POST['user'])) echo showStatus(__("Please fill all the inputs"), 'error'); else { $userInfo = $db->getUserInfo(false, $_POST['user']); if (!$userInfo) echo showStatus(__("There's no user with that username"), 'error'); else { if ($userInfo['status'] != 'nc') echo showStatus(__('The account was not waiting for an activation email'), 'error'); else { $query = $db->send("SELECT `token` FROM `keys` WHERE `keys`.`user_id` = ".(int)$userInfo['ID']." AND `keys`.`type` = 'activation' LIMIT 1"); if (!mysql_num_rows($query)) { $key = $db->newKey($userInfo['ID'], 'activation', substr(md5(rand()), 0, 6)); echo showStatus(__("There was a problem while trying to obtain your key. Please retry"), 'warning'); } else { $key = mysql_result($query, 0); $mailing->confirmRegistration($userInfo['email'], $userInfo['ID'], $key); echo showStatus(__('Check your email (including SPAM) to activate your account'), 'ok'); } } } } } } else { if ($_GET) { if (($_GET['key']) && ($_GET['uid'])) { $check = $db->checkForgotKey($_GET['key'], $_GET['uid']); if ($check) { $userInfo = $db->getUserInfo($_GET['uid']); $salt = $userInfo['salt']; if ($userInfo) { $new_password = substr(md5(mt_rand()), 5, 15); $salt = substr(md5(mt_rand()), 0, 5); $password = md5(md5($new_password).md5($salt)); $db->updatePassword($userInfo['ID'], $password, $salt); $mailing->resetPassword($userInfo['email'], $new_password, $userInfo['username']); $db->deleteKey($_GET['key'], $userInfo['ID']); echo showStatus(__('We have just sent you an e-mail with your new password'), 'ok'); } else { echo showStatus(__('Invalid key'), 'error'); } } else { echo showStatus(__('Invalid key'), 'error'); } } } } echo '

'.str_replace('%name', NAME, __('If you cannot login into your %name account, choose an option from the forms below')).'



'; doTroubleLoginForm(); ?>