1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace SimpleSAML\Module\ldapPasswordReset; |
||
6 | |||
7 | use SimpleSAML\{Configuration, Module, Utils}; |
||
8 | |||
9 | /** |
||
10 | * This class takes care of sending the magic links through email |
||
11 | * |
||
12 | * @package simplesamlphp/simplesamlphp-module-ldapPasswordReset |
||
13 | */ |
||
14 | class MagicLink |
||
15 | { |
||
16 | /** @var \SimpleSAML\Configuration */ |
||
17 | protected Configuration $config; |
||
18 | |||
19 | /** @var \SimpleSAML\Configuration */ |
||
20 | protected Configuration $moduleConfig; |
||
21 | |||
22 | |||
23 | /** |
||
24 | * @param \SimpleSAML\Configuration $config The configuration to use. |
||
25 | */ |
||
26 | public function __construct(Configuration $config) |
||
27 | { |
||
28 | $this->config = $config; |
||
29 | $this->moduleConfig = Configuration::getOptionalConfig('module_ldapPasswordReset.php'); |
||
30 | } |
||
31 | |||
32 | |||
33 | /** |
||
34 | * Send magic link |
||
35 | * |
||
36 | * @param string $email |
||
37 | * @param string $token |
||
38 | * @param int $validUntil |
||
39 | * @return void |
||
40 | */ |
||
41 | public function sendMagicLink(string $email, string $token, int $validUntil): void |
||
42 | { |
||
43 | $url = Module::getModuleURL('ldapPasswordReset/validateMagicLink', ['t' => $token]); |
||
44 | |||
45 | $mail = new Utils\EMail( |
||
46 | $this->moduleConfig->getOptionalString('email.subject', 'Password reset'), |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
47 | $this->moduleConfig->getOptionalString('email.from', $this->config->getString('technicalcontact_email')), |
||
48 | $email, |
||
49 | 'ldapPasswordReset:mailtxt.twig', |
||
50 | 'ldapPasswordReset:mailhtml.twig' |
||
51 | ); |
||
52 | $mail->setData(['url' => $url, 'validUntil' => $validUntil]); |
||
53 | $mail->setText('{url}'); |
||
54 | $mail->send(); |
||
55 | } |
||
56 | } |
||
57 |