set('title', "Przywrócenie hasła"); $db=$f3->get('db'); addCssJs($f3, 'news.css register.css'); define('MAILHEADER','MIME-Version: 1.0'."\r\n".'Content-type: text/html; charset=utf-8'. "\r\n" .'From: info@astroakademia.pl' . "\r\n" . 'Reply-To: info@astroakademia.pl'); $is_form = true; if (isset($_POST['rescueExe'])){ $email = trim(strip_tags($_POST['email'])); $password = trim(strip_tags($_POST['new_password'])); $preg_match = preg_match('/^[a-zA-Z0-9_]+$/',$password); $passlen = strlen($password); if (!login_exists($email)){ // kiedy nie ma takiego e-maila w bazie: $message = "Błąd: podanego adresu e-mail nie ma w bazie.
Spróbuj jeszcze raz."; } elseif (!(($preg_match>0) && ($passlen >4))){ // czyli kiedy hasło NIE TAKIE.. $message = "Błąd: nieprawidłowe hasło.
Spróbuj jeszcze raz."; } else { $haslo = strrev(md5($password)); $rescue_title = 'Przywrócenie/zmiana hasła'; $rescue_url = '24.astroakademia.pl/password_rescue'; $rescue_content = ''.$rescue_title.'

'.$rescue_title.'

Dokończ odnowienie hasła w witrynie AstroAkademia
(Kliknij powyższy link.)
Lub następujący adres wpisz do górnego paska przeglądarki:
https://'.$rescue_url.'?id='.$haslo.'&adr='.$email.'
'; $mail_sent = mail($email, $rescue_title, $rescue_content, MAILHEADER); $message = "Wysłaliśmy mail na adres $email z prośbą o potwierdzenie."; $is_form = false; } } elseif(isset($_GET['id']) && isset($_GET['adr'])){ // przyszed?sygnał z emaila zwrotnego $password = trim(strip_tags($_GET['id'])); $email = trim(strip_tags($_GET['adr'])); $affrows = $db->exec("UPDATE user SET password='$password' WHERE email='$email'"); if ($affrows===false){ $message = 'Odnowa hasła nie powiodła się.
Spróbuj jeszcze raz lub zwróć się po pomoc do administratora: info@astroakademia.pl.'; } else { $message = 'Odnowa hasła powiodła się. Możesz się zalogować.'; $is_form = false; } } $f3->set('message', $message); $f3->set('is_form', $is_form); echo \Template::instance()->render('templates/password_rescue.htm'); function login_exists($email){ global $db; $rows = $db->exec("SELECT id FROM user WHERE email='$email'"); return count($rows)>0; } ?>