/** * Save user * * @param \Pop\Form\Form $form * @param \Pop\Config $config * @return void */ public function save(\Pop\Form\Form $form, $config) { $encOptions = $config->encryptionOptions->asArray(); $fields = $form->getFields(); $type = Table\UserTypes::findById($fields['type_id']); $password = isset($fields['password1']) ? self::encryptPassword($fields['password1'], $type->password_encryption, $encOptions) : ''; // Set the username according to user type $username = isset($fields['username']) ? $fields['username'] : $fields['email1']; // Set the role according to user type if (isset($fields['role_id'])) { $fields['role_id'] = $fields['role_id'] == 0 ? null : $fields['role_id']; } else { $fields['role_id'] = $type->approval ? null : $type->default_role_id; } // Set verified or not if (!isset($fields['verified'])) { $fields['verified'] = $type->verification ? 0 : 1; } if (isset($fields['site_ids'])) { $siteIds = $fields['site_ids']; } else { $site = Table\Sites::getSite(); $siteIds = array($site->id); } // Save the new user $user = new Table\Users(array('type_id' => $fields['type_id'], 'role_id' => $fields['role_id'], 'username' => $username, 'password' => $password, 'email' => $fields['email1'], 'verified' => $fields['verified'], 'logins' => null, 'failed_attempts' => 0, 'site_ids' => serialize($siteIds), 'created' => date('Y-m-d H:i:s'))); $user->save(); $this->data['id'] = $user->id; $sess = Session::getInstance(); $sess->last_user_id = $user->id; FieldValue::save($fields, $user->id); // Send verification if needed if ($type->verification && !$user->verified) { $this->sendVerification($user, $type); } // Send registration notification to system admin if ($type->registration_notification) { $this->sendNotification($user, $type); } $form->clear(); }
/** * Send user password reminder notification * * @param Table\Users $user * @return void */ protected function sendReminder(Table\Users $user) { $host = Table\Config::findById('domain')->value; $domain = str_replace('www.', '', $host); $newPassword = Random::create(8, Random::ALPHANUM | Random::LOWERCASE); $user->password = (new Bcrypt())->create($newPassword); $user->save(); // Set the recipient $rcpt = ['name' => $user->username, 'email' => $user->email, 'domain' => $domain, 'username' => $user->username, 'password' => $newPassword]; // Check for an override template $mailTemplate = file_exists(CONTENT_ABS_PATH . '/phire/view/phire/mail/forgot.txt') ? CONTENT_ABS_PATH . '/phire/view/phire/mail/forgot.txt' : __DIR__ . '/../../view/phire/mail/forgot.txt'; // Send email verification $mail = new Mail($domain . ' - Forgot Password', $rcpt); $mail->from('noreply@' . $domain); $mail->setText(file_get_contents($mailTemplate)); $mail->send(); }