lonnieezell / Bonfire

Jumpstart your CodeIgniter web applications with a modular, HMVC-ready, backend.
http://cibonfire.com
1.39k stars 525 forks source link

Can't CC or send additional email to Web Admin for Notification of User Registrations #1307

Closed OAVHomeAdmin closed 5 years ago

OAVHomeAdmin commented 5 years ago

Hello,

I am currently building multiple websites on the CodeIgniter 3 and CI Bonfire 0.7 Infrastructures and all of the Website Owners would like to at least receive a notification once a user registers for there website. I have been fumbling with this issue for some time now and I've come to no resolve in getting this working.

I have attempted to add a 'cc' to the activate($user_id = null) function in the User Model, to no avail. Does anyone have any examples to reference or has this ever even been functional?

silverark commented 5 years ago

Why not just send them an email in the register method in the user controller?

$this->load->library('emailer/emailer');
$data = array(
     'to'       => 'siteadmin@owner.com',
     'subject'  => 'New user has signed up',
     'message'  => 'A new user has signed up. Their details are blah blah blah'
);

 $this->emailer->send($data);

I also added in a bcc variable to the emailer.php library so I could pass this through as a data attribute to send_email if that's what you are looking to do which just passes it to codeigniter: $this->ci->email->bcc($bcc);

OAVHomeAdmin commented 5 years ago

Why not just send them an email in the register method in the user controller?

$this->load->library('emailer/emailer');
$data = array(
     'to'     => 'siteadmin@owner.com',
     'subject'    => 'New user has signed up',
     'message'    => 'A new user has signed up. Their details are blah blah blah'
);

 $this->emailer->send($data);

I also added in a bcc variable to the emailer.php library so I could pass this through as a data attribute to send_email if that's what you are looking to do which just passes it to codeigniter: $this->ci->email->bcc($bcc);

Would I place this within the if (isset($_POST['register'])) method of the function after the Template::set_message($message, $error ? 'error' : 'success'); ?

Like so,

`public function register() { // Are users allowed to register? if (! $this->settings_lib->item('auth.allow_register')) { Template::set_message(lang('us_register_disabled'), 'error'); Template::redirect('/'); }

    $register_url = $this->input->post('register_url') ?: REGISTER_URL;
    $login_url    = $this->input->post('login_url') ?: LOGIN_URL;

    $this->load->model('roles/role_model');
    $this->load->helper('date');

    $this->load->config('address');
    $this->load->helper('address');

    $this->load->config('user_meta');
    $meta_fields = config_item('user_meta_fields');
    Template::set('meta_fields', $meta_fields);

    if (isset($_POST['register'])) {
        if ($userId = $this->saveUser('insert', 0, $meta_fields)) {
            // User Activation
            $activation = $this->user_model->set_activation($userId);
            $message = $activation['message'];
            $error   = $activation['error'];

            Template::set_message($message, $error ? 'error' : 'success');

            $this->load->library('emailer/emailer');
            $data = array(
                    'to'        => 'siteadmin@owner.com',
                    'subject'   => 'New user has signed up',
                   'message'    => 'A new user has signed up. Their details are blah blah blah'
             );

            $this->emailer->send($data);

             log_activity($userId, lang('us_log_register'), 'users');
            Template::redirect($login_url);

        }

        Template::set_message(lang('us_registration_fail'), 'error');
        // Don't redirect because validation errors will be lost.
    }

    if ($this->siteSettings['auth.password_show_labels'] == 1) {
        Assets::add_js(
            $this->load->view('users_js', array('settings' => $this->siteSettings), true),
            'inline'
        );
    }

    // Generate password hint messages.
    $this->user_model->password_hints();

    Template::set_view('users/register');
    Template::set('languages', unserialize($this->settings_lib->item('site.languages')));
    Template::set('page_title', 'Register');
    Template::render();
}`
silverark commented 5 years ago

Probably the simplest way to do it. You can load a view for the message template if you needed to too.

OAVHomeAdmin commented 5 years ago

Okay, testing!

In the meantime, can I ask you another question, do you have an example template or a link to a good example for a File Uploader for CI Bonfire?