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