From 2f150b1b26a0305af208a7719135bf60513f046d Mon Sep 17 00:00:00 2001 From: Mikkel Westh Date: Wed, 5 Apr 2023 21:42:13 +0200 Subject: [PATCH] ADDED function to fix passwords and send mail to affected participants --- include/controllers/mail_controller.php | 29 ++++++++++++++++---- include/entities/deltagere.php | 9 +----- include/framework/routes.php | 1 + include/models/mail_model.php | 8 ++++++ include/templates/mail/fixpass_mail_da.phtml | 11 ++++++++ include/templates/mail/fixpass_mail_en.phtml | 11 ++++++++ 6 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 include/templates/mail/fixpass_mail_da.phtml create mode 100644 include/templates/mail/fixpass_mail_en.phtml diff --git a/include/controllers/mail_controller.php b/include/controllers/mail_controller.php index 53686b48..4edab1b8 100644 --- a/include/controllers/mail_controller.php +++ b/include/controllers/mail_controller.php @@ -4,6 +4,7 @@ class MailController extends Controller { static protected $enabled_types = [ 'setup' => true, + 'fixpass' => true, ]; public function sendSetupMail() { @@ -19,6 +20,27 @@ public function sendSetupMail() { $this->sendBatchMail('setup', $title, $recipients); } + public function fixPasswords() { + $recipients = $this->model->getRecipients('fixpass', 0); + + echo "Updating participant passwords for ".count($recipients)." participants
"; + die('Password safety'); + + foreach ($recipients as $participant) { + $participant->createPass(); + $participant->update(); + echo $participant->id ."
"; + } + + $year = $this->getConYear(); + $title = [ + 'da' => "Ny kode til Fastaval $year", + 'en' => "New passcode for Fastaval $year" + ]; + + $this->sendBatchMail('fixpass', $title, $recipients, ['password']); + } + private function sendBatchMail($type, $title, $recipients, $info = []) { $total = count($recipients); echo "Sending $type mail to $total recipients
\n"; @@ -45,26 +67,23 @@ private function sendBatchMail($type, $title, $recipients, $info = []) { $this->page->name = $recipient->getName(); foreach ($info as $field) { if (is_string($field)) { - $this->page->info[$field] = $recipient->$field; + $page_info[$field] = $recipient->$field; } } + $this->page->info = $page_info; $mail = new Mail($this->config); - $mail->setFrom($this->config->get('app.email_address'), $this->config->get('app.email_alias')) ->setRecipient($recipient->email) ->setSubject($title[$lang]) ->setBodyFromPage($this->page); - $mail->send(); $this->log("System sent $type mail to participant (ID: $recipient->id )", 'Mail', null); - $count++; } $this->log("Finished sending $type mail to $count participants", 'Mail', null); - exit; } } \ No newline at end of file diff --git a/include/entities/deltagere.php b/include/entities/deltagere.php index 3e09c557..760fde5c 100755 --- a/include/entities/deltagere.php +++ b/include/entities/deltagere.php @@ -1190,14 +1190,7 @@ public function getPossiblePlaytime() */ public function createPass() { - $base = implode('', array_merge(range('a', 'z'), range('A', 'Z'))); - $pass = ''; - for ($i = 0; $i < 8; $i++) - { - $pass .= $base[mt_rand(0, strlen($base) - 1)]; - } - $this->password = $pass; - $this->passwordCleartext = $pass; + $this->password = sprintf('%06d', mt_rand(0, 999999)); } /** diff --git a/include/framework/routes.php b/include/framework/routes.php index 06a19d3b..1339d0fa 100644 --- a/include/framework/routes.php +++ b/include/framework/routes.php @@ -158,6 +158,7 @@ public function __construct(Config $config) // New mail sender $this->routes['send_setup_mail'] = array('url' => 'mail/sendsetupmail', 'controller' => 'Mail', 'method' => 'sendSetupMail'); + $this->routes['send_password_mail'] = array('url' => 'mail/fixpassword', 'controller' => 'Mail', 'method' => 'fixPasswords'); // Misc mail $this->routes['send_welcome_mail'] = array('url' => 'participant/sendwelcomemail', 'controller' => 'Participant', 'method' => 'sendWelcomeMail'); diff --git a/include/models/mail_model.php b/include/models/mail_model.php index 0a19f3b7..e90bf05f 100644 --- a/include/models/mail_model.php +++ b/include/models/mail_model.php @@ -21,6 +21,14 @@ public function getRecipients($type, $filter_recent = 1) { } } break; + + case 'fixpass': + foreach ($participants as $id => $participant) { + if (preg_match("/\d{6}/", $participant->password)) { + unset($participants[$id]); + } + } + break; } return $participants; diff --git a/include/templates/mail/fixpass_mail_da.phtml b/include/templates/mail/fixpass_mail_da.phtml new file mode 100644 index 00000000..dc008e4c --- /dev/null +++ b/include/templates/mail/fixpass_mail_da.phtml @@ -0,0 +1,11 @@ +

Kære name?>,

+ +

+ Da vi oprettede dig som deltager på Fastaval, kom vi desværre til at lave et kodeord, der ikke passer med vores app.
+ Derfor har vi automatisk rettet din kode så du også kan bruge appen.
+ Din nye kode er info['password']?> +

+ +

+ Venlig hilsen Fastaval IT +

\ No newline at end of file diff --git a/include/templates/mail/fixpass_mail_en.phtml b/include/templates/mail/fixpass_mail_en.phtml new file mode 100644 index 00000000..b5ef8136 --- /dev/null +++ b/include/templates/mail/fixpass_mail_en.phtml @@ -0,0 +1,11 @@ +

Dear name?>,

+ +

+ When we registered you in our system as a participant at Fastaval, we regretfully generated a password that doesn't work with our app.
+ Therefore we've automatically generated a new passcode, so you'll be able to log in with the app.
+ Your new passcode is info['password']?> +

+ +

+ Kind regards, Fastaval IT +

\ No newline at end of file