Skip to content

Commit

Permalink
feat: add reset password functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ellite committed May 25, 2024
1 parent abefd91 commit 9f55f89
Show file tree
Hide file tree
Showing 22 changed files with 392 additions and 3 deletions.
81 changes: 81 additions & 0 deletions endpoints/cronjobs/sendresetpasswordemails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';

$query = "SELECT * FROM admin";
$stmt = $db->prepare($query);
$result = $stmt->execute();
$admin = $result->fetchArray(SQLITE3_ASSOC);

$query = "SELECT * FROM password_resets WHERE email_sent = 0";
$stmt = $db->prepare($query);
$result = $stmt->execute();

$rows = [];
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$rows[] = $row;
}

if ($rows) {
if ($admin['smtp_address'] && $admin['smtp_port'] && $admin['smtp_username'] && $admin['smtp_password'] && $admin['encryption']) {
// There are SMTP settings
$smtpAddress = $admin['smtp_address'];
$smtpPort = $admin['smtp_port'];
$smtpUsername = $admin['smtp_username'];
$smtpPassword = $admin['smtp_password'];
$fromEmail = empty($admin['from_email']) ? '[email protected]' : $admin['from_email'];
$encryption = $admin['encryption'];
$server_url = $admin['server_url'];

require __DIR__ . '/../../libs/PHPMailer/PHPMailer.php';
require __DIR__ . '/../../libs/PHPMailer/SMTP.php';
require __DIR__ . '/../../libs/PHPMailer/Exception.php';

$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = $smtpAddress;
$mail->SMTPAuth = true;
$mail->Username = $smtpUsername;
$mail->Password = $smtpPassword;
$mail->SMTPSecure = $encryption;
$mail->Port = $smtpPort;
$mail->setFrom($fromEmail);

try {
foreach ($rows as $user) {
$mail->addAddress($user['email']);
$mail->isHTML(true);
$mail->Subject = 'Wallos - Reset Password';
$mail->Body = '<img src="' . $server_url . '/images/siteicons/blue/wallos.png" alt="Logo" />
<br>
A password reset was requested for your account.
<br>
Please click the following link to reset your password: <a href="' . $server_url . '/passwordreset.php?email=' . $user['email'] . '&token=' . $user['token'] . '">Reset Password</a>';

$mail->send();

$query = "UPDATE password_resets SET email_sent = 1 WHERE id = :id";
$stmt = $db->prepare($query);
$stmt->bindParam(':id', $user['id'], SQLITE3_INTEGER);
$stmt->execute();

$mail->clearAddresses();

echo "Verification email sent to " . $user['email'] . "<br>";
}
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
} else {
// There are no SMTP settings
die("There are password reset emails to be sent but no SMTP settings found.");
}
} else {
// There are no verification emails to be sent
die("No verification emails to be sent.");
}

?>
2 changes: 1 addition & 1 deletion endpoints/cronjobs/sendverificationemails.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
}
} else {
// There are no SMTP settings
die("There are verification email to be sent but no SMTP settings found.");
die("There are verification emails to be sent but no SMTP settings found.");
}
} else {
// There are no verification emails to be sent
Expand Down
4 changes: 4 additions & 0 deletions includes/i18n/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'login_failed' => "Loginangaben sind nicht korrekt",
'registration_successful' => "Registrierung erfolgreich",
'user_email_waiting_verification' => "Ihre E-Mail muss noch verifiziert werden. Bitte überprüfen Sie Ihre E-Mail.",
// Password Reset Page
'forgot_password' => "Passwort vergessen?",
'reset_password' => "Passwort zurücksetzen",
'reset_sent_check_email' => "Passwort zurücksetzen E-Mail wurde gesendet. Bitte überprüfen Sie Ihr Postfach.",
// Header
'subscriptions' => "Abonnements",
'stats' => "Statistiken",
Expand Down
4 changes: 4 additions & 0 deletions includes/i18n/el.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'login_failed' => "Τα στοιχεία σύνδεσης είναι λανθασμένα",
'registration_successful' => "Επιτυχής Εγγραφή",
'user_email_waiting_verification' => "Το email σας πρέπει να επαληθευτεί. Παρακαλούμε ελέγξτε το email σας",
// Password Reset Page
'forgot_password' => "Ξέχασες τον κωδικό σου; Κάνε κλικ",
'reset_password' => "Επαναφορά κωδικού πρόσβασης",
'reset_sent_check_email' => "Ένα email με οδηγίες για την επαναφορά του κωδικού πρόσβασης σας έχει σταλεί. Παρακαλώ ελέγξτε το email σας.",
// Header
'subscriptions' => "Συνδρομές",
'stats' => "Στατιστικές",
Expand Down
4 changes: 4 additions & 0 deletions includes/i18n/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'login_failed' => "Login details are incorrect",
'registration_successful' => "Registration successful",
'user_email_waiting_verification' => "Your email needs to be verified. Please check your email.",
// Password Reset Page
'forgot_password' => "Forgot Password",
'reset_password' => "Reset Password",
'reset_sent_check_email' => "Reset email sent. Please check your email.",
// Header
'subscriptions' => "Subscriptions",
'stats' => "Statistics",
Expand Down
4 changes: 4 additions & 0 deletions includes/i18n/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'login_failed' => "Los detalles de inicio de sesión son incorrectos",
'registration_successful' => "Registro efectuado con éxito",
'user_email_waiting_verification' => "Tu correo electrónico necesita ser verificado. Por favor, compruebe su correo electrónico",
// Password Reset Page
'forgot_password' => "¿Olvidaste tu contraseña?",
'reset_password' => "Restablecer Contraseña",
'reset_sent_check_email' => "Se ha enviado un correo electrónico con instrucciones para restablecer la contraseña. Por favor, compruebe su correo electrónico.",
// Header
'subscriptions' => "Suscripciones",
'stats' => "Estadísticas",
Expand Down
4 changes: 4 additions & 0 deletions includes/i18n/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'login_failed' => "Les détails de connexion sont incorrects",
'registration_successful' => "Inscription réussie",
'user_email_waiting_verification' => "Votre email doit être vérifié. Veuillez vérifier votre email",
// Password Reset Page
'forgot_password' => "Mot de passe oublié",
'reset_password' => "Réinitialiser le mot de passe",
'reset_sent_check_email' => "Un courriel a été envoyé à l'adresse fournie. Vérifiez votre boîte de réception.",
// En-tête
'subscriptions' => "Abonnements",
'stats' => "Statistiques",
Expand Down
5 changes: 5 additions & 0 deletions includes/i18n/it.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
'login_failed' => 'Le credenziali non sono corrette',
'registration_successful' => "L'account è stato creato con successo",
'user_email_waiting_verification' => "L'e-mail deve essere verificata. Controlla la tua email",

// Password Reset Page
'forgot_password' => "Hai dimenticato la password?",
'reset_password' => "Reimposta password",
'reset_sent_check_email' => "Un'email è stata inviata. Controlla la tua casella di posta",

// Header
'subscriptions' => 'Abbonamenti',
Expand Down
4 changes: 4 additions & 0 deletions includes/i18n/jp.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'login_failed' => "ログイン情報が間違っています",
'registration_successful' => "登録に成功",
'user_email_waiting_verification' => "Eメールの確認が必要です。メールを確認してください。",
// Password Reset Page
'forgot_password' => "パスワードを忘れた場合",
'reset_password' => "パスワードをリセット",
'reset_sent_check_email' => "パスワードリセットリンクが送信されました。メールを確認してください。",
// Header
'subscriptions' => "定期購入",
'stats' => "統計",
Expand Down
4 changes: 4 additions & 0 deletions includes/i18n/ko.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'login_failed' => "로그인 정보가 부정확합니다.",
'registration_successful' => "등록 성공",
'user_email_waiting_verification' => "이메일을 인증해야 합니다. 이메일을 확인해 주세요.",
// Password Reset Page
'forgot_password' => "비밀번호를 잊으셨나요?",
'reset_password' => "비밀번호 재설정",
'reset_sent_check_email' => "비밀번호 재설정 이메일이 전송되었습니다. 이메일을 확인해 주세요.",
// Header
'subscriptions' => "구독",
'stats' => "통계",
Expand Down
4 changes: 4 additions & 0 deletions includes/i18n/pl.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'login_failed' => "Dane logowania są nieprawidłowe",
'registration_successful' => "Pomyślnie zarejestrowano",
'user_email_waiting_verification' => "Twój adres e-mail musi zostać zweryfikowany. Sprawdź swój adres e-mail",
// Password Reset Page
'forgot_password' => "Zapomniałeś hasła? Kliknij tutaj",
'reset_password' => "Zresetuj hasło",
'reset_sent_check_email' => "Link do zresetowania hasła został wysłany na Twój adres e-mail",
// Header
'subscriptions' => "Subskrypcje",
'stats' => "Statystyki",
Expand Down
4 changes: 4 additions & 0 deletions includes/i18n/pt.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'login_failed' => "Dados de autenticação incorrectos",
'registration_successful' => "Registo efectuado com sucesso.",
'user_email_waiting_verification' => "O seu e-mail precisa de ser validado. Verifique o seu correio eletrónico",
// Password Reset Page
'forgot_password' => "Esqueceu-se da password?",
'reset_password' => "Repor Password",
'reset_sent_check_email' => "Pedido de reposição de password enviado. Verifique o seu email.",
// Header
'subscriptions' => "Subscrições",
'stats' => "Estatísticas",
Expand Down
4 changes: 4 additions & 0 deletions includes/i18n/pt_br.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'login_failed' => "As informações de login estão incorretas",
'registration_successful' => "Registro bem-sucedido",
'user_email_waiting_verification' => "Seu e-mail precisa ser validado. Por favor, verifique seu e-mail",
// Password Reset Page
'forgot_password' => "Esqueceu a senha?",
'reset_password' => "Redefinir senha",
'reset_sent_check_email' => "Redefinição de senha enviada. Por favor, verifique seu email",
// Header
'subscriptions' => "Assinaturas",
'stats' => "Estatísticas",
Expand Down
4 changes: 4 additions & 0 deletions includes/i18n/ru.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'login_failed' => "Данные для входа неверны",
'registration_successful' => "Регистрация прошла успешно",
'user_email_waiting_verification' => "Ваша электронная почта нуждается в проверке. Пожалуйста, проверьте свою электронную почту",
// Password Reset Page
'forgot_password' => "Забыли пароль?",
'reset_password' => "Сбросить пароль",
'reset_sent_check_email' => "Ссылка для сброса пароля отправлена на вашу электронную почту",
// Header
'subscriptions' => "Подписки",
'stats' => "Статистика",
Expand Down
4 changes: 4 additions & 0 deletions includes/i18n/sr.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'login_failed' => "Подаци за пријаву нису исправни",
'registration_successful' => "Пријава успешна",
'user_email_waiting_verification' => "Ваша е-пошта треба да буде верификована. Молимо прегледајте Е-пошту",
// Password Reset Page
'forgot_password' => "Заборављена лозинка",
'reset_password' => "Ресетуј лозинку",
'reset_sent_check_email' => "Ресетовање лозинке је послато на вашу е-пошту",
// Header
'subscriptions' => "Претплате",
'stats' => "Статистике",
Expand Down
4 changes: 4 additions & 0 deletions includes/i18n/sr_lat.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'login_failed' => "Podaci za prijavu nisu ispravni",
'registration_successful' => "Registracija uspešna",
'user_email_waiting_verification' => "Vaša e-pošta treba da bude verifikovana. Molimo pregledajte E-poštu",
// Password Reset Page
'forgot_password' => "Zaboravili ste lozinku?",
'reset_password' => "Resetuj lozinku",
'reset_sent_check_email' => "Poslali smo vam e-poštu sa uputstvima za resetovanje lozinke",
// Header
'subscriptions' => "Pretplate",
'stats' => "Statistike",
Expand Down
4 changes: 4 additions & 0 deletions includes/i18n/tr.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'login_failed' => "Giriş bilgileri hatalı",
'registration_successful' => "Kayıt başarılı",
'user_email_waiting_verification' => "E-postanızın doğrulanması gerekiyor. Lütfen e-postanızı kontrol edin",
// Password Reset Page
'forgot_password' => "Şifremi Unuttum",
'reset_password' => "Şifreyi Sıfırla",
'reset_sent_check_email' => "Şifre sıfırlama bağlantısı e-posta adresinize gönderildi. Lütfen e-postanızı kontrol edin.",
// Header
'subscriptions' => "Abonelikler",
'stats' => "İstatistikler",
Expand Down
4 changes: 4 additions & 0 deletions includes/i18n/zh_cn.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
'login_failed' => "登录信息错误",
'registration_successful' => "注册成功",
'user_email_waiting_verification' => "您的电子邮件需要验证。请检查您的电子邮件",
// Password Reset Page
'forgot_password' => "忘记密码",
'reset_password' => "重置密码",
'reset_sent_check_email' => "重置密码链接已发送到您的电子邮箱",

// 页眉
'subscriptions' => "订阅",
Expand Down
4 changes: 4 additions & 0 deletions includes/i18n/zh_tw.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'login_failed' => "登入資訊錯誤",
'registration_successful' => "註冊成功",
'user_email_waiting_verification' => "您的電子郵件需要驗證。 請查看你的信箱",
// Password Reset Page
'forgot_password' => "忘記密碼",
'reset_password' => "重設密碼",
'reset_sent_check_email' => "重設密碼的電子郵件已發送,請檢查您的電子郵件",
// 頁首
'subscriptions' => "訂閱",
'stats' => "統計",
Expand Down
16 changes: 14 additions & 2 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

//Check if registration is open
$registrations = false;
$adminQuery = "SELECT registrations_open, max_users FROM admin";
$adminQuery = "SELECT registrations_open, max_users, server_url, smtp_address FROM admin";
$adminResult = $db->query($adminQuery);
$adminRow = $adminResult->fetchArray(SQLITE3_ASSOC);
$registrationsOpen = $adminRow['registrations_open'];
Expand All @@ -119,6 +119,11 @@
}
}

$resetPasswordEnabled = false;
if ($adminRow['smtp_address'] != "" && $adminRow['server_url'] != "") {
$resetPasswordEnabled = true;
}

?>
<!DOCTYPE html>
<html dir="<?= $languages[$lang]['dir'] ?>">
Expand Down Expand Up @@ -210,8 +215,15 @@
</ul>
<?php
}

if ($resetPasswordEnabled) {
?>
<div class="forgot-password">
<a href="passwordreset.php"><?= translate('forgot_password', $i18n) ?></a>
</div>
<?php
}
?>

<?php
if ($registrations) {
?>
Expand Down
Loading

0 comments on commit 9f55f89

Please sign in to comment.