@@ -42,141 +42,141 @@ |
||
42 | 42 | use OCP\Security\ISecureRandom; |
43 | 43 | |
44 | 44 | class NewUserMailHelper { |
45 | - /** @var Defaults */ |
|
46 | - private $themingDefaults; |
|
47 | - /** @var IURLGenerator */ |
|
48 | - private $urlGenerator; |
|
49 | - /** @var IFactory */ |
|
50 | - private $l10nFactory; |
|
51 | - /** @var IMailer */ |
|
52 | - private $mailer; |
|
53 | - /** @var ISecureRandom */ |
|
54 | - private $secureRandom; |
|
55 | - /** @var ITimeFactory */ |
|
56 | - private $timeFactory; |
|
57 | - /** @var IConfig */ |
|
58 | - private $config; |
|
59 | - /** @var ICrypto */ |
|
60 | - private $crypto; |
|
61 | - /** @var string */ |
|
62 | - private $fromAddress; |
|
45 | + /** @var Defaults */ |
|
46 | + private $themingDefaults; |
|
47 | + /** @var IURLGenerator */ |
|
48 | + private $urlGenerator; |
|
49 | + /** @var IFactory */ |
|
50 | + private $l10nFactory; |
|
51 | + /** @var IMailer */ |
|
52 | + private $mailer; |
|
53 | + /** @var ISecureRandom */ |
|
54 | + private $secureRandom; |
|
55 | + /** @var ITimeFactory */ |
|
56 | + private $timeFactory; |
|
57 | + /** @var IConfig */ |
|
58 | + private $config; |
|
59 | + /** @var ICrypto */ |
|
60 | + private $crypto; |
|
61 | + /** @var string */ |
|
62 | + private $fromAddress; |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param Defaults $themingDefaults |
|
66 | - * @param IURLGenerator $urlGenerator |
|
67 | - * @param IFactory $l10nFactory |
|
68 | - * @param IMailer $mailer |
|
69 | - * @param ISecureRandom $secureRandom |
|
70 | - * @param ITimeFactory $timeFactory |
|
71 | - * @param IConfig $config |
|
72 | - * @param ICrypto $crypto |
|
73 | - * @param string $fromAddress |
|
74 | - */ |
|
75 | - public function __construct(Defaults $themingDefaults, |
|
76 | - IURLGenerator $urlGenerator, |
|
77 | - IFactory $l10nFactory, |
|
78 | - IMailer $mailer, |
|
79 | - ISecureRandom $secureRandom, |
|
80 | - ITimeFactory $timeFactory, |
|
81 | - IConfig $config, |
|
82 | - ICrypto $crypto, |
|
83 | - $fromAddress) { |
|
84 | - $this->themingDefaults = $themingDefaults; |
|
85 | - $this->urlGenerator = $urlGenerator; |
|
86 | - $this->l10nFactory = $l10nFactory; |
|
87 | - $this->mailer = $mailer; |
|
88 | - $this->secureRandom = $secureRandom; |
|
89 | - $this->timeFactory = $timeFactory; |
|
90 | - $this->config = $config; |
|
91 | - $this->crypto = $crypto; |
|
92 | - $this->fromAddress = $fromAddress; |
|
93 | - } |
|
64 | + /** |
|
65 | + * @param Defaults $themingDefaults |
|
66 | + * @param IURLGenerator $urlGenerator |
|
67 | + * @param IFactory $l10nFactory |
|
68 | + * @param IMailer $mailer |
|
69 | + * @param ISecureRandom $secureRandom |
|
70 | + * @param ITimeFactory $timeFactory |
|
71 | + * @param IConfig $config |
|
72 | + * @param ICrypto $crypto |
|
73 | + * @param string $fromAddress |
|
74 | + */ |
|
75 | + public function __construct(Defaults $themingDefaults, |
|
76 | + IURLGenerator $urlGenerator, |
|
77 | + IFactory $l10nFactory, |
|
78 | + IMailer $mailer, |
|
79 | + ISecureRandom $secureRandom, |
|
80 | + ITimeFactory $timeFactory, |
|
81 | + IConfig $config, |
|
82 | + ICrypto $crypto, |
|
83 | + $fromAddress) { |
|
84 | + $this->themingDefaults = $themingDefaults; |
|
85 | + $this->urlGenerator = $urlGenerator; |
|
86 | + $this->l10nFactory = $l10nFactory; |
|
87 | + $this->mailer = $mailer; |
|
88 | + $this->secureRandom = $secureRandom; |
|
89 | + $this->timeFactory = $timeFactory; |
|
90 | + $this->config = $config; |
|
91 | + $this->crypto = $crypto; |
|
92 | + $this->fromAddress = $fromAddress; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * @param IUser $user |
|
97 | - * @param bool $generatePasswordResetToken |
|
98 | - * @return IEMailTemplate |
|
99 | - */ |
|
100 | - public function generateTemplate(IUser $user, $generatePasswordResetToken = false) { |
|
101 | - $userId = $user->getUID(); |
|
102 | - $lang = $this->l10nFactory->getUserLanguage($user); |
|
103 | - $l10n = $this->l10nFactory->get('settings', $lang); |
|
95 | + /** |
|
96 | + * @param IUser $user |
|
97 | + * @param bool $generatePasswordResetToken |
|
98 | + * @return IEMailTemplate |
|
99 | + */ |
|
100 | + public function generateTemplate(IUser $user, $generatePasswordResetToken = false) { |
|
101 | + $userId = $user->getUID(); |
|
102 | + $lang = $this->l10nFactory->getUserLanguage($user); |
|
103 | + $l10n = $this->l10nFactory->get('settings', $lang); |
|
104 | 104 | |
105 | - if ($generatePasswordResetToken) { |
|
106 | - $token = $this->secureRandom->generate( |
|
107 | - 21, |
|
108 | - ISecureRandom::CHAR_DIGITS . |
|
109 | - ISecureRandom::CHAR_LOWER . |
|
110 | - ISecureRandom::CHAR_UPPER |
|
111 | - ); |
|
112 | - $tokenValue = $this->timeFactory->getTime() . ':' . $token; |
|
113 | - $mailAddress = (null !== $user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
|
114 | - $encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress . $this->config->getSystemValue('secret')); |
|
115 | - $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
|
116 | - $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]); |
|
117 | - } else { |
|
118 | - $link = $this->urlGenerator->getAbsoluteURL('/'); |
|
119 | - } |
|
120 | - $displayName = $user->getDisplayName(); |
|
105 | + if ($generatePasswordResetToken) { |
|
106 | + $token = $this->secureRandom->generate( |
|
107 | + 21, |
|
108 | + ISecureRandom::CHAR_DIGITS . |
|
109 | + ISecureRandom::CHAR_LOWER . |
|
110 | + ISecureRandom::CHAR_UPPER |
|
111 | + ); |
|
112 | + $tokenValue = $this->timeFactory->getTime() . ':' . $token; |
|
113 | + $mailAddress = (null !== $user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
|
114 | + $encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress . $this->config->getSystemValue('secret')); |
|
115 | + $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
|
116 | + $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]); |
|
117 | + } else { |
|
118 | + $link = $this->urlGenerator->getAbsoluteURL('/'); |
|
119 | + } |
|
120 | + $displayName = $user->getDisplayName(); |
|
121 | 121 | |
122 | - $emailTemplate = $this->mailer->createEMailTemplate('settings.Welcome', [ |
|
123 | - 'link' => $link, |
|
124 | - 'displayname' => $displayName, |
|
125 | - 'userid' => $userId, |
|
126 | - 'instancename' => $this->themingDefaults->getName(), |
|
127 | - 'resetTokenGenerated' => $generatePasswordResetToken, |
|
128 | - ]); |
|
122 | + $emailTemplate = $this->mailer->createEMailTemplate('settings.Welcome', [ |
|
123 | + 'link' => $link, |
|
124 | + 'displayname' => $displayName, |
|
125 | + 'userid' => $userId, |
|
126 | + 'instancename' => $this->themingDefaults->getName(), |
|
127 | + 'resetTokenGenerated' => $generatePasswordResetToken, |
|
128 | + ]); |
|
129 | 129 | |
130 | - $emailTemplate->setSubject($l10n->t('Your %s account was created', [$this->themingDefaults->getName()])); |
|
131 | - $emailTemplate->addHeader(); |
|
132 | - if ($displayName === $userId) { |
|
133 | - $emailTemplate->addHeading($l10n->t('Welcome aboard')); |
|
134 | - } else { |
|
135 | - $emailTemplate->addHeading($l10n->t('Welcome aboard %s', [$displayName])); |
|
136 | - } |
|
137 | - $emailTemplate->addBodyText($l10n->t('Welcome to your %s account, you can add, protect, and share your data.', [$this->themingDefaults->getName()])); |
|
138 | - if ($user->getBackendClassName() !== 'LDAP') { |
|
139 | - $emailTemplate->addBodyText($l10n->t('Your username is: %s', [$userId])); |
|
140 | - } |
|
141 | - if ($generatePasswordResetToken) { |
|
142 | - $leftButtonText = $l10n->t('Set your password'); |
|
143 | - } else { |
|
144 | - $leftButtonText = $l10n->t('Go to %s', [$this->themingDefaults->getName()]); |
|
145 | - } |
|
130 | + $emailTemplate->setSubject($l10n->t('Your %s account was created', [$this->themingDefaults->getName()])); |
|
131 | + $emailTemplate->addHeader(); |
|
132 | + if ($displayName === $userId) { |
|
133 | + $emailTemplate->addHeading($l10n->t('Welcome aboard')); |
|
134 | + } else { |
|
135 | + $emailTemplate->addHeading($l10n->t('Welcome aboard %s', [$displayName])); |
|
136 | + } |
|
137 | + $emailTemplate->addBodyText($l10n->t('Welcome to your %s account, you can add, protect, and share your data.', [$this->themingDefaults->getName()])); |
|
138 | + if ($user->getBackendClassName() !== 'LDAP') { |
|
139 | + $emailTemplate->addBodyText($l10n->t('Your username is: %s', [$userId])); |
|
140 | + } |
|
141 | + if ($generatePasswordResetToken) { |
|
142 | + $leftButtonText = $l10n->t('Set your password'); |
|
143 | + } else { |
|
144 | + $leftButtonText = $l10n->t('Go to %s', [$this->themingDefaults->getName()]); |
|
145 | + } |
|
146 | 146 | |
147 | - $clientDownload = $this->config->getSystemValue('customclient_desktop', 'https://nextcloud.com/install/#install-clients'); |
|
148 | - if ($clientDownload === '') { |
|
149 | - $emailTemplate->addBodyButton( |
|
150 | - $leftButtonText, |
|
151 | - $link |
|
152 | - ); |
|
153 | - } else { |
|
154 | - $emailTemplate->addBodyButtonGroup( |
|
155 | - $leftButtonText, |
|
156 | - $link, |
|
157 | - $l10n->t('Install Client'), |
|
158 | - $clientDownload |
|
159 | - ); |
|
160 | - } |
|
147 | + $clientDownload = $this->config->getSystemValue('customclient_desktop', 'https://nextcloud.com/install/#install-clients'); |
|
148 | + if ($clientDownload === '') { |
|
149 | + $emailTemplate->addBodyButton( |
|
150 | + $leftButtonText, |
|
151 | + $link |
|
152 | + ); |
|
153 | + } else { |
|
154 | + $emailTemplate->addBodyButtonGroup( |
|
155 | + $leftButtonText, |
|
156 | + $link, |
|
157 | + $l10n->t('Install Client'), |
|
158 | + $clientDownload |
|
159 | + ); |
|
160 | + } |
|
161 | 161 | |
162 | - $emailTemplate->addFooter(); |
|
162 | + $emailTemplate->addFooter(); |
|
163 | 163 | |
164 | - return $emailTemplate; |
|
165 | - } |
|
164 | + return $emailTemplate; |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * Sends a welcome mail to $user |
|
169 | - * |
|
170 | - * @param IUser $user |
|
171 | - * @param IEmailTemplate $emailTemplate |
|
172 | - * @throws \Exception If mail could not be sent |
|
173 | - */ |
|
174 | - public function sendMail(IUser $user, |
|
175 | - IEMailTemplate $emailTemplate) { |
|
176 | - $message = $this->mailer->createMessage(); |
|
177 | - $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); |
|
178 | - $message->setFrom([$this->fromAddress => $this->themingDefaults->getName()]); |
|
179 | - $message->useTemplate($emailTemplate); |
|
180 | - $this->mailer->send($message); |
|
181 | - } |
|
167 | + /** |
|
168 | + * Sends a welcome mail to $user |
|
169 | + * |
|
170 | + * @param IUser $user |
|
171 | + * @param IEmailTemplate $emailTemplate |
|
172 | + * @throws \Exception If mail could not be sent |
|
173 | + */ |
|
174 | + public function sendMail(IUser $user, |
|
175 | + IEMailTemplate $emailTemplate) { |
|
176 | + $message = $this->mailer->createMessage(); |
|
177 | + $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); |
|
178 | + $message->setFrom([$this->fromAddress => $this->themingDefaults->getName()]); |
|
179 | + $message->useTemplate($emailTemplate); |
|
180 | + $this->mailer->send($message); |
|
181 | + } |
|
182 | 182 | } |