I have been playing around with CI4 and Shield for authentication and authorisation. There is very little information out there on the work flow for registering new users and how to notify the user that they have been registered into the app. Any help would appreciated?
Here is my controller function so far:
type// Add a member
public function add_member()
{
$data = [];
//$users = model('UserModel');
if ($this->request->getMethod() == 'post') {
$rules = [
//'membership_status' =>
'firstname' => 'required|min_length[3]|max_length[50]',
'lastname' => 'required|min_length[3]|max_length[50]',
'prefered_name' => 'min_length[3]|max_length[50]',
'gender' => 'required|min_length[3]|max_length[25]',
'date_of_birth' => 'required|valid_date',
'address_1' => 'required|min_length[3]|max_length[100]',
'address_2' => 'required|min_length[3]|max_length[100]',
'postal_code' => 'required|min_length[3]|max_length[10]|integer',
'city' => 'required|min_length[3]|max_length[50]',
'home_phone' => 'min_length[3]|max_length[50]',
'work_phone' => 'min_length[3]|max_length[50]',
'mobile' => 'required_without[home_phone,work_phone]|min_length[3]|max_length[50]',
'consent' => 'min_length[2]|max_length[50]',
//'email' => 'required|min_length[6]|max_length[50]|valid_email',
];
if (!$this->validate($rules)) {
$data['validation'] = $this->validator;
$this->session->set('Details', $_POST);
//dd($_SESSION);
} else {
$newData = [
//'id' => $id,
'membership_status' => 'Active',
'firstname' => $this->request->getVar('firstname', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
'lastname' => $this->request->getVar('lastname', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
'prefered_name' => $this->request->getVar('prefered_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
'date_joined' => date('Y-m-d'),
'gender' => $this->request->getVar('gender', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
'date_of_birth' => $this->request->getVar('date_of_birth'),
'address_1' => $this->request->getVar('address_1', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
'address_2' => $this->request->getVar('address_2', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
'postal_code' => $this->request->getVar('postal_code', FILTER_SANITIZE_NUMBER_INT),
'city' => $this->request->getVar('city', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
'home_phone' => $this->request->getVar('home_phone', FILTER_SANITIZE_NUMBER_INT),
'work_phone' => $this->request->getVar('work_phone', FILTER_SANITIZE_NUMBER_INT),
'mobile' => $this->request->getVar('mobile', FILTER_SANITIZE_NUMBER_INT),
'consent' => $this->request->getVar('consent'),
//'email' => $this->request->getVar('email', FILTER_SANITIZE_EMAIL)
];
$user = new User([
'username' => NULL,
'email' => $this->request->getVar('email', FILTER_SANITIZE_EMAIL),
'password' => $this->request->getVar('email', FILTER_SANITIZE_EMAIL),
]);
$this->users->save($user);
$newData['id'] = $this->users->getInsertID();
// To get the complete user object with ID, we need to get from the database
$user = $this->users->findById($this->users->getInsertID());
// Add to default group
$this->users->addToDefaultGroup($user);
$this->users->save($newData);
$userEmail['email'] = $user->getEmail();
// Send the user an email with the code
$email = emailer()->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '');
$email->setTo($user->email);
$email->setSubject(lang('DojoApp.mailSubject'));
$email->setMessage($this->view('email/add_new_user_email', $userEmail));
if ($email->send(false) === false) {
log_message('error', $email->printDebugger(['headers']));
return redirect()->route('login')->with('error', lang('Auth.unableSendEmailToUser', [$user->email]));
}
// Clear the email
$email->clear();
$this->session->setFlashdata('success', 'Successfuly added new member information');
return redirect()->to('/admin/members');
}
}
echo view('templates/header');
echo view('admin/left_nav_bar');
echo view('admin/add_member', $data);
echo view('admin/left_nav_bar_closure');
echo view('admin/javascript');
echo view('templates/footer');
} here
No information on the topic internet wide.