@@ -42,148 +42,148 @@ |
||
| 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('', $lang); |
|
| 162 | + $emailTemplate->addFooter('', $lang); |
|
| 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): void { |
|
| 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): void { |
|
| 176 | 176 | |
| 177 | - // Be sure to never try to send to an empty e-mail |
|
| 178 | - $email = $user->getEMailAddress(); |
|
| 179 | - if ($email === null) { |
|
| 180 | - return; |
|
| 181 | - } |
|
| 177 | + // Be sure to never try to send to an empty e-mail |
|
| 178 | + $email = $user->getEMailAddress(); |
|
| 179 | + if ($email === null) { |
|
| 180 | + return; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - $message = $this->mailer->createMessage(); |
|
| 184 | - $message->setTo([$email => $user->getDisplayName()]); |
|
| 185 | - $message->setFrom([$this->fromAddress => $this->themingDefaults->getName()]); |
|
| 186 | - $message->useTemplate($emailTemplate); |
|
| 187 | - $this->mailer->send($message); |
|
| 188 | - } |
|
| 183 | + $message = $this->mailer->createMessage(); |
|
| 184 | + $message->setTo([$email => $user->getDisplayName()]); |
|
| 185 | + $message->setFrom([$this->fromAddress => $this->themingDefaults->getName()]); |
|
| 186 | + $message->useTemplate($emailTemplate); |
|
| 187 | + $this->mailer->send($message); |
|
| 188 | + } |
|
| 189 | 189 | } |
@@ -38,62 +38,62 @@ |
||
| 38 | 38 | |
| 39 | 39 | class HelpController extends Controller { |
| 40 | 40 | |
| 41 | - /** @var INavigationManager */ |
|
| 42 | - private $navigationManager; |
|
| 43 | - /** @var IURLGenerator */ |
|
| 44 | - private $urlGenerator; |
|
| 45 | - /** @var IGroupManager */ |
|
| 46 | - private $groupManager; |
|
| 41 | + /** @var INavigationManager */ |
|
| 42 | + private $navigationManager; |
|
| 43 | + /** @var IURLGenerator */ |
|
| 44 | + private $urlGenerator; |
|
| 45 | + /** @var IGroupManager */ |
|
| 46 | + private $groupManager; |
|
| 47 | 47 | |
| 48 | - /** @var string */ |
|
| 49 | - private $userId; |
|
| 48 | + /** @var string */ |
|
| 49 | + private $userId; |
|
| 50 | 50 | |
| 51 | - public function __construct( |
|
| 52 | - string $appName, |
|
| 53 | - IRequest $request, |
|
| 54 | - INavigationManager $navigationManager, |
|
| 55 | - IURLGenerator $urlGenerator, |
|
| 56 | - ?string $userId, |
|
| 57 | - IGroupManager $groupManager |
|
| 58 | - ) { |
|
| 59 | - parent::__construct($appName, $request); |
|
| 60 | - $this->navigationManager = $navigationManager; |
|
| 61 | - $this->urlGenerator = $urlGenerator; |
|
| 62 | - $this->userId = $userId; |
|
| 63 | - $this->groupManager = $groupManager; |
|
| 64 | - } |
|
| 51 | + public function __construct( |
|
| 52 | + string $appName, |
|
| 53 | + IRequest $request, |
|
| 54 | + INavigationManager $navigationManager, |
|
| 55 | + IURLGenerator $urlGenerator, |
|
| 56 | + ?string $userId, |
|
| 57 | + IGroupManager $groupManager |
|
| 58 | + ) { |
|
| 59 | + parent::__construct($appName, $request); |
|
| 60 | + $this->navigationManager = $navigationManager; |
|
| 61 | + $this->urlGenerator = $urlGenerator; |
|
| 62 | + $this->userId = $userId; |
|
| 63 | + $this->groupManager = $groupManager; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @return TemplateResponse |
|
| 68 | - * |
|
| 69 | - * @NoCSRFRequired |
|
| 70 | - * @NoAdminRequired |
|
| 71 | - * @NoSubAdminRequired |
|
| 72 | - */ |
|
| 73 | - public function help(string $mode = 'user'): TemplateResponse { |
|
| 74 | - $this->navigationManager->setActiveEntry('help'); |
|
| 66 | + /** |
|
| 67 | + * @return TemplateResponse |
|
| 68 | + * |
|
| 69 | + * @NoCSRFRequired |
|
| 70 | + * @NoAdminRequired |
|
| 71 | + * @NoSubAdminRequired |
|
| 72 | + */ |
|
| 73 | + public function help(string $mode = 'user'): TemplateResponse { |
|
| 74 | + $this->navigationManager->setActiveEntry('help'); |
|
| 75 | 75 | |
| 76 | - if ($mode !== 'admin') { |
|
| 77 | - $mode = 'user'; |
|
| 78 | - } |
|
| 76 | + if ($mode !== 'admin') { |
|
| 77 | + $mode = 'user'; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - $documentationUrl = $this->urlGenerator->getAbsoluteURL( |
|
| 81 | - $this->urlGenerator->linkTo('core', 'doc/' . $mode . '/index.html') |
|
| 82 | - ); |
|
| 80 | + $documentationUrl = $this->urlGenerator->getAbsoluteURL( |
|
| 81 | + $this->urlGenerator->linkTo('core', 'doc/' . $mode . '/index.html') |
|
| 82 | + ); |
|
| 83 | 83 | |
| 84 | - $urlUserDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'user']); |
|
| 85 | - $urlAdminDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'admin']); |
|
| 84 | + $urlUserDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'user']); |
|
| 85 | + $urlAdminDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'admin']); |
|
| 86 | 86 | |
| 87 | - $response = new TemplateResponse('settings', 'help', [ |
|
| 88 | - 'admin' => $this->groupManager->isAdmin($this->userId), |
|
| 89 | - 'url' => $documentationUrl, |
|
| 90 | - 'urlUserDocs' => $urlUserDocs, |
|
| 91 | - 'urlAdminDocs' => $urlAdminDocs, |
|
| 92 | - 'mode' => $mode, |
|
| 93 | - ]); |
|
| 94 | - $policy = new ContentSecurityPolicy(); |
|
| 95 | - $policy->addAllowedFrameDomain('\'self\''); |
|
| 96 | - $response->setContentSecurityPolicy($policy); |
|
| 97 | - return $response; |
|
| 98 | - } |
|
| 87 | + $response = new TemplateResponse('settings', 'help', [ |
|
| 88 | + 'admin' => $this->groupManager->isAdmin($this->userId), |
|
| 89 | + 'url' => $documentationUrl, |
|
| 90 | + 'urlUserDocs' => $urlUserDocs, |
|
| 91 | + 'urlAdminDocs' => $urlAdminDocs, |
|
| 92 | + 'mode' => $mode, |
|
| 93 | + ]); |
|
| 94 | + $policy = new ContentSecurityPolicy(); |
|
| 95 | + $policy->addAllowedFrameDomain('\'self\''); |
|
| 96 | + $response->setContentSecurityPolicy($policy); |
|
| 97 | + return $response; |
|
| 98 | + } |
|
| 99 | 99 | } |