Skip to content

Commit

Permalink
ADDED function to fix passwords and send mail to affected participants
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamSpawn committed Apr 5, 2023
1 parent 0d3e3e3 commit 2f150b1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 13 deletions.
29 changes: 24 additions & 5 deletions include/controllers/mail_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class MailController extends Controller {

static protected $enabled_types = [
'setup' => true,
'fixpass' => true,
];

public function sendSetupMail() {
Expand All @@ -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<br>";
die('Password safety');

foreach ($recipients as $participant) {
$participant->createPass();
$participant->update();
echo $participant->id ."<br>";
}

$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<br>\n";
Expand All @@ -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;
}
}
9 changes: 1 addition & 8 deletions include/entities/deltagere.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
1 change: 1 addition & 0 deletions include/framework/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 8 additions & 0 deletions include/models/mail_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions include/templates/mail/fixpass_mail_da.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h2>Kære <?=$this->name?>,</h2>

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

<p>
Venlig hilsen Fastaval IT
</p>
11 changes: 11 additions & 0 deletions include/templates/mail/fixpass_mail_en.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h2>Dear <?=$this->name?>,</h2>

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

<p>
Kind regards, Fastaval IT
</p>

0 comments on commit 2f150b1

Please sign in to comment.