Completed
Push — master ( b6e759...e9c713 )
by Morris
13:15
created
settings/Mailer/NewUserMailHelper.php 1 patch
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -33,136 +33,136 @@
 block discarded – undo
33 33
 use OCP\Security\ISecureRandom;
34 34
 
35 35
 class NewUserMailHelper {
36
-	/** @var Defaults */
37
-	private $themingDefaults;
38
-	/** @var IURLGenerator */
39
-	private $urlGenerator;
40
-	/** @var IL10N */
41
-	private $l10n;
42
-	/** @var IMailer */
43
-	private $mailer;
44
-	/** @var ISecureRandom */
45
-	private $secureRandom;
46
-	/** @var ITimeFactory */
47
-	private $timeFactory;
48
-	/** @var IConfig */
49
-	private $config;
50
-	/** @var ICrypto */
51
-	private $crypto;
52
-	/** @var string */
53
-	private $fromAddress;
36
+    /** @var Defaults */
37
+    private $themingDefaults;
38
+    /** @var IURLGenerator */
39
+    private $urlGenerator;
40
+    /** @var IL10N */
41
+    private $l10n;
42
+    /** @var IMailer */
43
+    private $mailer;
44
+    /** @var ISecureRandom */
45
+    private $secureRandom;
46
+    /** @var ITimeFactory */
47
+    private $timeFactory;
48
+    /** @var IConfig */
49
+    private $config;
50
+    /** @var ICrypto */
51
+    private $crypto;
52
+    /** @var string */
53
+    private $fromAddress;
54 54
 
55
-	/**
56
-	 * @param Defaults $themingDefaults
57
-	 * @param IURLGenerator $urlGenerator
58
-	 * @param IL10N $l10n
59
-	 * @param IMailer $mailer
60
-	 * @param ISecureRandom $secureRandom
61
-	 * @param ITimeFactory $timeFactory
62
-	 * @param IConfig $config
63
-	 * @param ICrypto $crypto
64
-	 * @param string $fromAddress
65
-	 */
66
-	public function __construct(Defaults $themingDefaults,
67
-								IURLGenerator $urlGenerator,
68
-								IL10N $l10n,
69
-								IMailer $mailer,
70
-								ISecureRandom $secureRandom,
71
-								ITimeFactory $timeFactory,
72
-								IConfig $config,
73
-								ICrypto $crypto,
74
-								$fromAddress) {
75
-		$this->themingDefaults = $themingDefaults;
76
-		$this->urlGenerator = $urlGenerator;
77
-		$this->l10n = $l10n;
78
-		$this->mailer = $mailer;
79
-		$this->secureRandom = $secureRandom;
80
-		$this->timeFactory = $timeFactory;
81
-		$this->config = $config;
82
-		$this->crypto = $crypto;
83
-		$this->fromAddress = $fromAddress;
84
-	}
55
+    /**
56
+     * @param Defaults $themingDefaults
57
+     * @param IURLGenerator $urlGenerator
58
+     * @param IL10N $l10n
59
+     * @param IMailer $mailer
60
+     * @param ISecureRandom $secureRandom
61
+     * @param ITimeFactory $timeFactory
62
+     * @param IConfig $config
63
+     * @param ICrypto $crypto
64
+     * @param string $fromAddress
65
+     */
66
+    public function __construct(Defaults $themingDefaults,
67
+                                IURLGenerator $urlGenerator,
68
+                                IL10N $l10n,
69
+                                IMailer $mailer,
70
+                                ISecureRandom $secureRandom,
71
+                                ITimeFactory $timeFactory,
72
+                                IConfig $config,
73
+                                ICrypto $crypto,
74
+                                $fromAddress) {
75
+        $this->themingDefaults = $themingDefaults;
76
+        $this->urlGenerator = $urlGenerator;
77
+        $this->l10n = $l10n;
78
+        $this->mailer = $mailer;
79
+        $this->secureRandom = $secureRandom;
80
+        $this->timeFactory = $timeFactory;
81
+        $this->config = $config;
82
+        $this->crypto = $crypto;
83
+        $this->fromAddress = $fromAddress;
84
+    }
85 85
 
86
-	/**
87
-	 * Set the IL10N object
88
-	 *
89
-	 * @param IL10N $l10n
90
-	 */
91
-	public function setL10N(IL10N $l10n) {
92
-		$this->l10n = $l10n;
93
-	}
86
+    /**
87
+     * Set the IL10N object
88
+     *
89
+     * @param IL10N $l10n
90
+     */
91
+    public function setL10N(IL10N $l10n) {
92
+        $this->l10n = $l10n;
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
-		if ($generatePasswordResetToken) {
102
-			$token = $this->secureRandom->generate(
103
-				21,
104
-				ISecureRandom::CHAR_DIGITS .
105
-				ISecureRandom::CHAR_LOWER .
106
-				ISecureRandom::CHAR_UPPER
107
-			);
108
-			$tokenValue = $this->timeFactory->getTime() . ':' . $token;
109
-			$mailAddress = (null !== $user->getEMailAddress()) ? $user->getEMailAddress() : '';
110
-			$encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress . $this->config->getSystemValue('secret'));
111
-			$this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue);
112
-			$link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]);
113
-		} else {
114
-			$link = $this->urlGenerator->getAbsoluteURL('/');
115
-		}
116
-		$displayName = $user->getDisplayName();
117
-		$userId = $user->getUID();
95
+    /**
96
+     * @param IUser $user
97
+     * @param bool $generatePasswordResetToken
98
+     * @return IEMailTemplate
99
+     */
100
+    public function generateTemplate(IUser $user, $generatePasswordResetToken = false) {
101
+        if ($generatePasswordResetToken) {
102
+            $token = $this->secureRandom->generate(
103
+                21,
104
+                ISecureRandom::CHAR_DIGITS .
105
+                ISecureRandom::CHAR_LOWER .
106
+                ISecureRandom::CHAR_UPPER
107
+            );
108
+            $tokenValue = $this->timeFactory->getTime() . ':' . $token;
109
+            $mailAddress = (null !== $user->getEMailAddress()) ? $user->getEMailAddress() : '';
110
+            $encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress . $this->config->getSystemValue('secret'));
111
+            $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue);
112
+            $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]);
113
+        } else {
114
+            $link = $this->urlGenerator->getAbsoluteURL('/');
115
+        }
116
+        $displayName = $user->getDisplayName();
117
+        $userId = $user->getUID();
118 118
 
119
-		$emailTemplate = $this->mailer->createEMailTemplate('settings.Welcome', [
120
-			'link' => $link,
121
-			'displayname' => $displayName,
122
-			'userid' => $userId,
123
-			'instancename' => $this->themingDefaults->getName(),
124
-			'resetTokenGenerated' => $generatePasswordResetToken,
125
-		]);
119
+        $emailTemplate = $this->mailer->createEMailTemplate('settings.Welcome', [
120
+            'link' => $link,
121
+            'displayname' => $displayName,
122
+            'userid' => $userId,
123
+            'instancename' => $this->themingDefaults->getName(),
124
+            'resetTokenGenerated' => $generatePasswordResetToken,
125
+        ]);
126 126
 
127
-		$emailTemplate->addHeader();
128
-		if ($displayName === $userId) {
129
-			$emailTemplate->addHeading($this->l10n->t('Welcome aboard'));
130
-		} else {
131
-			$emailTemplate->addHeading($this->l10n->t('Welcome aboard %s', [$displayName]));
132
-		}
133
-		$emailTemplate->addBodyText($this->l10n->t('You now have an %s account, you can add, protect, and share your data.', [$this->themingDefaults->getName()]));
134
-		$emailTemplate->addBodyText($this->l10n->t('Your username is: %s', [$userId]));
135
-		if ($generatePasswordResetToken) {
136
-			$leftButtonText = $this->l10n->t('Set your password');
137
-		} else {
138
-			$leftButtonText = $this->l10n->t('Go to %s', [$this->themingDefaults->getName()]);
139
-		}
140
-		$emailTemplate->addBodyButtonGroup(
141
-			$leftButtonText,
142
-			$link,
143
-			$this->l10n->t('Install Client'),
144
-			'https://nextcloud.com/install/#install-clients'
145
-		);
146
-		$emailTemplate->addFooter();
127
+        $emailTemplate->addHeader();
128
+        if ($displayName === $userId) {
129
+            $emailTemplate->addHeading($this->l10n->t('Welcome aboard'));
130
+        } else {
131
+            $emailTemplate->addHeading($this->l10n->t('Welcome aboard %s', [$displayName]));
132
+        }
133
+        $emailTemplate->addBodyText($this->l10n->t('You now have an %s account, you can add, protect, and share your data.', [$this->themingDefaults->getName()]));
134
+        $emailTemplate->addBodyText($this->l10n->t('Your username is: %s', [$userId]));
135
+        if ($generatePasswordResetToken) {
136
+            $leftButtonText = $this->l10n->t('Set your password');
137
+        } else {
138
+            $leftButtonText = $this->l10n->t('Go to %s', [$this->themingDefaults->getName()]);
139
+        }
140
+        $emailTemplate->addBodyButtonGroup(
141
+            $leftButtonText,
142
+            $link,
143
+            $this->l10n->t('Install Client'),
144
+            'https://nextcloud.com/install/#install-clients'
145
+        );
146
+        $emailTemplate->addFooter();
147 147
 
148
-		return $emailTemplate;
149
-	}
148
+        return $emailTemplate;
149
+    }
150 150
 
151
-	/**
152
-	 * Sends a welcome mail to $user
153
-	 *
154
-	 * @param IUser $user
155
-	 * @param IEmailTemplate $emailTemplate
156
-	 * @throws \Exception If mail could not be sent
157
-	 */
158
-	public function sendMail(IUser $user,
159
-							 IEMailTemplate $emailTemplate) {
160
-		$message = $this->mailer->createMessage();
161
-		$message->setTo([$user->getEMailAddress() => $user->getDisplayName()]);
162
-		$message->setSubject($this->l10n->t('Your %s account was created', [$this->themingDefaults->getName()]));
163
-		$message->setHtmlBody($emailTemplate->renderHtml());
164
-		$message->setPlainBody($emailTemplate->renderText());
165
-		$message->setFrom([$this->fromAddress => $this->themingDefaults->getName()]);
166
-		$this->mailer->send($message);
167
-	}
151
+    /**
152
+     * Sends a welcome mail to $user
153
+     *
154
+     * @param IUser $user
155
+     * @param IEmailTemplate $emailTemplate
156
+     * @throws \Exception If mail could not be sent
157
+     */
158
+    public function sendMail(IUser $user,
159
+                                IEMailTemplate $emailTemplate) {
160
+        $message = $this->mailer->createMessage();
161
+        $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]);
162
+        $message->setSubject($this->l10n->t('Your %s account was created', [$this->themingDefaults->getName()]));
163
+        $message->setHtmlBody($emailTemplate->renderHtml());
164
+        $message->setPlainBody($emailTemplate->renderText());
165
+        $message->setFrom([$this->fromAddress => $this->themingDefaults->getName()]);
166
+        $this->mailer->send($message);
167
+    }
168 168
 }
Please login to merge, or discard this patch.