| @@ -73,8 +73,9 @@ | ||
| 73 | 73 | { |
| 74 | 74 | $enableCreate = $this->getParam('enableCreate', '0'); |
| 75 | 75 | if (empty($user->email) || !empty($user->cms_id) || empty($enableCreate)) return; |
| 76 | 76 | |
| 77 | + // Should we only create from front subscriber creation | |
| 77 | 78 | if ($this->getParam('onlyFront', 'front') === 'front' && acym_isAdmin()) return; |
| 78 | 79 | |
| 79 | 80 | if ('wordpress' === ACYM_CMS) { |
| 80 | 81 | $this->createWordpressUser($user); |
| @@ -93,8 +94,9 @@ | ||
| 93 | 94 | if ($allowUserRegistration == 0) return; |
| 94 | 95 | |
| 95 | 96 | acym_loadLanguageFile('com_users', JPATH_SITE); |
| 96 | 97 | |
| 98 | + // Generate the password | |
| 97 | 99 | $minimum_integers = $joomlaUsersparams->get('minimum_integers'); |
| 98 | 100 | $minimum_symbols = $joomlaUsersparams->get('minimum_symbols'); |
| 99 | 101 | $minimum_uppercase = $joomlaUsersparams->get('minimum_uppercase'); |
| 100 | 102 | $length = 8; |
| @@ -102,8 +104,9 @@ | ||
| 102 | 104 | $tryCount = 0; |
| 103 | 105 | do { |
| 104 | 106 | $password = UserHelper::genrandompassword($length); |
| 105 | 107 | $tryCount++; |
| 108 | + //Could happen if the admin selected 90 as min integers and min length = 9, in this case we will never generate a satisfying password | |
| 106 | 109 | if ($tryCount > 50) break; |
| 107 | 110 | } while ($this->getConditionPassword($password, $minimum_integers, $minimum_symbols, $minimum_uppercase)); |
| 108 | 111 | |
| 109 | 112 | $defaultUsergroup = $joomlaUsersparams->get('new_usertype'); |
| @@ -123,21 +126,26 @@ | ||
| 123 | 126 | ]; |
| 124 | 127 | |
| 125 | 128 | $joomlaUser = new User(); |
| 126 | 129 | |
| 130 | + // Check if the user needs to activate his account. | |
| 127 | 131 | if (in_array($useractivation, [1, 2])) { |
| 128 | 132 | $userData['activation'] = ApplicationHelper::getHash(UserHelper::genrandompassword()); |
| 129 | 133 | $userData['block'] = 1; |
| 130 | 134 | } |
| 131 | 135 | |
| 136 | + // Write to database | |
| 132 | 137 | if (!$joomlaUser->bind($userData)) return false; |
| 138 | + // Store the data. | |
| 133 | 139 | if (!$this->save($joomlaUser)) return false; |
| 134 | 140 | |
| 135 | 141 | $user->cms_id = $joomlaUser->id; |
| 136 | 142 | $userClass = new UserClass(); |
| 143 | + // We don't want to send the confirmation because it already has been set in the AcyMailing user creation | |
| 137 | 144 | $userClass->sendConf = false; |
| 138 | 145 | $userClass->save($user); |
| 139 | 146 | |
| 147 | + // Compile the notification mail values. | |
| 140 | 148 | $data = $joomlaUser->getProperties(); |
| 141 | 149 | $data['fromname'] = $joomlaConfig->get('fromname'); |
| 142 | 150 | $data['mailfrom'] = $joomlaConfig->get('mailfrom'); |
| 143 | 151 | $data['sitename'] = $joomlaConfig->get('sitename'); |
| @@ -142,8 +150,9 @@ | ||
| 142 | 150 | $data['mailfrom'] = $joomlaConfig->get('mailfrom'); |
| 143 | 151 | $data['sitename'] = $joomlaConfig->get('sitename'); |
| 144 | 152 | $data['siteurl'] = str_replace('/administrator', '', acym_baseURI()); |
| 145 | 153 | |
| 154 | + // Handle account activation/confirmation emails. | |
| 146 | 155 | $emailSubject = acym_translationSprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); |
| 147 | 156 | if (in_array($useractivation, [1, 2])) { |
| 148 | 157 | $base = acym_currentURL(); |
| 149 | 158 | $activationLink = 'index.php?option=com_users&task=registration.activate&token='; |
| @@ -181,8 +190,9 @@ | ||
| 181 | 190 | $data['password_clear'] |
| 182 | 191 | ); |
| 183 | 192 | } |
| 184 | 193 | |
| 194 | + // Replace variables for Joomla 4 | |
| 185 | 195 | if (ACYM_J40) { |
| 186 | 196 | $keys = []; |
| 187 | 197 | $replaceData = []; |
| 188 | 198 | foreach ($data as $key => $oneKey) { |
| @@ -195,13 +205,21 @@ | ||
| 195 | 205 | $emailBody = str_replace($keys, $replaceData, $emailBody); |
| 196 | 206 | } |
| 197 | 207 | |
| 198 | 208 | $mailer = Factory::getMailer(); |
| 209 | + /* Set a sender - The sender of an email is set with setSender. The function takes an array with an email address and a name as an argument. | |
| 210 | + We fetch the site's email address and name from the global configuration. | |
| 211 | + This info is set in Global Configuration -> Server -> Mail Settings. */ | |
| 199 | 212 | $sender = [$joomlaConfig->get('mailfrom'), $joomlaConfig->get('fromname')]; |
| 200 | 213 | $mailer->setSender($sender); |
| 214 | + /* Recipient - You set the recipient of an email with the function addRecipient. | |
| 215 | + To set the email address to the currently logged in user, we fetch it from the user object. */ | |
| 201 | 216 | $mailer->addRecipient($user->email); |
| 217 | + /* Set the subject and the body. The easy way to create an email body is as a string with plain text. | |
| 218 | + You can also attach a file with addAttachment. It takes a single file name or an array of file names as argument.*/ | |
| 202 | 219 | $mailer->setSubject($emailSubject); |
| 203 | 220 | $mailer->setBody($emailBody); |
| 221 | + // Send the mail - It is sent with the function Send. It returns true on success or a JError object. | |
| 204 | 222 | $send = $mailer->Send(); |
| 205 | 223 | if ($send !== true) return false; |
| 206 | 224 | } |
| 207 | 225 | |
| @@ -206,8 +224,9 @@ | ||
| 206 | 224 | } |
| 207 | 225 | |
| 208 | 226 | public function save($joomlaUser) |
| 209 | 227 | { |
| 228 | + // Create the user table object | |
| 210 | 229 | $table = $joomlaUser->getTable(); |
| 211 | 230 | $joomlaUser->params = '{}'; |
| 212 | 231 | $table->bind($joomlaUser->getProperties()); |
| 213 | 232 | |
| @@ -228,15 +247,18 @@ | ||
| 228 | 247 | if (($my->id == 0 && !$isNew) && $joomlaUser->id == $oldUser->id && $oldUser->authorise('core.admin') && $oldUser->password != $joomlaUser->password) { |
| 229 | 248 | $iAmRehashingSuperadmin = true; |
| 230 | 249 | } |
| 231 | 250 | |
| 251 | + // We are only worried about edits to this account if I am not a Super Admin. | |
| 232 | 252 | $iAmSuperAdmin = $my->authorise('core.admin'); |
| 233 | 253 | if ($iAmSuperAdmin != true && $iAmRehashingSuperadmin != true) { |
| 254 | + // I am not a Super Admin, and this one is, so fail. | |
| 234 | 255 | if (!$isNew && Access::check($joomlaUser->id, 'core.admin')) { |
| 235 | 256 | throw new \RuntimeException('User not Super Administrator'); |
| 236 | 257 | } |
| 237 | 258 | |
| 238 | 259 | if ($joomlaUser->groups != null) { |
| 260 | + // I am not a Super Admin and I'm trying to make one. | |
| 239 | 261 | foreach ($joomlaUser->groups as $groupId) { |
| 240 | 262 | if (Access::checkGroup($groupId, 'core.admin')) { |
| 241 | 263 | throw new \RuntimeException('User not Super Administrator'); |
| 242 | 264 | } |
| @@ -243,8 +265,9 @@ | ||
| 243 | 265 | } |
| 244 | 266 | } |
| 245 | 267 | } |
| 246 | 268 | |
| 269 | + // Fire the onUserBeforeSave event. | |
| 247 | 270 | PluginHelper::importPlugin('user'); |
| 248 | 271 | if (ACYM_J40) { |
| 249 | 272 | $result = Factory::getApplication()->triggerEvent('onUserBeforeSave', [$oldUser->getProperties(), $isNew, $joomlaUser->getProperties()]); |
| 250 | 273 | } else { |
| @@ -288,8 +311,9 @@ | ||
| 288 | 311 | return false; |
| 289 | 312 | } else { |
| 290 | 313 | $user->cms_id = $result; |
| 291 | 314 | $userClass = new UserClass(); |
| 315 | + // We don't want to send the confirmation because it already has been set in the AcyMailing user creation | |
| 292 | 316 | $userClass->sendConf = false; |
| 293 | 317 | $userClass->save($user); |
| 294 | 318 | $wpUser = new WP_User($result); |
| 295 | 319 | $wpUser->set_role($configUserGroup); |